[PATCH] Fix -Wformat-length warning in time/tst-strptime2.c
Steve Ellcey
sellcey@caviumnetworks.com
Mon Oct 24 16:28:00 GMT 2016
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))
     {
More information about the Libc-alpha
mailing list