Prevent potential integer overflows in SortedList's binary search midpoint calculation
authorJeffrey Stedfast <jeff@xamarin.com>
Fri, 12 Jul 2013 18:05:55 +0000 (14:05 -0400)
committerJeffrey Stedfast <jeff@xamarin.com>
Fri, 12 Jul 2013 18:05:55 +0000 (14:05 -0400)
mcs/class/System/System.Collections.Generic/SortedList.cs

index c1190b2ad26d67daeeecc6c79191814e56db3879..2eaec862bda11b699875eb110f37849fb71b1134 100644 (file)
@@ -629,7 +629,7 @@ namespace System.Collections.Generic
                        int right = len-1;
 
                        while (left <= right) {
-                               int guess = (left + right) >> 1;
+                               int guess = left + ((right - left) >> 1);
 
                                int cmp = Compare (table[guess].Key, key);
                                if (cmp == 0) return guess;