]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib:replace: Do not build strndup test with gcc 11 or newer
authorAndreas Schneider <asn@samba.org>
Thu, 6 May 2021 17:07:04 +0000 (19:07 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 7 May 2021 06:23:32 +0000 (06:23 +0000)
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>
lib/replace/tests/testsuite.c

index ce344d6549e4c3133fe5f2f7c5e6430d9701d0b5..b4b038af8c74f27b6511ee5cb693c46320f26e87 100644 (file)
@@ -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;