mail-archives/mono-bugs/2006-February/039072.html

181 строка
6.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> [Mono-bugs] [Bug 77504][Maj] New - System.Array:BinarySearch does
not return the correct value
</TITLE>
<LINK REL="Index" HREF="index.html" >
<LINK REL="made" HREF="mailto:mono-bugs%40lists.ximian.com?Subject=%5BMono-bugs%5D%20%5BBug%2077504%5D%5BMaj%5D%20New%20-%20System.Array%3ABinarySearch%20does%0A%09not%20return%20the%20correct%20value&In-Reply-To=bug-77504%40chernobyl.ximian.com">
<META NAME="robots" CONTENT="index,nofollow">
<META http-equiv="Content-Type" content="text/html; charset=us-ascii">
<LINK REL="Previous" HREF="039071.html">
<LINK REL="Next" HREF="039073.html">
</HEAD>
<BODY BGCOLOR="#ffffff">
<H1>[Mono-bugs] [Bug 77504][Maj] New - System.Array:BinarySearch does
not return the correct value</H1>
<B>bugzilla-daemon at bugzilla.ximian.com</B>
<A HREF="mailto:mono-bugs%40lists.ximian.com?Subject=%5BMono-bugs%5D%20%5BBug%2077504%5D%5BMaj%5D%20New%20-%20System.Array%3ABinarySearch%20does%0A%09not%20return%20the%20correct%20value&In-Reply-To=bug-77504%40chernobyl.ximian.com"
TITLE="[Mono-bugs] [Bug 77504][Maj] New - System.Array:BinarySearch does
not return the correct value">bugzilla-daemon at bugzilla.ximian.com
</A><BR>
<I>Wed Feb 8 11:57:34 EST 2006</I>
<P><UL>
<LI>Previous message: <A HREF="039071.html">[Mono-bugs] [Bug 77503][Cri] New - compiling file in ISO-8859-15
encoding with degree symbol character constant fails
</A></li>
<LI>Next message: <A HREF="039073.html">[Mono-bugs] [Bug 77503][Cri] Changed - compiling file in
ISO-8859-15 encoding with degree symbol character constant fails
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#39072">[ date ]</a>
<a href="thread.html#39072">[ thread ]</a>
<a href="subject.html#39072">[ subject ]</a>
<a href="author.html#39072">[ author ]</a>
</LI>
</UL>
<HR>
<!--beginarticle-->
<PRE>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 <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">julien.degroote at tremplin-utc.net.</A>
<A HREF="http://bugzilla.ximian.com/show_bug.cgi?id=77504">http://bugzilla.ximian.com/show_bug.cgi?id=77504</A>
--- shadow/77504 2006-02-08 11:57:34.000000000 -0500
+++ shadow/77504.tmp.14477 2006-02-08 11:57:34.000000000 -0500
@@ -0,0 +1,107 @@
+Bug#: 77504
+Product: Mono: Class Libraries
+Version: 1.1
+OS: GNU/Linux [Other]
+OS Details: Linux mordor 2.6.8.1-epia1 #2 Tue Mar 29 23:40:09 CEST 2005 i686 VIA Nehemiah CentaurHauls GNU/Linux
+Status: NEW
+Resolution:
+Severity: Unknown
+Priority: Major
+Component: CORLIB
+AssignedTo: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">mono-bugs at ximian.com</A>
+ReportedBy: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">julien.degroote at tremplin-utc.net</A>
+QAContact: <A HREF="http://lists.ximian.com/mailman/listinfo/mono-bugs">mono-bugs at ximian.com</A>
+TargetMilestone: ---
+URL:
+Cc:
+Summary: System.Array:BinarySearch does not return the correct value
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+I noticed that the return value of
+System.Collections.Generic.List:BinarySearch(T item, IComparer&lt;T&gt; comparer)
+ is invalid when item is not in the List.
+
+
+Steps to reproduce the problem:
+1. Use the given file compile and run :
+==========================================================
+using System;
+using System.Collections.Generic;
+
+namespace Test {
+ class Node {
+ public Node(int x) {
+ cx = x;
+ }
+ public int cx;
+ }
+
+ class MyComparer : IComparer&lt;Node&gt; {
+ public int Compare(Node a, Node b) {
+ string sa = (a == null ? &quot;null&quot; : &quot;cx:&quot;+a.cx.ToString());
+ string sb = (b == null ? &quot;null&quot; : &quot;cx:&quot;+b.cx.ToString());
+ Console.WriteLine(&quot;Comparing {0} and {1}&quot;,sa,sb);
+ if (a == null) {
+ if (b == null) {
+ return 0;
+ } else {
+ return -1;
+ }
+ }
+ if (b == null) {
+ return 1;
+ }
+ if (a.cx &lt; b.cx) {
+ return -1;
+ } else if (a.cx &gt; b.cx) {
+ return 1;
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ class Start {
+ public static void Main() {
+ IComparer&lt;Node&gt; comp = new MyComparer();
+ List&lt;Node&gt; ss = new List&lt;Node&gt;();
+ Node n = new Node(50);
+ int ind1 = ss.BinarySearch(n,comp);
+ ss.Insert(~ind1,n);
+
+ n = new Node(51);
+ ind1 = ss.BinarySearch(n,comp);
+ ss.Insert(~ind1,n);
+ }
+ }
+}
+
+==========================================================
+
+
+Actual Results:
+You will notice that the second Insert produces an exception here it looks
+like this :
+==========================================================
+Unhandled Exception: System.ArgumentOutOfRangeException: Argument is out of
+range.
+Parameter name: index
+in &lt;0x00088&gt; System.Collections.Generic.List`1[Test.Node]:Insert (Int32 ,
+Test.Node )
+
+Expected Results:
+Program runs and returns with no problem. Both Node objects added to the
+List ss.
+
+How often does this happen?
+Always
+
+Additional Information:
+The cause of the exception is that BinarySearch returns -5 (the binary
+complement of 4) but it should return -2 (binary complement of 1).
+I tracked down the bug to System.Array:BinarySearch that apparently uses
+the capacity of the internal array instead of the actual number of items to
+do its search.
</PRE>
<!--endarticle-->
<HR>
<P><UL>
<!--threads-->
<LI>Previous message: <A HREF="039071.html">[Mono-bugs] [Bug 77503][Cri] New - compiling file in ISO-8859-15
encoding with degree symbol character constant fails
</A></li>
<LI>Next message: <A HREF="039073.html">[Mono-bugs] [Bug 77503][Cri] Changed - compiling file in
ISO-8859-15 encoding with degree symbol character constant fails
</A></li>
<LI> <B>Messages sorted by:</B>
<a href="date.html#39072">[ date ]</a>
<a href="thread.html#39072">[ thread ]</a>
<a href="subject.html#39072">[ subject ]</a>
<a href="author.html#39072">[ author ]</a>
</LI>
</UL>
<hr>
<a href="http://lists.ximian.com/mailman/listinfo/mono-bugs">More information about the mono-bugs
mailing list</a><br>
</body></html>