Updated RemoveItemsRange to prevent int.MaxValue overflow errors
authorAndrew Hoefling <andrew@hoeflingsoftware.com>
Tue, 5 Mar 2019 04:50:36 +0000 (23:50 -0500)
committerSantiago Fernandez Madero <safern@microsoft.com>
Fri, 8 Mar 2019 19:20:58 +0000 (11:20 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/0190ab05d31de5ca020ee7a2325ff3d3625af43a

src/libraries/System.Private.CoreLib/src/System/Collections/ObjectModel/Collection.cs

index 67185eb..a320a4b 100644 (file)
@@ -207,8 +207,12 @@ namespace System.Collections.ObjectModel
                 ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert);
             }
 
-            int indexCount = index + count;
-            int length = indexCount > items.Count ? items.Count : indexCount;
+            int length = items.Count;
+            if (index < items.Count - count)
+            {
+                length = index + count;
+            }
+
             for (int i = index; i < length; i++)
             {
                 RemoveAt(index);