*BSD News Article 22748


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!elroy.jpl.nasa.gov!decwrl!concert!sas!mozart.unx.sas.com!torpid.unx.sas.com!sastdr
From: sastdr@torpid.unx.sas.com (Thomas David Rivers)
Subject: Re: mktemp() crashes
Sender: news@unx.sas.com (Noter of Newsworthy Events)
Message-ID: <CF9BDx.n2J@unx.sas.com>
Date: Thu, 21 Oct 1993 17:03:32 GMT
References: <CF7snJ.ID9@dvorak.amd.com>
Nntp-Posting-Host: torpid.unx.sas.com
Organization: SAS Institute Inc.
Lines: 31


 The mktemp problem is usually caused by incorrect use of mktemp().

 If you have code of the form:

    name = mktemp("some_char_const");

 then when the mktemp call tries to write into the template 
("some_char_const") - it blows up...

 This is because the "some_char_const", per ANSI can be placed in non
writable (read-only) storage - since it is a character constant.

 You can get around this by proper coding of the code that uses mktemp()
as in:

     char temp_buf[] = "some_char_const";

     name = mktemp(temp_buf);

(Which will write into "temp_buf" - not the defined char const.)

Or - you can compile with the GCC option for writeable-strings; which
was added just for this, and other similar cases.


	- Dave Rivers -
	(ponds!rivers@dg-rtp.dg-com)
	(sastdr@unx.sas.com)
-- 
Imagine Whirled Peas.