[linq] fix Range extreme boundaries
authorJb Evain <jbevain@gmail.com>
Tue, 25 Jan 2011 22:45:44 +0000 (23:45 +0100)
committerJb Evain <jbevain@gmail.com>
Tue, 25 Jan 2011 22:45:44 +0000 (23:45 +0100)
mcs/class/System.Core/System.Linq/Enumerable.cs

index d0a4c77a73247f4d7bc11d5467082119503c44d4..56d52d4f45391875d38289ed1c46b9af57243fd7 100644 (file)
@@ -2163,18 +2163,16 @@ namespace System.Linq
                        if (count < 0)
                                throw new ArgumentOutOfRangeException ("count");
 
-                       long upto = ((long) start + count) - 1;
-
-                       if (upto > int.MaxValue)
+                       if (((long) start + count) - 1L > int.MaxValue)
                                throw new ArgumentOutOfRangeException ();
 
-                       return CreateRangeIterator (start, (int) upto);
+                       return CreateRangeIterator (start, count);
                }
 
-               static IEnumerable<int> CreateRangeIterator (int start, int upto)
+               static IEnumerable<int> CreateRangeIterator (int start, int count)
                {
-                       for (int i = start; i <= upto; i++)
-                               yield return i;
+                       for (int i = 0; i < count; i++)
+                               yield return start + i;
                }
 
                #endregion