Re: Format string wrapper and -Wformat-nonliteral

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

 



Hey Kevin :)

Thanks for your quick reply.

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 $



I also tried to declare the function first:

size_t my_strftime(char *s, size_t max, const char *fmt,
                   const struct tm *tm)
                   __attribute__((format (strftime, 3, 0)));

size_t my_strftime(char *s, size_t max, const char *fmt,
                   const struct tm *tm)
{...}

And it fails with
muelli@bigbox /tmp $ gcc -Wformat  -Wformat-nonliteral -Werror=format-nonliteral  -Wfatal-errors -o mystrftime{,.c}
mystrftime.c: In function ‘my_strftime’:
mystrftime.c:14: error: format not a string literal, format string not checked
compilation terminated due to -Wfatal-errors.
muelli@bigbox /tmp $

In case it's of any importance: I use gcc (GCC) 4.3.2 20081105 (Red Hat 4.3.2-7)

Maybe I misunderstood you?


Cheers,
  Tobi

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux