+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.
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.
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.");
}
+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
\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