diff --git a/stl/inc/xstring b/stl/inc/xstring index b034af9425..455e6ae8f1 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -3807,12 +3807,13 @@ public: // either we are shrinking, or the growth fits // may temporarily overflow; OK because size_type must be unsigned const auto _New_size = _Old_size + _Count - _Nx; - _ASAN_STRING_MODIFY(*this, _Old_size, _New_size); + _ASAN_STRING_REMOVE(*this); _Mypair._Myval2._Mysize = _New_size; _Elem* const _Old_ptr = _Mypair._Myval2._Myptr(); _Elem* const _Insert_at = _Old_ptr + _Off; _Traits::move(_Insert_at + _Count, _Insert_at + _Nx, _Old_size - _Nx - _Off + 1); _Traits::assign(_Insert_at, _Count, _Ch); + _ASAN_STRING_CREATE(*this); return *this; } diff --git a/tests/std/tests/GH_002030_asan_annotate_string/test.cpp b/tests/std/tests/GH_002030_asan_annotate_string/test.cpp index dcafe097fe..ae8fd17f33 100644 --- a/tests/std/tests/GH_002030_asan_annotate_string/test.cpp +++ b/tests/std/tests/GH_002030_asan_annotate_string/test.cpp @@ -1913,6 +1913,13 @@ void test_DevCom_10109507() { assert(s == "xyefbcd"); } +void test_gh_3883() { + // GH-3883 : basic_string::replace fails under ASan when pos + count > size, and count2 < count + string t = "0123456789ABCDEF"; // large string + t.replace(0, 30, 7, 'A'); + assert(t == "AAAAAAA"); +} + int main() { run_allocator_matrix(); #ifdef __cpp_char8_t @@ -1924,4 +1931,5 @@ int main() { test_DevCom_10116361(); test_DevCom_10109507(); + test_gh_3883(); }