[Mono-list] bug in ArrayList::RemoveRange ()

Varga Zoltan vargaz@freemail.hu
Sun, 12 Jan 2003 17:59:33 +0100 (CET)


--0-1804289383-1042390773=:88315
Content-Type: TEXT/PLAIN; CHARSET=ISO-8859-2


                                         Hi,

  Under MS .NET, RemoveRange () allows a zero sized removal
at the end
of the list, i.e. 

aList.RemoveRange (aList.Count, 0)

works. There is code out there which depends on this behavior.

The attached patch fixes this. It also cleans up the
argument checking code so the raised exceptions have the
same message as under MS.NET.


--0-1804289383-1042390773=:88315
Content-Type: APPLICATION/octet-stream; name="arraylist.patch"
Content-Disposition: attachment; filename="arraylist.patch"

Index: System.Collections/ArrayList.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System.Collections/ArrayList.cs,v
retrieving revision 1.39
diff -u -3 -p -r1.39 ArrayList.cs
--- System.Collections/ArrayList.cs	10 Jan 2003 21:54:44 -0000	1.39
+++ System.Collections/ArrayList.cs	12 Jan 2003 16:57:28 -0000
@@ -892,10 +892,17 @@ namespace System.Collections {
 					("Collection is fixed size.");
 			}
 
-			if (index < 0 || index >= this.count || index + count > this.count) {
-				throw new ArgumentOutOfRangeException
-					("index/count out of range");
-			}
+			if (index < 0)
+				throw new ArgumentOutOfRangeException 
+					("index", "Non-negative number required.");
+
+			if (count < 0)
+				throw new ArgumentOutOfRangeException 
+					("count", "Non-negative number required.");
+
+			if (index + count > this.count)
+				throw new ArgumentException
+					("Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
 
 			shiftElements (index, - count);
 			this.count -= count;

--0-1804289383-1042390773=:88315--