This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: format string is not a string literal
- From: Pedro Alves <palves at redhat dot com>
- To: paul at mad-scientist dot net
- Cc: Jack Howarth <howarth dot mailing dot lists at gmail dot com>, pinskia at gmail dot com, Simon Marchi <simon dot marchi at polymtl dot ca>, "Paul_Koning at dell dot com" <Paul_Koning at dell dot com>, "gdb at sourceware dot org" <gdb at sourceware dot org>
- Date: Thu, 26 Feb 2015 17:52:37 +0000
- Subject: Re: format string is not a string literal
- Authentication-results: sourceware.org; auth=none
- References: <CADtEn-1ZT1uznxPzQxr_nBQya1AVrNLyE+ZSDmm2x_ux8qyzUQ at mail dot gmail dot com> <0AB56024-875B-4724-8ED2-A9DDB237CBFF at dell dot com> <CADtEn-0txdtq6x6dAZZ5wew-VOvYU28fueT_kJ2cx7=H0=vdPg at mail dot gmail dot com> <23CC7871-C616-436C-920C-4A635DC87189 at dell dot com> <CAFXXi0=56gNf2GoSKkrx=bRArhjk+AhSbiu0crpdR3=df7B2BQ at mail dot gmail dot com> <7A311B56-C424-4C4F-A0E4-B12B65131745 at gmail dot com> <CADtEn-1vHnay=ftK9Hq6ogYyDNPc_anNgLnwuUZSt4VjzF+7GQ at mail dot gmail dot com> <54EEECD9 dot 4050909 at redhat dot com> <1424972642 dot 824 dot 33 dot camel at homebase>
On 02/26/2015 05:44 PM, Paul Smith wrote:
> On Thu, 2015-02-26 at 09:52 +0000, Pedro Alves wrote:
>> + /* Use FMT from here on instead of complaint->fmt, to avoid "format
>> + string is not a string literal" warnings. */
>> + gdb_assert (complaint->fmt == fmt);
>> +
>> if (complaint->file != NULL)
>> - internal_vwarning (complaint->file, complaint->line,
>> - complaint->fmt, args);
>> + internal_vwarning (complaint->file, complaint->line, fmt, args);
>
> Can someone quickly explain how using fmt instead of complaint->fmt here
> removes the warning? fmt is not a "string literal" either...?
>
> Just curious what the trick is...
Simon explained it, actually:
> If the function is vprintf-style, it's similar but the last argument
> should be 0. It will push the argument check a level higher, where
> eventually they are explicitely defined printf-style. The doc is
> somewhere here [2] in the middle.
That code is in this function:
> static void ATTRIBUTE_PRINTF (4, 0)
vcomplaint (struct complaints **c, const char *file,
int line, const char *fmt,
va_list args)
{
So here the compiler will check FMT in the caller.
Thanks,
Pedro Alves