Commit d1615643 by Paolo Carlini Committed by Paolo Carlini

basic_string.tcc (_Rep::_S_create): Never allocate a string bigger than max_size()...

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
parent 1e0f41c9
2004-01-30 Paolo Carlini <pcarlini@suse.de> 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, * include/bits/basic_string.tcc (_S_construct(_InIterator,
_InIterator, const _Alloc&, input_iterator_tag)): Simplify _InIterator, const _Alloc&, input_iterator_tag)): Simplify
the double loop, streamline. the double loop, streamline.
......
...@@ -520,7 +520,10 @@ namespace std ...@@ -520,7 +520,10 @@ namespace std
- (__size + __malloc_header_size) - (__size + __malloc_header_size)
% __pagesize); % __pagesize);
__capacity += __extra / sizeof(_CharT); __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) else if (__size > __subpagesize)
{ {
...@@ -528,7 +531,7 @@ namespace std ...@@ -528,7 +531,7 @@ namespace std
- (__size + __malloc_header_size) - (__size + __malloc_header_size)
% __subpagesize); % __subpagesize);
__capacity += __extra / sizeof(_CharT); __capacity += __extra / sizeof(_CharT);
__size += __extra; __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep);
} }
// NB: Might throw, but no worries about a leak, mate: _Rep() // NB: Might throw, but no worries about a leak, mate: _Rep()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment