This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Format string wrapper and -Wformat-nonliteral


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]