public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: tmpnam() core dumping
@ 1997-12-15  8:20 Bill Ahlbrandt
  0 siblings, 0 replies; 9+ messages in thread
From: Bill Ahlbrandt @ 1997-12-15  8:20 UTC (permalink / raw)
  To: 'egcs@cygnus.com'

[-- Attachment #1: Type: text/plain, Size: 616 bytes --]

Understood and agreed.

-----Original Message-----
From:	Andreas Schwab [SMTP:schwab@issan.informatik.uni-dortmund.de]
Sent:	Monday, December 15, 1997 4:51 AM
To:	egcs@cygnus.com
Subject:	Re: tmpnam() core dumping

Bill Ahlbrandt <bahlbr@icdata.com> writes:

|> Yes, using -fwritable-strings fixes the problem.

No, it does not "fix" the problem, it just hides it away.  A program that
must be compiled with -fwritable-strings is simply broken.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
schwab@gnu.org


[-- Attachment #2: bin00000.bin --]
[-- Type: application/vnd.ms-tnef, Size: 2105 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tmpnam() core dumping
  1997-12-12 10:18 Bill Ahlbrandt
  1997-12-12 13:04 ` Per Bothner
  1997-12-12 15:46 ` Tim Hollebeek
@ 1997-12-15  2:51 ` Andreas Schwab
  2 siblings, 0 replies; 9+ messages in thread
From: Andreas Schwab @ 1997-12-15  2:51 UTC (permalink / raw)
  To: egcs

Bill Ahlbrandt <bahlbr@icdata.com> writes:

|> Yes, using -fwritable-strings fixes the problem.

No, it does not "fix" the problem, it just hides it away.  A program that
must be compiled with -fwritable-strings is simply broken.

-- 
Andreas Schwab                                      "And now for something
schwab@issan.informatik.uni-dortmund.de              completely different"
schwab@gnu.org

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: tmpnam() core dumping
@ 1997-12-13  9:55 Bill Ahlbrandt
  0 siblings, 0 replies; 9+ messages in thread
From: Bill Ahlbrandt @ 1997-12-13  9:55 UTC (permalink / raw)
  To: 'egcs@cygnus.com'

[-- Attachment #1: Type: text/plain, Size: 968 bytes --]

Great!  I get it now.  Thanks for all of the input/help!

-----Original Message-----
From:	Marc Lehmann [SMTP:pcg@goof.com]
Sent:	Friday, December 12, 1997 11:01 AM
To:	egcs@cygnus.com
Subject:	Re: tmpnam() core dumping

On Fri, Dec 12, 1997 at 08:13:46AM -0600, Bill Ahlbrandt wrote:
> I am getting a core dump when I use the tmpnam() function.

RTM, you are calling

tmpnam("xxx"),

and tmpnam tries to overwrite the memory you gave to it (which
is a constant string which is in a readonly section), thus
you get a segmentation fault.

      -----==-                                              |
      ----==-- _                                            |
      ---==---(_)__  __ ____  __       Marc Lehmann       +--
      --==---/ / _ \/ // /\ \/ /       pcg@goof.com       |e|
      -=====/_/_//_/\_,_/ /_/\_\                          --+
    The choice of a GNU generation                        |
                                                          |

[-- Attachment #2: bin00000.bin --]
[-- Type: application/vnd.ms-tnef, Size: 2273 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tmpnam() core dumping
  1997-12-12 10:18 Bill Ahlbrandt
  1997-12-12 13:04 ` Per Bothner
@ 1997-12-12 15:46 ` Tim Hollebeek
  1997-12-15  2:51 ` Andreas Schwab
  2 siblings, 0 replies; 9+ messages in thread
From: Tim Hollebeek @ 1997-12-12 15:46 UTC (permalink / raw)
  To: egcs

Bill Ahlbrandt writes ...
> 
> Yes, using -fwritable-strings fixes the problem.
> 
> I wonder why these functions want to modify the string that is passed to them :-)?

Normal behavior.  Otherwise they would have to call malloc() to allocate the
result, or something similar.  E.g. from the IRIX man page:

     tmpnam always generates a file name using the path-prefix defined as
     P_tmpdir in the <stdio.h> header file.  If s is NULL, tmpnam leaves its
     result in an internal static area and returns a pointer to that area.
     The next call to tmpnam will destroy the contents of the area.  If s is
     not NULL, it is assumed to be the address of an array of at least
     L_tmpnam bytes, where L_tmpnam is a constant defined in <stdio.h>; tmpnam
     places its result in that array and returns s.

---------------------------------------------------------------------------
Tim Hollebeek                           | "Everything above is a true
email: tim@wfn-shop.princeton.edu       |  statement, for sufficiently
URL: http://wfn-shop.princeton.edu/~tim |  false values of true."

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tmpnam() core dumping
  1997-12-12  6:18 Bill Ahlbrandt
  1997-12-12  8:02 ` Jeffrey A Law
@ 1997-12-12 14:32 ` Marc Lehmann
  1 sibling, 0 replies; 9+ messages in thread
From: Marc Lehmann @ 1997-12-12 14:32 UTC (permalink / raw)
  To: egcs

On Fri, Dec 12, 1997 at 08:13:46AM -0600, Bill Ahlbrandt wrote:
> I am getting a core dump when I use the tmpnam() function.

RTM, you are calling

tmpnam("xxx"),

and tmpnam tries to overwrite the memory you gave to it (which
is a constant string which is in a readonly section), thus
you get a segmentation fault.

      -----==-                                              |
      ----==-- _                                            |
      ---==---(_)__  __ ____  __       Marc Lehmann       +--
      --==---/ / _ \/ // /\ \/ /       pcg@goof.com       |e|
      -=====/_/_//_/\_,_/ /_/\_\                          --+
    The choice of a GNU generation                        |
                                                          |

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tmpnam() core dumping
  1997-12-12 10:18 Bill Ahlbrandt
@ 1997-12-12 13:04 ` Per Bothner
  1997-12-12 15:46 ` Tim Hollebeek
  1997-12-15  2:51 ` Andreas Schwab
  2 siblings, 0 replies; 9+ messages in thread
From: Per Bothner @ 1997-12-12 13:04 UTC (permalink / raw)
  To: egcs

> I wonder why these functions want to modify the string that is passed to them :-)?

Because that is what the C standard specifies it should do?

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: tmpnam() core dumping
@ 1997-12-12 10:18 Bill Ahlbrandt
  1997-12-12 13:04 ` Per Bothner
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Bill Ahlbrandt @ 1997-12-12 10:18 UTC (permalink / raw)
  To: 'law@cygnus.com'; +Cc: 'egcs@cygnus.com'

Yes, using -fwritable-strings fixes the problem.

I wonder why these functions want to modify the string that is passed to them :-)?

Thanks much... 

-----Original Message-----
From:	Jeffrey A Law [SMTP:law@hurl.cygnus.com]
Sent:	Friday, December 12, 1997 10:05 AM
To:	Bill Ahlbrandt
Cc:	egcs@cygnus.com
Subject:	Re: tmpnam() core dumping 


  In message < 01BD06D5.E1EF50C0@bill.icdata.com >you write:
  > This probably has nothing to do with egcs, but being extremely new this env
  > ironment and compiler, any assistance will be much appreciated.
  > 
  > Note that the tempnam function works just fine.
Does -fwritable-strings fix the problem.

From the GCC manual:
@itemize @bullet
@cindex string constants
@cindex read-only strings
@cindex shared strings
@item
GNU CC normally makes string constants read-only.  If several
identical-looking string constants are used, GNU CC stores only one
copy of the string.

@cindex @code{mktemp}, and constant strings
One consequence is that you cannot call @code{mktemp} with a string
constant argument.  The function @code{mktemp} always alters the
string its argument points to.


This may also apply to tempnam.

jeff



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: tmpnam() core dumping
  1997-12-12  6:18 Bill Ahlbrandt
@ 1997-12-12  8:02 ` Jeffrey A Law
  1997-12-12 14:32 ` Marc Lehmann
  1 sibling, 0 replies; 9+ messages in thread
From: Jeffrey A Law @ 1997-12-12  8:02 UTC (permalink / raw)
  To: Bill Ahlbrandt; +Cc: egcs

  In message < 01BD06D5.E1EF50C0@bill.icdata.com >you write:
  > This probably has nothing to do with egcs, but being extremely new this env
  > ironment and compiler, any assistance will be much appreciated.
  > 
  > Note that the tempnam function works just fine.
Does -fwritable-strings fix the problem.

From the GCC manual:
@itemize @bullet
@cindex string constants
@cindex read-only strings
@cindex shared strings
@item
GNU CC normally makes string constants read-only.  If several
identical-looking string constants are used, GNU CC stores only one
copy of the string.

@cindex @code{mktemp}, and constant strings
One consequence is that you cannot call @code{mktemp} with a string
constant argument.  The function @code{mktemp} always alters the
string its argument points to.


This may also apply to tempnam.

jeff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* tmpnam() core dumping
@ 1997-12-12  6:18 Bill Ahlbrandt
  1997-12-12  8:02 ` Jeffrey A Law
  1997-12-12 14:32 ` Marc Lehmann
  0 siblings, 2 replies; 9+ messages in thread
From: Bill Ahlbrandt @ 1997-12-12  6:18 UTC (permalink / raw)
  To: 'egcs@cygnus.com'

I am getting a core dump when I use the tmpnam() function.

I'm running slackware 2.0.29, 

gcc -v gives:

Reading specs from /usr/local/lib/gcc-lib/i486-pc-linux-gnulibc1/egcs-2.90.21/specs
gcc version egcs-2.90.21 971202 (egcs-1.00 release)

This probably has nothing to do with egcs, but being extremely new this environment and compiler, any assistance will be much appreciated.

Note that the tempnam function works just fine.


The following code produces the output that follows:

#include <stdio.h>

int main() {
  char *tempFileName;
  printf("doing tempnam\n");
  tempFileName=tempnam(".","xxx");
  printf("done\n");
  if (tempFileName) {
    printf("I got %s\n",tempFileName);
  } else {
    printf("Got an error\n");
  } /* endif */

  printf("doing tmpnam\n");
  tempFileName=tmpnam("xxx");
  printf("done\n");
  if (tempFileName) {
    printf("I got %s\n",tempFileName);
  } else {
    printf("Got an error\n");
  } /* endif */
  return 0;
}


mail:~/src/bug$ gcc bug.cpp
mail:~/src/bug$ a.out
doing tempnam
done
I got ./xxx30905aaa
doing tmpnam
Segmentation fault (core dumped)
mail:~/src/bug$                                                                                                                                       


Thanks in advance.

Bill Ahlbrandt



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~1997-12-15  8:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-12-15  8:20 tmpnam() core dumping Bill Ahlbrandt
  -- strict thread matches above, loose matches on Subject: below --
1997-12-13  9:55 Bill Ahlbrandt
1997-12-12 10:18 Bill Ahlbrandt
1997-12-12 13:04 ` Per Bothner
1997-12-12 15:46 ` Tim Hollebeek
1997-12-15  2:51 ` Andreas Schwab
1997-12-12  6:18 Bill Ahlbrandt
1997-12-12  8:02 ` Jeffrey A Law
1997-12-12 14:32 ` Marc Lehmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).