[Mono-bugs] [Bug 61458][Nor] New - Binary search returns wrong result with DefaultInvariant comparer

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Mon, 12 Jul 2004 20:25:00 -0400 (EDT)


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 michi@zeroc.com.

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

--- shadow/61458	2004-07-12 20:25:00.000000000 -0400
+++ shadow/61458.tmp.31374	2004-07-12 20:25:00.000000000 -0400
@@ -0,0 +1,81 @@
+Bug#: 61458
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: michi@zeroc.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Binary search returns wrong result with DefaultInvariant comparer
+
+Compile and run the following code. It produces incorrect output when run 
+with Mono 1.0 under both Linux and Windows:
+
+public class Program
+{
+    private static string[] __all =
+    {
+        "ice_id",
+        "ice_ids",
+        "ice_isA",
+        "ice_ping",
+        "opBool",
+        "opBoolS",
+        "opBoolSS",
+        "opByte",
+        "opByteBoolD",
+        "opByteS",
+        "opByteSS",
+        "opContext",
+        "opDerived",
+        "opFloatDouble",
+        "opFloatDoubleS",
+        "opFloatDoubleSS",
+        "opIntS",
+        "opLongFloatD",
+        "opMyClass",
+        "opMyEnum",
+        "opShortIntD",
+        "opShortIntLong",
+        "opShortIntLongS",
+        "opShortIntLongSS",
+        "opString",
+        "opStringMyEnumD",
+        "opStringS",
+        "opStringSS",
+        "opStringSSS",
+        "opStringStringD",
+        "opStruct",
+        "opVoid",
+        "shutdown"
+    };
+
+    static void Main(string[] args)
+    {
+        int pos = System.Array.BinarySearch(__all, "opStringStringD", 
+System.Collections.Comparer.DefaultInvariant);
+        System.Console.WriteLine(pos);
+    }
+}
+
+The output is "-28", but should be "29" (which is what is produced by 
+Visual C#).
+
+If you change the BinarySearch line to read
+
+        int pos = System.Array.BinarySearch(__all, "opStringStringD");
+
+the correct result is returned, so it appears the DefaultInvariant 
+comparer does not return the correct result for some comparisons.
+
+Cheers,
+
+Michi.