This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[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: Mon, 24 Oct 2016 09:28:21 -0700
- Subject: [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;
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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))
{