1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

lib:replace: Do not build strndup test with gcc 11 or newer

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 <asn@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
(cherry picked from commit 8f12793ca5e7c9aa7c23a17400986878ae110e70)

Autobuild-User(v4-14-test): Karolin Seeger <kseeger@samba.org>
Autobuild-Date(v4-14-test): Wed May 12 09:07:45 UTC 2021 on sn-devel-184
This commit is contained in:
Andreas Schneider 2021-05-06 19:07:04 +02:00 committed by Karolin Seeger
parent a18d6bdaa5
commit 5611a6999c

View File

@ -272,6 +272,16 @@ static int test_strndup(void)
return false;
}
free(x);
#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);
if (strcmp(x, "bla") != 0) {
printf("failure: strndup [\ninvalid\n]\n");
@ -279,6 +289,9 @@ static int test_strndup(void)
return false;
}
free(x);
# endif
#endif /* __GNUC__ */
printf("success: strndup\n");
return true;
}