remove warning
[mono.git] / mcs / class / corlib / System / Array.cs
index 67f4db84cb4ee436353db1e82f4f0ae71ff5a9d4..84b3a1879023ed11be904c3fa8c7981f44952f92 100644 (file)
@@ -229,8 +229,10 @@ namespace System
 
                        public T Current {
                                get {
-                                       if (idx < 0)
-                                               throw new InvalidOperationException ();
+                                       if (idx == NOT_STARTED)
+                                               throw new InvalidOperationException ("Enumeration has not started. Call MoveNext");
+                                       if (idx == FINISHED)
+                                               throw new InvalidOperationException ("Enumeration already finished");
 
                                        return array.InternalArray__get_Item<T> (array.Length - 1 - idx);
                                }
@@ -238,7 +240,7 @@ namespace System
 
                        void IEnumerator.Reset ()
                        {
-                               throw new NotImplementedException ();
+                               idx = NOT_STARTED;
                        }
 
                        object IEnumerator.Current {
@@ -840,7 +842,9 @@ namespace System
                        int iCmp = 0;
                        try {
                                while (iMin <= iMax) {
-                                       int iMid = (iMin + iMax) / 2;
+                                       // Be careful with overflow
+                                       // http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html
+                                       int iMid = iMin + ((iMax - iMin) / 2);
                                        object elt = array.GetValueImpl (iMid);
 
                                        iCmp = comparer.Compare (elt, value);
@@ -1486,7 +1490,9 @@ namespace System
                        int low = low0;
                        int high = high0;
 
-                       object objPivot = keys.GetValueImpl ((low + high) / 2);
+                       // Be careful with overflows
+                       int mid = low + ((high - low) / 2);
+                       object objPivot = keys.GetValueImpl (mid);
 
                        while (low <= high) {
                                // Move the walls in
@@ -1684,7 +1690,9 @@ namespace System
                        int low = low0;
                        int high = high0;
 
-                       K keyPivot = keys [(low + high) / 2];
+                       // Be careful with overflows
+                       int mid = low + ((high - low) / 2);
+                       K keyPivot = keys [mid];
 
                        while (low <= high) {
                                // Move the walls in
@@ -1733,7 +1741,9 @@ namespace System
                        int low = low0;
                        int high = high0;
 
-                       T keyPivot = array [(low + high) / 2];
+                       // Be careful with overflows
+                       int mid = low + ((high - low) / 2);
+                       T keyPivot = array [mid];
 
                        while (low <= high) {
                                // Move the walls in
@@ -2050,7 +2060,8 @@ namespace System
                        int iCmp = 0;
                        try {
                                while (iMin <= iMax) {
-                                       int iMid = (iMin + iMax) / 2;
+                                       // Be careful with overflows
+                                       int iMid = iMin + ((iMax - iMin) / 2);
                                        iCmp = comparer.Compare (value, array [iMid]);
 
                                        if (iCmp == 0)