Skip to content

Commit 32dfa3a

Browse files
author
Advenam Tacet
committed
[libc++] Remove usage of internal string function in sstream
This function replaces a call to `__move_assign` (internal function) with two calls to public member functions (`resize` and `erase`). The order of call is chosen for the best performance. This change is required to turn on ASan string annotations for short strings (Short String Optimization - SSO). The `std::basic_string` class's `void __move_assign(basic_string&& __str, size_type __pos, size_type __len)` function operates on uninitialized strings, where it is reasonable to assume that the memory is not poisoned. However, in `sstream` this function is applied to existing strings that may already have poisoned memory. String ASan annotations turned on here: #72677
1 parent cdc0392 commit 32dfa3a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libcxx/include/sstream

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ public:
398398
typename string_type::size_type __pos = __view.empty() ? 0 : __view.data() - __str_.data();
399399
// In C++23, this is just string_type(std::move(__str_), __pos, __view.size(), __str_.get_allocator());
400400
// But we need something that works in C++20 also.
401-
string_type __result(__str_.get_allocator());
402-
__result.__move_assign(std::move(__str_), __pos, __view.size());
403-
__str_.clear();
401+
string_type __result(std::move(__str_), __str_.get_allocator());
402+
__result.resize(__pos + __view.size());
403+
__result.erase(0, __pos);
404404
__init_buf_ptrs();
405405
return __result;
406406
}

0 commit comments

Comments
 (0)