[Mono-bugs] [Bug 409169] New: ImageCollection.CopyTo broken

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jul 15 05:51:03 EDT 2008


           Summary: ImageCollection.CopyTo broken
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: andyhume32 at yahoo.co.uk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

Identified by FxCop.

void ICollection.CopyTo(Array dest, int index)
        for (int imageIndex = 0; imageIndex < this.Count; imageIndex++)
                dest.SetValue (this [index], index++);

Should be
… ...
        dest.SetValue (this [imageIndex], index++);

Renaming imageIndex to srcIndex would make the logic clearer...

using System;
using System.Windows.Forms;
using System.Drawing;

class ImageCollectionCopyToOffsetTest {
    static void Main()
        ImageList imgList = new ImageList ();
        ImageList.ImageCollection coll = imgList.Images;
        Bitmap img1 = new Bitmap (10, 10);
        coll.Add (img1);
        const int dstOffset = 5;
        object[] dst = new object[dstOffset + coll.Count];
        ((System.Collections.IList)coll).CopyTo (dst, dstOffset);
        // Mono 1.9 etc actually crashes on the CopyTo (attempting to read 
        // index five when the collection only contains one item!).
        if (dst [dstOffset] == null) {
            Console.WriteLine ("CopyTo broken");

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list