[Mono-bugs] [Bug 82469][Nor] New - System.Array.BinarySearch is broken for large values

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Aug 17 11:24:48 EDT 2007


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by andriy.tkach at stu-electronics.com.

http://bugzilla.ximian.com/show_bug.cgi?id=82469

--- shadow/82469	2007-08-17 11:24:48.000000000 -0400
+++ shadow/82469.tmp.23635	2007-08-17 11:24:48.000000000 -0400
@@ -0,0 +1,49 @@
+Bug#: 82469
+Product: Mono: Class Libraries
+Version: unspecified
+OS: other
+OS Details: suse 10.1
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: andriy.tkach at stu-electronics.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.Array.BinarySearch is broken for large values
+
+Description of Problem:
+System.Array.BinarySearch throws System.InvalidOperationException if the
+array is large.  This is caused by overflow in the calculation:
+
+	mid = (bot + top) / 2
+
+
+Steps to reproduce the problem:
+1. Execute this code:
+	1:		int ind = 0;
+        2:              byte[] array = new byte[1100000000];
+	3:		array[array.Length - 1] = 1;
+	4:		ind = System.Array.BinarySearch(array,1);
+	5:		if (ind!=0)
+	6:			Console.WriteLine("found " + ind);
+	7:		else Console.WriteLine("not found");
+
+Actual Results:
+System.InvalidOperationException while executing line 4
+
+Expected Results:
+Successful execution of line:
+  6: Console.WriteLine("found " + ind);
+
+How often does this happen? 
+Every time
+
+Additional Information:
+one of the ways to fix it substitute line with division:
+
+      mid = bot + ((top - bot) / 2);


More information about the mono-bugs mailing list