"format not a string literal"

Ken Raeburn raeburn@raeburn.org
Tue Oct 12 08:17:00 GMT 1999


I submitted the patch to add this warning because it caught specific
bugs in code we (MIT) were shipping.  It's not useless, except in your
glibc cases.

I think Kaveh's fix may be right for some cases.

The additional change I'd mentioned before on the patches list
(suppressing warnings if the *calling* function had the same format
attribute, and was passing the incoming format arg) would also deal
with the vprintf case, and (without Kaveh's patch) could be used to
verify that both had been declared to use printf formats specifically.
I am going to try to write up such a patch.  (Checking for using the
value of the incoming format arg is non-trivial if you want to follow
assignments and arithmetic operations, etc, but IMHO they shouldn't be
happening in normal code, and checking for a use of the incoming arg
itself is probably a good first cut.)

Ulrich Drepper <drepper@cygnus.com> writes:
> "Kaveh R. Ghazi" <ghazi@caip.rutgers.edu> writes:
> > 	Does this gcc patch help out?  I'd be interested to know if
> > any other false positives remain.
> 
> This solves the obvious problems.  There is still case:
> 
> 	printf (gettext ("%s %d"), "foo", 42);
> 
> you have to take the functions registered using
> `record_international_format' into account.

No.  The warning I added is after the processing of
internationalization functions, and after the decision has been made
that the format checking cannot be done.  If you're getting the
warning for the above code, it means the format checking wasn't
happening before.

I wasn't able to generate the new warning for the above code just now
except in a case with no declaration for gettext at all, which means
an implicit "int" return type, which would be a bug and gets another
warning from the compiler already.  If you've got another (complete)
gettext-with-string-literal example that gets the warning, let me
know.

Ken


More information about the Gcc-bugs mailing list