diff gcc/testsuite/gcc.dg/Wstringop-overflow-26.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-26.c	Thu Feb 13 11:34:05 2020 +0900
@@ -0,0 +1,20 @@
+/* PR middle-end/79221 - missing -Wstringop-overflow= on a strcat overflow
+   { dg-do compile }
+   { dg-options "-O2 -Wall" } */
+
+extern char* strcat (char*, const char*);
+
+char d[3];
+
+void f (int i)
+{
+  const char *s = i < 0 ? "01234567" : "89abcd";
+  strcat (d, s);    // { dg-warning "'strcat' writing between 7 and 9 bytes into a region of size 3" } */
+}
+
+
+void g (int i)
+{
+  const char *s = i < 0 ? "12345678" : "87654321";
+  strcat (d, s);    // { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" }
+}