This is the mail archive of the gcc-bugs@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]

[Bug c/39438] Can't compile a wrapper around strftime with -Werror=format-nonliteral


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39438

D. Hugh Redelmeier <hugh at mimosa dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hugh at mimosa dot com

--- Comment #4 from D. Hugh Redelmeier <hugh at mimosa dot com> ---
I have this problem too.  I'm writing a wrapper for strftime.  I get a warning
on the actual strftime call.  

warning: format not a string literal, format string not checked
[-Wformat-nonliteral]
  strftime(buf, buflen, fmt, t);

Surely GCC should not that for "fmt" argument has been checked to be a valid
strftime format at the points where prettynow gets called.  So there is no need
to whine that it is unchecked.


static void prettynow(char *buf, size_t buflen, const char *fmt) __attribute__
((format (__strftime__, 3, 0)));

static void prettynow(char *buf, size_t buflen, const char *fmt)
{
     time_t n = time(0);
    struct tm tm1;
    struct tm *t = localtime_r(&n, &tm1);

    strftime(buf, buflen, fmt, t);
}

I'm using gcc-4.8.2-7.fc20.x86_64 on Fedora 20.

I managed to suppress the warning with a very ugly cast:

        ((size_t (*)(char *, size_t, const char *, const struct tm
*))strftime)(buf, buflen, fmt, t);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]