]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix tst-cmp.c build with GCC mainline.
authorJoseph Myers <joseph@codesourcery.com>
Wed, 20 Jun 2018 22:19:50 +0000 (22:19 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Wed, 20 Jun 2018 22:19:50 +0000 (22:19 +0000)
Building the testsuite with GCC mainline fails with
-Wstringop-overflow= errors in string/tst-cmp.c.  These are for calls
to strncmp and strncasecmp with SIZE_MAX size argument.  The tests are
deliberately using this size that would be dubious in normal code, so
this patch disables the warning for the calls in question.

Tested with build-many-glibcs.py for aarch64-linux-gnu.

* string/tst-cmp.c: Include <libc-diag.h>.
(strncmp_max): Disable -Wstringop-overflow= around call to
strncmp.
(strncasecmp_max): Disable -Wstringop-overflow= around call to
strncasecmp.

ChangeLog
string/tst-cmp.c

index ce0266a35edf355758ffa599f4e4afa313520d9a..a514dd69a65986b693a2fd3b092294819349832f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2018-06-20  Joseph Myers  <joseph@codesourcery.com>
 
+       * string/tst-cmp.c: Include <libc-diag.h>.
+       (strncmp_max): Disable -Wstringop-overflow= around call to
+       strncmp.
+       (strncasecmp_max): Disable -Wstringop-overflow= around call to
+       strncasecmp.
+
        * string/bug-strpbrk1.c: Include <libc-diag.h>.
        (main): Disable -Wunused-value around call to strpbrk.
        * string/bug-strspn1.c: Include <libc-diag.h>.
index 1a7f1c8b89e6f462ca6b9ec9771a7a23d070a223..3b9f7b2506dabd747676c65cf366fc073bc0ba88 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include <libc-diag.h>
 
 static int
 signum (int val)
@@ -98,13 +99,27 @@ strncasecmp_64 (const char *left, const char *right)
 static int
 strncmp_max (const char *left, const char *right)
 {
+  DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+  /* GCC 9 warns about the size passed to strncmp being larger than
+     PTRDIFF_MAX; the use of SIZE_MAX is deliberate here.  */
+  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wstringop-overflow=");
+#endif
   return strncmp (left, right, SIZE_MAX);
+  DIAG_POP_NEEDS_COMMENT;
 }
 
 static int
 strncasecmp_max (const char *left, const char *right)
 {
+  DIAG_PUSH_NEEDS_COMMENT;
+#if __GNUC_PREREQ (7, 0)
+  /* GCC 9 warns about the size passed to strncasecmp being larger
+     than PTRDIFF_MAX; the use of SIZE_MAX is deliberate here.  */
+  DIAG_IGNORE_NEEDS_COMMENT (9, "-Wstringop-overflow=");
+#endif
   return strncasecmp (left, right, SIZE_MAX);
+  DIAG_POP_NEEDS_COMMENT;
 }
 
 int