Format string wrapper and -Wformat-nonliteral

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

 



Hi folks,

I basically have a wrapper around strftime() and compilation with -Werror=format-nonliteral fails when the wrapper wants to call strftime, because "format not a string literal, format string not checked".

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?

The code in question looks like this:
> muelli@bigbox /tmp $ cat mystrftime.c
#include<time.h>
#include<stdio.h>

#define SIZE 256

size_t my_strftime(char *s, size_t max, const char *fmt,
                   const struct tm *tm)
{
    size_t ret;
    ret = strftime(s, max, fmt, tm);
    return ret;
}

int
main ()
{
    char s[SIZE];
    time_t curtime;
    struct tm* loctime;

    curtime = time(NULL);
    loctime = localtime (&curtime);
    my_strftime(s, SIZE, "Hello %A", loctime);
    printf("%s", s);
    return 0;
}
muelli@bigbox /tmp $ gcc -Wformat  -Wformat-nonliteral -Werror=format-nonliteral -o mystrftime{,.c}
mystrftime.c: In function ‘my_strftime’:
mystrftime.c:9: error: format not a string literal, format string not checked
muelli@bigbox /tmp $



Thanks in advance,
  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