public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hugh at mimosa dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/39438] Can't compile a wrapper around strftime with -Werror=format-nonliteral
Date: Sat, 10 May 2014 16:47:00 -0000	[thread overview]
Message-ID: <bug-39438-4-fZ0tCSCfX5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-39438-4@http.gcc.gnu.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);


  parent reply	other threads:[~2014-05-10 16:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bug-39438-4@http.gcc.gnu.org/bugzilla/>
2012-01-10 20:39 ` tss at iki dot fi
2014-05-10 16:47 ` hugh at mimosa dot com [this message]
2014-05-12 12:26 ` manu at gcc dot gnu.org
2014-05-12 14:58 ` hugh at mimosa dot com
2014-05-12 15:38 ` manu at gcc dot gnu.org
2014-05-12 15:52 ` manu at gcc dot gnu.org
2014-05-12 19:33 ` hugh at mimosa dot com
2015-02-27 16:43 ` manu at gcc dot gnu.org
2024-06-03  1:48 ` peter0x44 at disroot dot org
2009-03-11 22:57 [Bug c/39438] New: " 4tmuelle at informatik dot uni-hamburg dot de
2009-03-12  9:40 ` [Bug c/39438] " rguenth at gcc dot gnu dot org
2009-03-12  9:58 ` 4tmuelle at informatik dot uni-hamburg dot de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-39438-4-fZ0tCSCfX5@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).