[PATCH] string: Fix tester build with fortify enable with gcc < 12

bmahi496@linux.ibm.com bmahi496@linux.ibm.com
Wed Aug 9 12:03:44 GMT 2023


From: Mahesh Bodapati <bmahi496@linux.ibm.com>

When building with fortify enabled, GCC < 12 issues a warning on the
fortify strncat 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 12 or newer.

Checked on ppc64 and x86_64.
---
 string/tester.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/string/tester.c b/string/tester.c
index f7d4bac5a8..cf3f5ae495 100644
--- a/string/tester.c
+++ b/string/tester.c
@@ -421,6 +421,12 @@ test_strncat (void)
   (void) strncat (one, "ij", (size_t)-1);	/* set sign bit in count */
   equal (one, "abcdghij", 13);
 
+  /* When building with fortify enabled, GCC < 12 issues a warning on the
+     fortify strncat 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 12 or newer.  */
+#if __GNUC_PREREQ (12, 0)
   int ntest = 14;
   char buf1[80] __attribute__ ((aligned (16)));
   char buf2[32] __attribute__ ((aligned (16)));
@@ -464,6 +470,7 @@ test_strncat (void)
 		    }
 		}
 	  }
+#endif
 }
 
 static void
-- 
2.31.1



More information about the Libc-alpha mailing list