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


Hello,
There is a bug in basic_string<>::_Rep::_S_create that results in too
small storage allocated in case of sizeof(char) < sizeof(char_type).

Here is a patch.

Regards,
Vadim.


1999-06-23  Vadim Egorov  <egorovv@1c.ru>

        * bits/string.tcc(basic_string<>::_Rep::_S_create): Fixed
        allocated size

Index: string.tcc
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/string.tcc,v
retrieving revision 1.39
diff -c -r1.39 string.tcc
*** string.tcc  1999/06/09 02:21:05     1.39
--- string.tcc  1999/06/22 20:36:12
***************
*** 282,288 ****
        // NB: Need an array of char_type[__capacity], plus a
        // terminating null char_type() element, plus enough for the
        // _Rep data structure. Whew. Seemingly so needy, yet so
elemental.
!       size_t __size = (__capacity + 1 * sizeof(_CharT)) +
sizeof(_Rep);
        // NB: Might throw, but no worries about a leak, mate: _Rep()
        // does not throw.
        void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);
--- 282,288 ----
        // NB: Need an array of char_type[__capacity], plus a
        // terminating null char_type() element, plus enough for the
        // _Rep data structure. Whew. Seemingly so needy, yet so
elemental.
!       size_t __size = (__capacity + 1) * sizeof(_CharT) +
sizeof(_Rep);
        // NB: Might throw, but no worries about a leak, mate: _Rep()
        // does not throw.
        void* __place = _Raw_bytes_alloc(__alloc).allocate(__size);

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