This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix -Wformat-length warning in time/tst-strptime2.c
- From: Steve Ellcey <sellcey at caviumnetworks dot com>
- To: <libc-alpha at sourceware dot org>
- Date: Wed, 2 Nov 2016 12:47:06 -0700
- Subject: Re: [PATCH] Fix -Wformat-length warning in time/tst-strptime2.c
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Steve dot Ellcey at cavium dot com;
- References: <1477326501.8523.51.camel@caviumnetworks.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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))
{