aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/ext/rc_string.h
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/include/ext/rc_string.h')
-rw-r--r--libstdc++-v3/include/ext/rc_string.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/libstdc++-v3/include/ext/rc_string.h b/libstdc++-v3/include/ext/rc_string.h
index 0ece46583c3..7857330eacf 100644
--- a/libstdc++-v3/include/ext/rc_string.h
+++ b/libstdc++-v3/include/ext/rc_string.h
@@ -618,10 +618,17 @@ namespace __gnu_cxx
__rc_string<_CharT, _Traits, _Alloc>::
_M_reserve(size_type __res)
{
- const allocator_type __a = _M_get_allocator();
- _CharT* __tmp = _M_rep()->_M_clone(__a, __res - _M_length());
- _M_dispose(__a);
- _M_data(__tmp);
+ if (__res != _M_capacity() || _M_is_shared())
+ {
+ // Make sure we don't shrink below the current size.
+ if (__res < _M_length())
+ __res = _M_length();
+
+ const allocator_type __a = _M_get_allocator();
+ _CharT* __tmp = _M_rep()->_M_clone(__a, __res - _M_length());
+ _M_dispose(__a);
+ _M_data(__tmp);
+ }
}
template<typename _CharT, typename _Traits, typename _Alloc>