public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Steve Ellcey <sellcey@caviumnetworks.com>
To: <libc-alpha@sourceware.org>
Subject: [PATCH] Fix -Wformat-length warning in time/tst-strptime2.c
Date: Mon, 24 Oct 2016 16:28:00 -0000	[thread overview]
Message-ID: <1477326501.8523.51.camel@caviumnetworks.com> (raw)

This is the third of three patches to deal with the new -Wformat-length
warning in GCC 7.0.  Changing the size of the buffer looked like it
might interfer with what the test was trying to check so I added a
DIAG_IGNORE macro for this test.

Steve Ellcey
sellcey@caviumnetworks.com


2016-10-24  Steve Ellcey  <sellcey@caviumnetworks.com>

	* time/tst-strptime2.c: Ignore -Wformat-length warning.


diff --git a/time/tst-strptime2.c b/time/tst-strptime2.c
index 7fe7350..2f411a4 100644
--- a/time/tst-strptime2.c
+++ b/time/tst-strptime2.c
@@ -4,6 +4,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <time.h>
+#include <libc-internal.h>
 
 /* Dummy string is used to match strptime's %s specifier.  */
 
@@ -67,10 +68,16 @@ mkbuf (char *buf, bool neg, bool colon, unsigned int hhmm, s
ize_t ndigits)
   long int expect = LONG_MAX;
 
   i = sprintf (buf, "%s %c", dummy_string, sign);
+  /* GCC cannot be certain that the buffer is long enough so it issues a
+     warning.  We know that hhmm is never more than 4 digits so we can ignore
+     the warning.  */
+  DIAG_PUSH_NEEDS_COMMENT;
+  DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-length");
   if (colon)
     snprintf (buf + i, ndigits + 2, "%02u:%02u", hh, mm);
   else
     snprintf (buf + i, ndigits + 1, "%04u", hhmm);
+  DIAG_POP_NEEDS_COMMENT;
 
   if (mm <= mm_max && (ndigits == 2 || ndigits == 4))
     {

             reply	other threads:[~2016-10-24 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 16:28 Steve Ellcey [this message]
2016-11-02 19:47 ` Steve Ellcey
2016-11-02 20:55   ` Carlos O'Donell

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=1477326501.8523.51.camel@caviumnetworks.com \
    --to=sellcey@caviumnetworks.com \
    --cc=libc-alpha@sourceware.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).