From 088e6015b20fd097f7b00bb330c359added2c9c5 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 7 Feb 2018 21:30:17 +0000 Subject: [PATCH] Fix PR#31454 - 'basic_string::push_back() crashes if sizeof(T)>sizeof(long long)'. We were mishandling the small-string optimization calculations for very large 'characters'. This may be an ABI change (change the size of) strings of very large 'characters', but since they never worked, I'm not too concerned. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@324531 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/string | 10 +++++++--- .../string.modifiers/string_append/push_back.pass.cpp | 3 +-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/string b/include/string index b213cd411..f89ef5741 100644 --- a/include/string +++ b/include/string @@ -1363,9 +1363,13 @@ private: enum {__alignment = 16}; static _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __s) _NOEXCEPT - {return (__s < __min_cap ? static_cast(__min_cap) : - __align_it (__s+1)) - 1;} + { + if (__s < __min_cap) return static_cast(__min_cap) - 1; + size_type __guess = __align_it (__s+1) - 1; + if (__guess == __min_cap) ++__guess; + return __guess; + } inline void __init(const value_type* __s, size_type __sz, size_type __reserve); diff --git a/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp b/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp index 5ca5aaf86..128446534 100644 --- a/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp +++ b/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp @@ -48,7 +48,7 @@ int main() test(S("12345678901234567890"), 'a', S("12345678901234567890a")); } #endif -#if 0 + { // https://bugs.llvm.org/show_bug.cgi?id=31454 std::basic_string s; @@ -57,5 +57,4 @@ int main() s.push_back(vl); s.push_back(vl); } -#endif }