Skip to content

Commit 56772d8

Browse files
committed
Fix shrink_to_fit to swap buffer only when capacity is strictly smaller
1 parent 3e61c1a commit 56772d8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

libcxx/include/string

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3495,7 +3495,7 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocat
34953495
// The Standard mandates shrink_to_fit() does not increase the capacity.
34963496
// With equal capacity keep the existing buffer. This avoids extra work
34973497
// due to swapping the elements.
3498-
if (__allocation.count - 1 > capacity()) {
3498+
if (__allocation.count - 1 >= capacity()) {
34993499
__alloc_traits::deallocate(__alloc_, __allocation.ptr, __allocation.count);
35003500
return;
35013501
}

0 commit comments

Comments
 (0)