From 8f12793ca5e7c9aa7c23a17400986878ae110e70 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 6 May 2021 19:07:04 +0200 Subject: lib:replace: Do not build strndup test with gcc 11 or newer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG: https://bugzilla.samba.org/show_bug.cgi?id=14699 gcc11 with -O3 detects that the size is incorrect: lib/replace/tests/testsuite.c:286:13: error: ‘strndup’ specified bound 10 exceeds source size 4 [-Werror=stringop-overread] 286 | x = strndup("bla", 10); | ^~~~~~~~~~~~~~~~~~ Signed-off-by: Andreas Schneider Reviewed-by: Guenther Deschner --- lib/replace/tests/testsuite.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/replace') diff --git a/lib/replace/tests/testsuite.c b/lib/replace/tests/testsuite.c index ce344d6549e..b4b038af8c7 100644 --- a/lib/replace/tests/testsuite.c +++ b/lib/replace/tests/testsuite.c @@ -283,6 +283,15 @@ static int test_strndup(void) return false; } +#ifdef __GNUC__ +# if __GNUC__ < 11 + /* + * This code will not compile with gcc11 -O3 anymore. + * + * error: ‘strndup’ specified bound 10 exceeds source size 4 [-Werror=stringop-overread] + * x = strndup("bla", 10); + * ^~~~~~~~~~~~~~~~~~ + */ x = strndup("bla", 10); cmp = strcmp(x, "bla"); free(x); @@ -290,6 +299,8 @@ static int test_strndup(void) printf("failure: strndup [\ninvalid\n]\n"); return false; } +# endif +#endif /* __GNUC__ */ printf("success: strndup\n"); return true; -- cgit v1.2.1