This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] ext/vstring fixes


Hi,

tested x86-linux (for real in the v7-branch + mainline), committed mainline and 4_1-branch.

Paolo.

//////////////////////
2006-07-03  Ian Lance Taylor  <ian@airs.com>
	    Paolo Carlini  <pcarlini@suse.de>

	* include/ext/rc_string_base.h (__rc_string_base::_S_max_size):
	Increase by a factor of two.
	* include/ext/sso_string_base.h (__sso_string_base::_S_max_size):
	Likewise.

2006-07-03  Paolo Carlini  <pcarlini@suse.de>

	* include/ext/sso_string_base.h (__sso_string_base::_M_create): Never
	allocate a string bigger than _S_max_size.
Index: include/ext/rc_string_base.h
===================================================================
--- include/ext/rc_string_base.h	(revision 115147)
+++ include/ext/rc_string_base.h	(working copy)
@@ -177,9 +177,9 @@
       // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT)
       // Solving for m:
       // m = ((npos - sizeof(_Rep)) / sizeof(_CharT)) - 1
-      // In addition, this implementation quarters this amount.
+      // In addition, this implementation halfs this amount.
       enum { _S_max_size = (((static_cast<size_type>(-1) - sizeof(_Rep))
-			     / sizeof(_CharT)) - 1) / 4 };
+			     / sizeof(_CharT)) - 1) / 2 };
 
       // Data Member (private):
       mutable typename _Util_Base::template _Alloc_hider<_Alloc>  _M_dataplus;
Index: include/ext/sso_string_base.h
===================================================================
--- include/ext/sso_string_base.h	(revision 115147)
+++ include/ext/sso_string_base.h	(working copy)
@@ -61,9 +61,9 @@
       // npos = m * sizeof(_CharT) + sizeof(_CharT)
       // Solving for m:
       // m = npos / sizeof(_CharT) - 1
-      // In addition, this implementation quarters this amount.
+      // In addition, this implementation halfs this amount.
       enum { _S_max_size = (((static_cast<size_type>(-1)
-			      / sizeof(_CharT)) - 1) / 4) };
+			      / sizeof(_CharT)) - 1) / 2) };
 
       // Data Members (private):
       typename _Util_Base::template _Alloc_hider<_CharT_alloc_type>
@@ -325,7 +325,12 @@
       // 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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]