aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorPaolo Carlini <pcarlini@suse.de>2006-07-03 19:27:55 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2006-07-03 19:27:55 +0000
commit2da7ea252a6b95314132dea56d806501a3303f77 (patch)
treef7eadefd7127a170c113a912ec9e4098e8cf2979 /libstdc++-v3
parent7aa6ba766c8438ca61e08d85573256d00278cc50 (diff)
downloadgcc-2da7ea252a6b95314132dea56d806501a3303f77.zip
gcc-2da7ea252a6b95314132dea56d806501a3303f77.tar.gz
gcc-2da7ea252a6b95314132dea56d806501a3303f77.tar.bz2
rc_string_base.h (__rc_string_base::_S_max_size): Adjust, take into account rounding in _M_create.
2006-07-03 Paolo Carlini <pcarlini@suse.de> * include/ext/rc_string_base.h (__rc_string_base::_S_max_size): Adjust, take into account rounding in _M_create. (__rc_string_base::_M_create): Add early _S_max_size check. From-SVN: r115158
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog6
-rw-r--r--libstdc++-v3/include/ext/rc_string_base.h16
2 files changed, 17 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 01868aa..5e4c01e 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,9 @@
+2006-07-03 Paolo Carlini <pcarlini@suse.de>
+
+ * include/ext/rc_string_base.h (__rc_string_base::_S_max_size):
+ Adjust, take into account rounding in _M_create.
+ (__rc_string_base::_M_create): Add early _S_max_size check.
+
2006-07-03 Ian Lance Taylor <ian@airs.com>
Paolo Carlini <pcarlini@suse.de>
diff --git a/libstdc++-v3/include/ext/rc_string_base.h b/libstdc++-v3/include/ext/rc_string_base.h
index 9470db7..eec6f2d 100644
--- a/libstdc++-v3/include/ext/rc_string_base.h
+++ b/libstdc++-v3/include/ext/rc_string_base.h
@@ -175,11 +175,13 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
// with a terminating character and m _CharT elements, it'd
// look like this:
// npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
+ // + sizeof(_Rep) - 1
+ // (NB: last two terms for rounding reasons, see _M_create below)
// Solving for m:
- // m = ((npos - sizeof(_Rep)) / sizeof(_CharT)) - 1
+ // m = ((npos - 2 * sizeof(_Rep) + 1) / sizeof(_CharT)) - 1
// In addition, this implementation halfs this amount.
- enum { _S_max_size = (((static_cast<size_type>(-1) - sizeof(_Rep))
- / sizeof(_CharT)) - 1) / 2 };
+ enum { _S_max_size = (((static_cast<size_type>(-1) - 2 * sizeof(_Rep)
+ + 1) / sizeof(_CharT)) - 1) / 2 };
// Data Member (private):
mutable typename _Util_Base::template _Alloc_hider<_Alloc> _M_dataplus;
@@ -386,7 +388,12 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
// meet amortized linear time requirements of the library: see
// http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html.
if (__capacity > __old_capacity && __capacity < 2 * __old_capacity)
- __capacity = 2 * __old_capacity;
+ {
+ __capacity = 2 * __old_capacity;
+ // Never allocate a string bigger than _S_max_size.
+ if (__capacity > size_type(_S_max_size))
+ __capacity = size_type(_S_max_size);
+ }
// NB: Need an array of char_type[__capacity], plus a terminating
// null char_type() element, plus enough for the _Rep data structure,
@@ -401,7 +408,6 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
{
const size_type __extra = __pagesize - __adj_size % __pagesize;
__capacity += __extra / sizeof(_CharT);
- // Never allocate a string bigger than _S_max_size.
if (__capacity > size_type(_S_max_size))
__capacity = size_type(_S_max_size);
__size = (__capacity + 1) * sizeof(_CharT) + 2 * sizeof(_Rep) - 1;