This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/39438] Can't compile a wrapper around strftime with -Werror=format-nonliteral
- From: "hugh at mimosa dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 10 May 2014 16:47:09 +0000
- Subject: [Bug c/39438] Can't compile a wrapper around strftime with -Werror=format-nonliteral
- Auto-submitted: auto-generated
- References: <bug-39438-4 at http dot gcc dot gnu dot org/bugzilla/>
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);