public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Steve Ellcey <sellcey@caviumnetworks.com>
To: <libc-alpha@sourceware.org>
Subject: Re: [PATCH] Fix -Wformat-length warning in time/tst-strptime2.c
Date: Wed, 02 Nov 2016 19:47:00 -0000	[thread overview]
Message-ID: <1478116026.2891.53.camel@caviumnetworks.com> (raw)
In-Reply-To: <1477326501.8523.51.camel@caviumnetworks.com>

Here is an updated version of my earlier patch, I hadn't tested the
original one with an old GCC so I hadn't realized I needed to put the
DIAG_IGNORE_NEEDS_COMMENT in an ifdef.  This version was tested with
GCC 5.4 and GCC 7.0 with no regressions.

I also double checked that the test program is deliberately using
snprintf to truncate the output so changing the test by increasing the
buffer size and avoiding the warnings that way would change what was
being tested.

OK to checkin?


2016-11-02  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..53b366b 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,20 @@ 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);
+#if __GNUC_PREREQ (7, 0)
+  /* GCC issues a warning when it thinks the snprintf buffer may be
too short.
+     This test is explicitly using short buffers to force snprintf to
truncate
+     the output so we ignore the warnings.  */
+  DIAG_PUSH_NEEDS_COMMENT;
+  DIAG_IGNORE_NEEDS_COMMENT (7.0, "-Wformat-length");
+#endif
   if (colon)
     snprintf (buf + i, ndigits + 2, "%02u:%02u", hh, mm);
   else
     snprintf (buf + i, ndigits + 1, "%04u", hhmm);
+#if __GNUC_PREREQ (7, 0)
+  DIAG_POP_NEEDS_COMMENT;
+#endif
 
   if (mm <= mm_max && (ndigits == 2 || ndigits == 4))
     {


  reply	other threads:[~2016-11-02 19:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 16:28 Steve Ellcey
2016-11-02 19:47 ` Steve Ellcey [this message]
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=1478116026.2891.53.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).