https://bugzilla.novell.com/show_bug.cgi?id=213892
matz@novell.com changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|matz@novell.com |pbaudis@novell.com
------- Comment #1 from matz@novell.com 2006-10-20 08:32 MST -------
This is a result of the options -std=c99 and -D_FORTIFY_SOURCE=2. That latter
makes printf actually be "__printf_chk", and the former switches off the
implicit format checking warning for that (not for printf() though).
This behaviour is correct from gcc side. As "__printf_chk" is no ISO
function, gcc is not allowed to infer any special semantic about it
in -std=c99 mode (unlike for printf). The "special semantic" here is the
checking of the format string. Hence __printf_chk in -std=c99 mode gets no
special treatment. glibc (/usr/include/bits/stdio2.h actually) defines
printf as __printf_chk (when fortify level is > 1). And __printf_chk is
simply declared like so:
extern int __printf_chk (int __flag, __const char *__restrict __format, ...);
Note especially the absence of any "printf" attributes. That's why we get
no warning here.
There are two ways out: 1) define printf to __builtin___printf_chk in
bits/stdio2.h or 2) add the necessary attributes to the __printf_chk
declaration.
The first solution works, because the function "__builtin___printf_chk" is
defined as builtin in gcc regardless of the ISO mode, and it will get format
checking. GCC itself will then implement this builtin via a call to
__printf_chk, so there's no change in runtime behaviour (i.e. gcc itself
emits no interesting special code for __builtin___printf_chk, which it doesn't
also emit for just __printf_chk).
The second solution also would work because of the explicitely added printf
attributes (which are implicitely defined for the builtins).
I think the first solution would be a bit nicer, but ultimately that's up to
the glibc maintainers.
Just for reference as testcase:
% cat pr.c
#include