aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-12-10 11:21:50 -0500
committerJason Merrill <jason@redhat.com>2021-12-10 23:58:13 -0500
commit2e8067041d1d69da02bd7578f58abc11eb35a04b (patch)
tree5b3b28b4f30f602d6f8e96592a560f9803b3e08d /libstdc++-v3/include/bits
parent0bceef1671adee52e9cc409d82e5f5590fed8d45 (diff)
downloadgcc-2e8067041d1d69da02bd7578f58abc11eb35a04b.zip
gcc-2e8067041d1d69da02bd7578f58abc11eb35a04b.tar.gz
gcc-2e8067041d1d69da02bd7578f58abc11eb35a04b.tar.bz2
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.
Diffstat (limited to 'libstdc++-v3/include/bits')
-rw-r--r--libstdc++-v3/include/bits/basic_string.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 4007a8d..3da2f80 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -1382,7 +1382,7 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX20_CONSTEXPR
basic_string&
append(const basic_string& __str)
- { return _M_append(__str._M_data(), __str.size()); }
+ { return this->append(__str._M_data(), __str.size()); }
/**
* @brief Append a substring.
@@ -1400,9 +1400,9 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11
_GLIBCXX20_CONSTEXPR
basic_string&
append(const basic_string& __str, size_type __pos, size_type __n = npos)
- { return _M_append(__str._M_data()
- + __str._M_check(__pos, "basic_string::append"),
- __str._M_limit(__pos, __n)); }
+ { return this->append(__str._M_data()
+ + __str._M_check(__pos, "basic_string::append"),
+ __str._M_limit(__pos, __n)); }
/**
* @brief Append a C substring.