This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: tmpnam() core dumping


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."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]