re PR libstdc++/4548 (When reserving a string to become smaller, program crashes)
2001-11-21 Paolo Carlini <pcarlini@unitus.it> PR libstdc++/4548 * include/bits/basic_string.tcc (basic_string::reserve): Never shrink below the current size. * testsuite/21_strings/capacity.cc (test02): Add test. From-SVN: r47246
This commit is contained in:
parent
ae1139f97d
commit
dcc61724f1
|
@ -1,3 +1,10 @@
|
|||
2001-11-21 Paolo Carlini <pcarlini@unitus.it>
|
||||
|
||||
PR libstdc++/4548
|
||||
* include/bits/basic_string.tcc (basic_string::reserve): Never shrink
|
||||
below the current size.
|
||||
* testsuite/21_strings/capacity.cc (test02): Add test.
|
||||
|
||||
2001-11-19 Phil Edwards <pme@gcc.gnu.org>
|
||||
|
||||
* docs/doxygen/Intro.3: More notes.
|
||||
|
|
|
@ -315,6 +315,9 @@ namespace std
|
|||
{
|
||||
if (__res > this->max_size())
|
||||
__throw_length_error("basic_string::reserve");
|
||||
// Make sure we don't shrink below the current size
|
||||
if (__res < this->size())
|
||||
__res = this->size();
|
||||
allocator_type __a = get_allocator();
|
||||
_CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
|
||||
_M_rep()->_M_dispose(__a);
|
||||
|
|
|
@ -169,9 +169,30 @@ bool test01()
|
|||
return test;
|
||||
}
|
||||
|
||||
// libstdc++/4548
|
||||
// http://gcc.gnu.org/ml/libstdc++/2001-11/msg00150.html
|
||||
bool test02()
|
||||
{
|
||||
bool test = true;
|
||||
|
||||
std::string str01 = "twelve chars";
|
||||
// str01 becomes shared
|
||||
std::string str02 = str01;
|
||||
str01.reserve(1);
|
||||
VERIFY( str01.capacity() == 12 );
|
||||
|
||||
#ifdef DEBUG_ASSERT
|
||||
assert(test);
|
||||
#endif
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
test01();
|
||||
test02();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue