This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
basic_string bug
- To: libstdc++@sourceware.cygnus.com
- Subject: basic_string bug
- From: Vadim Egorov <egorovv@1c.ru>
- Date: Wed, 02 Jun 1999 15:07:58 +0400
Hi,
I found a bug in basic_string which causes memory
underallocation/owerwrite
following code :
string str(30, 'q');
string str2 = str;
str = str2 + str ;
cout << "size:" << str.size() << ",capacity:" << str.capacity()
<< endl;
gives output:
size:60,capacity:32
Here is small patch fixing the problem
Regards,
Vadim
1999-06-02 Vadim Egorov <egorovv@1c.ru>
* bits/string.tcc (basic_string::_M_mutate): Fixed memory
allocation error
Index: string.tcc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/string.tcc,v
retrieving revision 1.34
diff -c -r1.34 string.tcc
*** string.tcc 1999/05/07 10:20:23 1.34
--- string.tcc 1999/06/02 10:44:48
***************
*** 273,279 ****
}
else
{
! _Rep* __r = _Rep::_S_create (__old_size, get_allocator ());
try
{
if (__keep)
--- 273,279 ----
}
else
{
! _Rep* __r = _Rep::_S_create (__nsize, get_allocator ());
try
{
if (__keep)
--
*********************************************
Vadim Egorov, 1C * Вадим Егоров,1C
egorovv@1c.ru * egorovv@1c.ru
*********************************************