In Test/System.Text:
authorBen Maurer <benm@mono-cvs.ximian.com>
Fri, 6 May 2005 20:33:08 +0000 (20:33 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Fri, 6 May 2005 20:33:08 +0000 (20:33 -0000)
2005-05-06  Ben Maurer  <bmaurer@ximian.com>

* StringBuilderTest.cs (MaxCapacity_Overflow3): Test for #72244.

In System.Text:
2005-05-06  Ben Maurer  <bmaurer@ximian.com>

* StringBuilder.cs (InternalEnsureCapacity): It is possible that
the size we attempt to grow to is more than the max capacity, but
that a smaller size will do. In this case, don't throw an
exception. Fixes #72244

svn path=/trunk/mcs/; revision=44166

mcs/class/corlib/System.Text/ChangeLog
mcs/class/corlib/System.Text/StringBuilder.cs
mcs/class/corlib/Test/System.Text/ChangeLog
mcs/class/corlib/Test/System.Text/StringBuilderTest.cs

index cf8aefea802eeda1fdd6bdcf227e080508df94df..394bd2e8c787246be126149591d104402dda1624 100755 (executable)
@@ -1,3 +1,10 @@
+2005-05-06  Ben Maurer  <bmaurer@ximian.com>
+
+       * StringBuilder.cs (InternalEnsureCapacity): It is possible that
+       the size we attempt to grow to is more than the max capacity, but
+       that a smaller size will do. In this case, don't throw an
+       exception. Fixes #72244
+
 2005-04-16  Atsushi Enomoto  <atsushi@ximian.com>
 
        * NormalizationForm.cs : new file.
index 0f60ab857e62f10cfa1434472802f7d9aba34057..9c229bfdeb7db1b426f8ef60aafa76fdf3096b0f 100644 (file)
@@ -644,8 +644,7 @@ namespace System.Text {
                                int capacity = _str.Length;
 
                                // Try double buffer, if that doesn't work, set the length as capacity
-                               if (size > capacity) 
-                               {
+                               if (size > capacity) {
                                        
                                        // The first time a string is appended, we just set _cached_str
                                        // and _str to it. This allows us to do some optimizations.
@@ -660,6 +659,9 @@ namespace System.Text {
                                        if (capacity >= Int32.MaxValue || capacity < 0)
                                                capacity = Int32.MaxValue;
 
+                                       if (capacity > _maxCapacity && size <= _maxCapacity)
+                                               capacity = _maxCapacity;
+                                       
                                        if (capacity > _maxCapacity)
                                                throw new ArgumentOutOfRangeException ("size", "capacity was less than the current size.");
                                }
index 4f1df8b45ce9c5d36fb6635accd941e3c2e3caca..6907c6d6692eda0e2012290261c2fa11e698a37d 100644 (file)
@@ -1,3 +1,7 @@
+2005-05-06  Ben Maurer  <bmaurer@ximian.com>
+
+       * StringBuilderTest.cs (MaxCapacity_Overflow3): Test for #72244.
+
 2005-01-21  Ben Maurer  <bmaurer@ximian.com>
 
        * StringBuilderTest.cs (CapacityFromString): This relies on impl
index 8f278eaeb4c3c0b14bfd740e99e90a600962ae79..4e55efa82e3fc030221562d06f4fb223aac4f909 100644 (file)
@@ -441,8 +441,19 @@ namespace MonoTests.System.Text {
 \r
                AssertEquals (2, sb.Capacity);\r
                AssertEquals (3, sb.MaxCapacity);\r
+       }
+       
+       [Test]
+       public void MaxCapacity_Overflow3 ()
+       {
+               //
+               // When the capacity (4) gets doubled, it is greater than the
+               // max capacity. This makes sure that before throwing an exception
+               // we first attempt to go for a smaller size.
+               //
+               new StringBuilder(4, 7).Append ("foo").Append ("bar");
+               new StringBuilder(4, 6).Append ("foo").Append ("bar");
        }\r
-\r
        [Test]\r
        public void CapacityFromString ()\r
        {\r