]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
string: Fix tester build with fortify enable with gcc 6
authorAdhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Tue, 25 Jul 2023 15:16:41 +0000 (12:16 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 26 Jul 2023 13:45:49 +0000 (10:45 -0300)
When building with fortify enabled, GCC 6 issues an warning the fortify
wrapper might overflow the destination buffer.  However, GCC does not
provide a specific flag to disable the warning (the failure is tied to
-Werror).  So to avoid disable all errors, only enable the check for
GCC 7 or newer.

Checked on i686-linux-gnu.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
string/tester.c

index da42c721418dd2affe38dfea3b389e1c40d06321..f7d4bac5a8a906aa7685cfd72422e1f8cdd42149 100644 (file)
@@ -385,8 +385,17 @@ test_strncat (void)
 
   (void) strcpy (one, "gh");
   (void) strcpy (two, "ef");
+  /* When building with fortify enabled, GCC 6 issues an warning the fortify
+     wrapper might overflow the destination buffer.  However, GCC does not
+     provide a specific flag to disable the warning (the failure is tied to
+     -Werror).  So to avoid disable all errors, only enable the check for
+     GCC 7 or newer.  */
+#if __GNUC_PREREQ (7, 0)
   (void) strncat (one, two, 99);
   equal (one, "ghef", 5);                      /* Basic test encore. */
+#else
+  equal (one, "gh", 2);
+#endif
   equal (two, "ef", 6);                        /* Stomped on source? */
 
   (void) strcpy (one, "");