This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

basic_string bug


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
*********************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]