This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: warning for -Wformat and non-literal-string format
- To: law at cygnus dot com
- Subject: Re: warning for -Wformat and non-literal-string format
- From: Andreas Jaeger <aj at suse dot de>
- Date: 10 Oct 1999 14:46:11 +0200
- Cc: Ken Raeburn <raeburn at raeburn dot org>, gcc-patches at gcc dot gnu dot org
- References: <3541.939532620@upchuck.cygnus.com>
>>>>> Jeffrey A Law writes:
>> ------- Start of forwarded message -------
>> Message-Id: <199910070051.UAA12759@dcl.mit.edu>
>> From: Ken Raeburn <raeburn@MIT.EDU>
>> To: gcc-patches@egcs.cygnus.com
>>
>> I ran into some problems with code that did lame-o stuff like this:
>>
>> vsprintf (buf, fmt, ap);
>> ...
>> fprintf (logfile, buf);
>>
>> when one of the supplied strings included a %s or %n that wound up in
>> "buf". The following patch is helping me track down such bugs.
>>
>> Unfortunately, it also complains on variadic routines that themselves
>> accept formats and parameters, and call vfprintf or vsyslog or
>> whatever. If such calling functions have format attribute
>> declarations too, it may be possible to refine the check somewhat.
>> But I'm just going to check those cases by hand, for now. :-)
>>
>> That might be a good reason to use a different -W flag for now. (Yet
>> another one??) Let me know if you want another patch to do it that
>> way.
>>
>> Ken
>>
>>
>> Wed Oct 6 01:59:29 1999 Ken Raeburn <raeburn@mit.edu>
>>
>> * c-common.c (check_format_info): Warn if format string isn't a
>> string literal.
Jeff> Thanks. Installed.
Jeff> Note I removed the goto usage and just copied the warning/return statements.
Jeff> Depending on how often it triggers we may or may not have to make it a
Jeff> separate option. I consider that issue unresolved at this time.
Bootstrapping egcs I got a number of:
In file included from /usr/include/stdio.h:631,
from ../../cvs/gcc/gcc/system.h:33,
from insn-emit.c:5:
/usr/include/bits/stdio.h: In function `vprintf':
/usr/include/bits/stdio.h:35: warning: format not a string literal, argument types not checked
The warnings come from this piece of code in <bits/stdio.h> (from
glibc 2.1.2):
/* Write formatted output to stdout from argument list ARG. */
__STDIO_INLINE int
vprintf (__const char *__restrict __fmt, _G_va_list __arg) __THROW
{
return vfprintf (stdout, __fmt, __arg);
}
Is there a way to stop these warnings?
Andreas
--
Andreas Jaeger
SuSE Labs aj@suse.de
private aj@arthur.rhein-neckar.de