]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
basic_string.tcc (_Rep::_S_create): Never allocate a string bigger than max_size...
authorPaolo Carlini <pcarlini@suse.de>
Fri, 30 Jan 2004 13:23:42 +0000 (13:23 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 30 Jan 2004 13:23:42 +0000 (13:23 +0000)
2004-01-30  Paolo Carlini  <pcarlini@suse.de>

* include/bits/basic_string.tcc (_Rep::_S_create):
Never allocate a string bigger than max_size(); always keep
__capacity and __size in sync to avoid memory leaks at
deallocation time.

From-SVN: r76955

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.tcc

index e13c44a07c708880a7b04e64b98583c3e3cf211f..0273958d79ecb006c2069f3edc3b0ce49dbacf8f 100644 (file)
@@ -1,3 +1,10 @@
+2004-01-30  Paolo Carlini  <pcarlini@suse.de>
+
+       * include/bits/basic_string.tcc (_Rep::_S_create):
+       Never allocate a string bigger than max_size(); always keep
+       __capacity and __size in sync to avoid memory leaks at
+       deallocation time.
+
 2004-01-30  Paolo Carlini  <pcarlini@suse.de>
 
        * include/bits/basic_string.tcc (_S_construct(_InIterator,
index a478a4cf248380ca5bffd920711bca36fe583222..e35b305cdeb12bee159785489a8e4721db14079b 100644 (file)
@@ -520,7 +520,10 @@ namespace std
                                     - (__size + __malloc_header_size)
                                     % __pagesize);
          __capacity += __extra / sizeof(_CharT);
-         __size += __extra;
+         // Never allocate a string bigger than _S_max_size.
+         if (__capacity > _S_max_size)
+           __capacity = _S_max_size;
+         __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
        }
       else if (__size > __subpagesize)
        {
@@ -528,7 +531,7 @@ namespace std
                                     - (__size + __malloc_header_size)
                                     % __subpagesize);
          __capacity += __extra / sizeof(_CharT);
-         __size += __extra;
+         __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
        }
 
       // NB: Might throw, but no worries about a leak, mate: _Rep()