From 2e8067041d1d69da02bd7578f58abc11eb35a04b Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 10 Dec 2021 11:21:50 -0500 Subject: libstdc++: check length in string append [PR103534] In the testcase for 103534 we get a warning about append leading to memcpy of a very large number of bytes overflowing the buffer. This turns out to be because we weren't calling _M_check_length for string append. Rather than do that directly, let's go through the public pointer append that calls it. PR c++/103534 libstdc++-v3/ChangeLog: * include/bits/basic_string.h (append (basic_string)): Call pointer append instead of _M_append directly. gcc/testsuite/ChangeLog: * g++.dg/warn/Wstringop-overflow-8.C: New test. --- gcc/testsuite/g++.dg/warn/Wstringop-overflow-8.C | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/Wstringop-overflow-8.C (limited to 'gcc') diff --git a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-8.C b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-8.C new file mode 100644 index 0000000..d0ef5e7 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-8.C @@ -0,0 +1,10 @@ +// PR c++/103534 +// { dg-additional-options "-O -Wall" } + +#include + +std::string foo(std::string x) +{ + // This used to get a bogus -Wstringop-overflow warning. + return std::string("1234567890123456") + x; +} -- cgit v1.1