[Mono-bugs] [Bug 29791][Wis] New - StringCollection enumerator has off-by-one-bug
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
2 Sep 2002 23:48:18 -0000
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 mathpup@mylinuxisp.com.
http://bugzilla.ximian.com/show_bug.cgi?id=29791
--- shadow/29791 Mon Sep 2 19:48:18 2002
+++ shadow/29791.tmp.5062 Mon Sep 2 19:48:18 2002
@@ -0,0 +1,72 @@
+Bug#: 29791
+Product: Mono/Class Libraries
+Version: unspecified
+OS:
+OS Details: SuSE 8.0
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: System
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: mathpup@mylinuxisp.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: StringCollection enumerator has off-by-one-bug
+
+Description of Problem:
+
+The class System.Collections.Specialized.StringCollection has a bug in its
+enumerator. The last item in the collection is missed. The problem is with
+the MoveNext method:
+
+public bool MoveNext() {
+ if (myModCount != data.modCount) {
+ throw new InvalidOperationException();
+ }
+
+ if (++index >= data.count - 1) {
+ return false;
+ }
+ return true;
+}
+
+The expression in the if stmt should be "++index > data.count -1" (change
+>= to >).
+
+
+Steps to reproduce the problem:
+1. Run the program below.
+
+using System.Collections;
+using System.Collections.Specialized;
+
+public class Sample
+{
+ public static void Main()
+ {
+ StringCollection list = new StringCollection();
+ list.Add("A");
+ list.Add("B");
+ foreach (string X in list)
+ Console.WriteLine("{0}", X);
+ }
+}
+
+
+Actual Results:
+
+Prints A on a line.
+
+Expected Results:
+
+Print A on a line. Then prints B on the next line.
+
+
+How often does this happen?
+
+Always
+
+Additional Information: