[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] [PATCH] Fix ListViewItem.SizeSubItemArray
From: |
Marc Haisenko |
Subject: |
[Pnet-developers] [PATCH] Fix ListViewItem.SizeSubItemArray |
Date: |
Fri, 12 Nov 2004 12:19:05 +0100 |
User-agent: |
KMail/1.7.1 |
Hi folks,
attached is a patch to fix System.Windows.Forms.ListViewItem.SizeSubItemArray
(int, int). It's quite trivial ;-)
The old behaviour was that this method threw an OutOfMemory-Exception. This
was because the abort condition in a loop was the opposite of what the
original author intended:
private void SizeSubItemArray(int size, int index)
{
// Do we need more space?
if (owner.subItems.Length < owner.subItemsCount + size)
{
int newLength = owner.subItems.Length * 2;
int minLength = owner.subItemsCount + size;
for (; newLength < minLength ; newLength *= 2)
{
}
ListViewSubItem[] newSubItems = new ListViewSubItem[newLength];
...
}
...
}
newLength grows until it wraps around and gets negative. This is when the
condition suddenly gets true and then new ListViewSubItem[] is called with a
negative size, which triggered the OutOfMemory exception (wouldn't a
InvalidArgument exception make more sense ? I.e. the array constructor should
test for negative numbers !)
The solution is to just swap newLength and minLength in the condition.
C'ya,
Marc
--
Marc Haisenko
Systemspezialist
Webport IT-Services GmbH
mailto: address@hidden
ListViewItem.cs.patch
Description: Text Data
- [Pnet-developers] [PATCH] Fix ListViewItem.SizeSubItemArray,
Marc Haisenko <=