Re: error: format not a string literal and no format arguments



Am Sonntag, den 06.07.2008, 02:40 +0100 schrieb Alexander Jones:
> I'm trying to build Rhythmbox...
> 
> With gcc 4.3 (from Ubuntu 8.10), I'm getting this error in a
> helluvalot of places:
> 
> "error: format not a string literal and no format arguments"
> 
> The problem lies in code like this:
> 
> char* error = NULL;
> ...
> g_warning(error)
> 
> You have to use, e.g.:
> g_warning ("%s", error);
> for macros like g_warning and g_log, and any API function that
> actually accepts a printf-format (like g_error_set) while we're
> passing it any old string without any parameters.
> 
> Yeah, I could just use -Wleave-me-alone-ffs or something, but it's
> probably worth considering this properly.
> 
> "Discuss."

That's because Ubuntu 8.10 uses -Wformat=2. Unfortunately the last time
I checked -Wformat=2 it produced a lot of false positives:

char *fmt = "%s %d";
print (fmt, "bla", 2);

produced a warning for the same reason.

It's an error in your case because of -Werror I guess :)


In general you shouldn't pass random strings as format strings to those
function as this could lead to crashes but in some cases it's fine IMHO.

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]