This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: format string is not a string literal


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]