bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portability issue for error_tail().


From: Jim Meyering
Subject: Re: Portability issue for error_tail().
Date: Sat, 20 Aug 2011 09:34:35 +0200

Bruno Haible wrote:

> Paul Eggert wrote:
>> portable programs should not pass a NULL format to 'error', so this is not
>> a gnulib bug.
>
> Yes. But why does it not yield a GCC warning?
>
> ======================== foo.c =========================
> #include <errno.h>
> #include <stdlib.h>
> extern void error (int __status, int __errnum, __const char *__format, ...)
>   __attribute__ ((__format__ (__printf__, 3, 4)))
> #ifdef DECLARE_NONNULL
>   __attribute__ ((__nonnull__(3)))
> #endif
> ;
>
> void foo ()
> {
>   error (EXIT_FAILURE, EPERM, NULL);
> }
> =====================================================
>
> $ gcc -Wformat=2 -c foo.c
> $ gcc -Wformat=2 -c foo.c -DDECLARE_NONNULL
> foo.c: In function 'foo':
> foo.c:12: warning: null argument where non-null required (argument 3)
>
> Should the declaration in glibc's and gnulib's error.h be changed to contain a
> __attribute__ ((__nonnull__(3)))  ?
>
> Or should gcc be changed so that  __attribute__ ((__format__ (__printf__, m, 
> n)))
> implies __attribute__ ((__nonnull__(m))) ?

Good point.
IMHO the latter (enhancing gcc) makes more sense.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]