diff options
author | Mikhail Kashkarov <m.kashkarov@partner.samsung.com> | 2018-04-28 19:03:17 +0300 |
---|---|---|
committer | Mikhail Kashkarov <m.kashkarov@partner.samsung.com> | 2018-04-28 19:03:17 +0300 |
commit | 42d1cd35c5a25fff440354beffa63aab2811f9ac (patch) | |
tree | 2bc4cc61d65df43be8fc64488caa627e3ff3bda5 | |
parent | ade91a43e02a944e8aafb329e1e7d2fc30f95322 (diff) | |
download | linaro-gcc-42d1cd35c5a25fff440354beffa63aab2811f9ac.tar.gz linaro-gcc-42d1cd35c5a25fff440354beffa63aab2811f9ac.tar.bz2 linaro-gcc-42d1cd35c5a25fff440354beffa63aab2811f9ac.zip |
Fix basic_string::reserve in case of disabled SSO
Keep buffer alive after relocations.
Change-Id: I71d0a6a2f23779b6c802661ae0a0095fdb1fd45c
-rw-r--r-- | libstdc++-v3/include/bits/basic_string.tcc | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index d8fe861399e..6036549598f 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -350,27 +350,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } else if (!_M_is_local()) { - #ifndef _GLIBCXX_DISABLE_STRING_SSO - this->_S_copy(_M_local_data(), _M_data(), length() + 1); - #endif - // 27 march -- COMMIT THIS, TEST CASE: - // int main() { - // std::string a = "string"; - // std::string b = "other string"; - // a.reserve(10); - // b.reserve(20); - // a.swap(b); - // a.reserve(10 - - _M_capacity(__capacity); +#ifndef _GLIBCXX_DISABLE_STRING_SSO + this->_S_copy(_M_local_data(), _M_data(), length() + 1); + _M_destroy(__capacity); + _M_capacity(__res); +#endif + _M_capacity(__res); //__annotate_new(length()); - _M_destroy(__capacity); // __annotate_new(length()); - #ifndef _GLIBCXX_DISABLE_STRING_SSO - _M_data(_M_local_data()); - #endif - } - } +#ifndef _GLIBCXX_DISABLE_STRING_SSO + _M_data(_M_local_data()); +#endif + } + } } template<typename _CharT, typename _Traits, typename _Alloc> |