[Bug 213892] New: gcc fails to warn about incorrect printf usage
https://bugzilla.novell.com/show_bug.cgi?id=213892 Summary: gcc fails to warn about incorrect printf usage Product: openSUSE 10.2 Version: Alpha 5 plus Platform: Other OS/Version: Linux Status: NEW Severity: Minor Priority: P5 - None Component: Development AssignedTo: matz@novell.com ReportedBy: max@novell.com QAContact: qa@suse.de The following line from spandsp-0.0.3pre24, which has more format specifiers than arguments following the format, gets a "warning: too few arguments for format" on s390 and s390x, but not on any other platform: printf("v = %10.5f %5d - %f %f %d %d\n", v, i, p, s->baud_phase, s->total_baud_timing_correction); -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.
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
participants (1)
-
bugzilla_noreply@novell.com