diff options
author | Martin Sebor <msebor@redhat.com> | 2021-03-08 13:28:52 -0700 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-03-08 13:28:52 -0700 |
commit | 7f5ff78ff3f971c11ec67f422b2fd34281db9123 (patch) | |
tree | b7458cb5524353d63a17efea75f21868f8259978 /gcc/testsuite/c-c++-common/Wstringop-overflow.c | |
parent | b64551af5159ea30b5941ddd430001b13936822c (diff) | |
download | gcc-7f5ff78ff3f971c11ec67f422b2fd34281db9123.zip gcc-7f5ff78ff3f971c11ec67f422b2fd34281db9123.tar.gz gcc-7f5ff78ff3f971c11ec67f422b2fd34281db9123.tar.bz2 |
PR middle-end/97631 - bogus "writing one too many bytes" warning for memcpy with strlen argument
gcc/ChangeLog:
PR middle-end/97631
* tree-ssa-strlen.c (maybe_warn_overflow): Test rawmem.
(handle_builtin_stxncpy_strncat): Rename locals. Determine
destination size from allocation calls. Issue a more appropriate
kind of warning.
(handle_builtin_memcpy): Pass true as rawmem to maybe_warn_overflow.
(handle_builtin_memset): Same.
gcc/testsuite/ChangeLog:
PR middle-end/97631
* c-c++-common/Wstringop-overflow.c: Remove unexpected warnings.
Add an xfail.
* c-c++-common/Wstringop-truncation.c: Add expected warnings.
* gcc.dg/Wstringop-overflow-10.c: Also enable -Wstringop-truncation.
* gcc.dg/Wstringop-overflow-66.c: New test.
* gcc.dg/tree-ssa/strncpy-2.c: Adjust expected warning.
Diffstat (limited to 'gcc/testsuite/c-c++-common/Wstringop-overflow.c')
-rw-r--r-- | gcc/testsuite/c-c++-common/Wstringop-overflow.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/gcc/testsuite/c-c++-common/Wstringop-overflow.c b/gcc/testsuite/c-c++-common/Wstringop-overflow.c index 53f5166..5757a23 100644 --- a/gcc/testsuite/c-c++-common/Wstringop-overflow.c +++ b/gcc/testsuite/c-c++-common/Wstringop-overflow.c @@ -115,28 +115,31 @@ void test_strncpy (char **d, const char* s, int i) T (d, "123", sizeof "123"); T (d, ar, sizeof ar); - T (d, s, strlen (s)); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ + /* There is no overflow in the following calls but they are diagnosed + by -Wstringop-truncation. Verify that they aren'y also diagnosed + by -Wstringop-overflow. */ + T (d, s, strlen (s)); { - int n = strlen (s); /* { dg-message "length computed here" } */ - T (d, s, n); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ + int n = strlen (s); + T (d, s, n); } { - unsigned n = strlen (s); /* { dg-message "length computed here" } */ - T (d, s, n); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ + unsigned n = strlen (s); + T (d, s, n); } { size_t n; - n = strlen (s); /* { dg-message "length computed here" } */ - T (d, s, n); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ + n = strlen (s); + T (d, s, n); } { size_t n; - n = strlen (s) - 1; /* { dg-message "length computed here" } */ - T (d, s, n); /* { dg-warning "\\\[-Wstringop-overflow=]" } */ + n = strlen (s) - 1; + T (d, s, n); } { @@ -148,11 +151,8 @@ void test_strncpy (char **d, const char* s, int i) { /* This use of strncpy is certainly dubious and it could well be - diagnosed by -Wstringop-truncation but it isn't. That it is - diagnosed with -Wstringop-overflow is more by accident than - by design. -Wstringop-overflow considers any dependency of - the bound on strlen(s) a potential bug. */ - size_t n = i < strlen (s) ? i : strlen (s); /* { dg-message "length computed here" } */ - T (d, s, n); /* { dg-message ".strncpy\[^\n\r]* specified bound depends on the length of the source argument" } */ + diagnosed by -Wstringop-truncation but it isn't. */ + size_t n = i < strlen (s) ? i : strlen (s); /* { dg-message "length computed here" "note" { xfail *-*-* } } */ + T (d, s, n); /* { dg-message ".strncpy\[^\n\r]* specified bound depends on the length of the source argument" "pr?????" { xfail *-*-* } } */ } } |