This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Format string wrapper and -Wformat-nonliteral
- From: Tobias Mueller <4tmuelle+gcc at informatik dot uni-hamburg dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 06 Mar 2009 03:06:10 +0100
- Subject: Re: Format string wrapper and -Wformat-nonliteral
- References: <49A96972.5060004@informatik.uni-hamburg.de> <49A96D57.1050201@digium.com> <49A96F40.7050409@informatik.uni-hamburg.de>
Hey,
Tobias Mueller wrote:
Kevin P. Fleming wrote:
Tobias Mueller wrote:
I think I want to make gcc
* know that the wrapper is not responsible for the format string and
thus the call to strftime is allowed
* pass the responsibility up to the callers and thus check whether they
call the wrapper with "good" strings.
And I don't know how to do that. Do you have any advices?
<snip>
size_t my_strftime(char *s, size_t max, const char *fmt,
const struct tm *tm)
Add "__attribute__((format (strftime, 3, 0)))" to your function
declaration.
Well, I tried that:
size_t my_strftime(char *s, size_t max, const char *fmt,
const struct tm *tm)
__attribute__((format (strftime, 3, 0)))
{...}
and it fails:
muelli@bigbox /tmp $ gcc -Wformat -Wformat-nonliteral
-Werror=format-nonliteral -Wfatal-errors -o mystrftime{,.c}
mystrftime.c:9: error: expected â,â or â;â before â{â token
compilation terminated due to -Wfatal-errors.
muelli@bigbox /tmp $
Now I tried
__attribute__(( format (strftime, 3, 0) ))
size_t my_strftime(char *s, size_t max, const char *fmt,
const struct tm *tm)
{...}
and at least it doesn't throw a syntax error. But it still fails to compile:
muelli@bigbox /tmp $ gcc -Wformat -Wformat-nonliteral -Werror=format-nonliteral -o mystrftime{,.c}
mystrftime.c: In function âmy_strftimeâ:
mystrftime.c:14: error: format not a string literal, format string not checked
muelli@bigbox /tmp $
What would be the next step in solving this issue? Maybe filing a bug
would be appropriate?
Cheers,
Tobi