From 0a22f996399c968efe9bfec96bd9f87ee537be12 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Wed, 11 Dec 2019 15:59:55 +0000 Subject: [PATCH] PR middle-end/79221 - missing -Wstringop-overflow= on a strcat overflow gcc/testsuite/ChangeLog: * gcc.dg/Wstringop-overflow-26.c: New test. From-SVN: r279227 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/Wstringop-overflow-26.c | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/Wstringop-overflow-26.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 25a13a3dd97f..0942db0dc013 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-11 Martin Sebor + + PR middle-end/79221 + * gcc.dg/Wstringop-overflow-26.c: New test. + 2019-12-11 Andre Vieira * gcc.dg/vect/vect-epilogues.c: Remove xfail for arm. diff --git a/gcc/testsuite/gcc.dg/Wstringop-overflow-26.c b/gcc/testsuite/gcc.dg/Wstringop-overflow-26.c new file mode 100644 index 000000000000..4e8765eedbb8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wstringop-overflow-26.c @@ -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" } +} -- 2.47.2