From a25e17bd53831d2478d7e3cf0e1f65b1be69d31c Mon Sep 17 00:00:00 2001 From: Mikhail Kashkarov Date: Thu, 3 May 2018 15:03:17 +0300 Subject: Fix string::operator= with disable sso. Found this case during aarch64 build: __str may be null and setting new length with clear() will cause error. Change-Id: I93ad10b4c15ed293d1228243591a1ec1ed22c4d9 --- libstdc++-v3/include/bits/basic_string.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 61e16ae4d94..7a899c16dd7 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -940,13 +940,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 // Replace allocator if POCMA is true. std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator()); + pointer __data = nullptr; if (!__str._M_is_local() && (_Alloc_traits::_S_propagate_on_move_assign() || _Alloc_traits::_S_always_equal())) { __annotate_delete(); __str.__annotate_delete(); - pointer __data = nullptr; size_type __capacity; #ifdef _GLIBCXX_HAS_ASAN size_type __length; @@ -1007,7 +1007,10 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 else { assign(__str); } - __str.clear(); +#ifdef _GLIBCXX_DISABLE_STRING_SSO + if (__data) +#endif + __str.clear(); #ifdef _GLIBCXX_HAS_ASAN _M_capacity(__str_capacity); #ifdef _GLIBCXX_DISABLE_STRING_SSO -- cgit v1.2.3