Fix PR#31454 - 'basic_string<T>::push_back() crashes if sizeof(T)>sizeof(long long...
authorMarshall Clow <mclow.lists@gmail.com>
Wed, 7 Feb 2018 21:30:17 +0000 (21:30 +0000)
committerMarshall Clow <mclow.lists@gmail.com>
Wed, 7 Feb 2018 21:30:17 +0000 (21:30 +0000)
llvm-svn: 324531

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

index b213cd4..f89ef57 100644 (file)
@@ -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);
index 5ca5aaf..1284465 100644 (file)
@@ -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
 }