diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -2278,8 +2278,11 @@ if (__delta_cap > __ms - __old_cap - 1) this->__throw_length_error(); pointer __old_p = __get_pointer(); + const bool __was_short = __old_cap + 1 == __min_cap; size_type __cap = __old_cap < __ms / 2 - __alignment ? - __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : + __recommend( + _VSTD::max(__old_cap + __delta_cap, + __was_short ? 0 : 2 * __old_cap)) : __ms - 1; pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); __invalidate_all_iterators(); @@ -2292,7 +2295,7 @@ if (__sec_cp_sz != 0) traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add, _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); - if (__old_cap+1 != __min_cap) + if (!__was_short) __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1); @@ -2310,8 +2313,11 @@ if (__delta_cap > __ms - __old_cap) this->__throw_length_error(); pointer __old_p = __get_pointer(); + const bool __was_short = __old_cap + 1 == __min_cap; size_type __cap = __old_cap < __ms / 2 - __alignment ? - __recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) : + __recommend( + _VSTD::max(__old_cap + __delta_cap, + __was_short ? 0 : 2 * __old_cap)) : __ms - 1; pointer __p = __alloc_traits::allocate(__alloc(), __cap+1); __invalidate_all_iterators(); @@ -2323,7 +2329,7 @@ traits_type::copy(_VSTD::__to_address(__p) + __n_copy + __n_add, _VSTD::__to_address(__old_p) + __n_copy + __n_del, __sec_cp_sz); - if (__old_cap+1 != __min_cap) + if (!__was_short) __alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1); __set_long_pointer(__p); __set_long_cap(__cap+1);