This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: BZ #13908 Fix mktemp attribute and comment


On 04/04/2012 06:16 PM, Paul Eggert wrote:
On 04/04/2012 08:58 AM, Carlos O'Donell wrote:

Is there some common idiom that is used by developers which triggers a
warning when it shouldn't?

It's the typical way mktemp should be used. Here's an example, from <http://stuff.mit.edu/afs/athena/astaff/project/opssrc/cups/foomatic-filters-4.0.3/pdf.c>:

     snprintf(filename, PATH_MAX, "%s/foomatic-XXXXXX", temp_dir());
     mktemp(filename);
     if (!filename[0])
         return 0;

Is this with a recent GCC?

It should be with any gcc that supports __wur, no?

Yep, with gcc 4.6:


gcc -Wall t.c -O2 -D_FORTIFY_SOURCE=2
t.c: In function ‘main’:
t.c:12:10: warning: ignoring return value of ‘mktemp’, declared with attribute warn_unused_result [-Wunused-result]
/tmp/ccm8JfIk.o: In function `main':
t.c:(.text.startup+0x1f): warning: the use of `mktemp' is dangerous, better use `mkstemp'


Ok, with the change to use "Always returns"?

Andreas

Testprogram:
#include <sys/param.h>
#include <stdlib.h>
#include <stdio.h>

int
main (void)
{
  char filename [PATH_MAX];

   snprintf(filename, PATH_MAX, "/tmp/foomatic-XXXXXX");
   mktemp(filename);
   if (!filename[0])
     return 1;
   return 0;
}

--
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


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