[libcxx] r324531 - Fix PR#31454 - 'basic_string<T>::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.

Marshall Clow via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 7 13:30:17 PST 2018


Author: marshall
Date: Wed Feb  7 13:30:17 2018
New Revision: 324531

URL: http://llvm.org/viewvc/llvm-project?rev=324531&view=rev
Log:
Fix PR#31454 - 'basic_string<T>::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.

Modified:
    libcxx/trunk/include/string
    libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp

Modified: libcxx/trunk/include/string
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/string?rev=324531&r1=324530&r2=324531&view=diff
==============================================================================
--- libcxx/trunk/include/string (original)
+++ libcxx/trunk/include/string Wed Feb  7 13:30:17 2018
@@ -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<size_type>(__min_cap) :
-                 __align_it<sizeof(value_type) < __alignment ?
-                            __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;}
+        {
+        if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
+        size_type __guess = __align_it<sizeof(value_type) < __alignment ?
+                     __alignment/sizeof(value_type) : 1 > (__s+1) - 1;
+        if (__guess == __min_cap) ++__guess;
+        return __guess;
+        }
 
     inline
     void __init(const value_type* __s, size_type __sz, size_type __reserve);

Modified: libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp?rev=324531&r1=324530&r2=324531&view=diff
==============================================================================
--- libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp (original)
+++ libcxx/trunk/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp Wed Feb  7 13:30:17 2018
@@ -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<veryLarge> s;
@@ -57,5 +57,4 @@ int main()
     s.push_back(vl);
     s.push_back(vl);
     }
-#endif
 }




More information about the cfe-commits mailing list