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>
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);
printf("failure: strndup [\ninvalid\n]\n");
return false;
}
+# endif
+#endif /* __GNUC__ */
printf("success: strndup\n");
return true;