From fefd30867d3fa33ff7cff3fcb4d2c361d1b1d51b Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 10 Jan 2017 22:35:22 +0000 Subject: [PATCH] PR middle-end/78138 - missing warnings on buffer overflow with non-constant source length gcc/testsuite/ChangeLog: PR middle-end/78138 * gcc.dg/pr78138.c: New test. From-SVN: r244297 --- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr78138.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr78138.c diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6fdfcacafeb..8f5f8dfc028 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-01-10 Martin Sebor + + PR middle-end/78138 + * gcc.dg/pr78138.c: New test. + 2017-01-10 David Malcolm PR c++/77949 diff --git a/gcc/testsuite/gcc.dg/pr78138.c b/gcc/testsuite/gcc.dg/pr78138.c new file mode 100644 index 00000000000..ecc9ee655bc --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr78138.c @@ -0,0 +1,22 @@ +/* PR middle-end/78138 - missing warnings on buffer overflow with non-constant + source length + { dg-do compile } + { dg-options "-O2 -Wformat-length" } */ + +char d [5]; + +void* memcpy (void*, const void*, unsigned long); +extern char* strcpy (char*, const char*); + +void f (int i, int j) +{ + strcpy (d, j ? "12345" : "123456"); /* { dg-warning ".strcpy. writing 6 bytes into a region of size 5" } */ +} + +void g (void *p) +{ + extern unsigned n; + if (n < 17 || 32 < n) n = 7; + + memcpy (d, p, n); /* { dg-warning ".memcpy.: writing between 7 and 32 bytes into a region of size 5" } */ +}; -- 2.30.2