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.