basic_string bug
Vadim Egorov
egorovv@1c.ru
Wed Jun 23 00:13:00 GMT 1999
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
*********************************************
More information about the Libstdc++
mailing list