Listbox delete string handling should validate the range of the

index. Added some tests.
This commit is contained in:
Jason Edmeades 2005-08-27 09:24:14 +00:00 committed by Alexandre Julliard
parent 52a63149dc
commit 34db84e1da
2 changed files with 13 additions and 3 deletions

View File

@ -1662,8 +1662,7 @@ static LRESULT LISTBOX_RemoveItem( LB_DESCR *descr, INT index )
LB_ITEMDATA *item;
INT max_items;
if ((index == -1) && (descr->nb_items > 0)) index = descr->nb_items - 1;
else if ((index < 0) || (index >= descr->nb_items)) return LB_ERR;
if ((index < 0) || (index >= descr->nb_items)) return LB_ERR;
/* We need to invalidate the original rect instead of the updated one. */
LISTBOX_InvalidateItems( descr, index );
@ -1760,7 +1759,7 @@ static LRESULT LISTBOX_SetCount( LB_DESCR *descr, INT count )
else if (count < descr->nb_items)
{
while (count < descr->nb_items)
if ((ret = LISTBOX_RemoveItem( descr, -1 )) < 0)
if ((ret = LISTBOX_RemoveItem( descr, (descr->nb_items - 1) )) < 0)
return ret;
}
return LB_OKAY;

View File

@ -139,6 +139,7 @@ check (const struct listbox_test test)
HWND hLB=create_listbox (test.prop.add_style, 0);
RECT second_item;
int i;
int res;
listbox_query (hLB, &answer);
listbox_ok (test, init, answer);
@ -179,6 +180,16 @@ check (const struct listbox_test test)
HeapFree (GetProcessHeap(), 0, txt);
}
/* Confirm the count of items, and that an invalid delete does not remove anything */
res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
ok((res==4), "Expected 4 items, got %d\n", res);
res = SendMessage (hLB, LB_DELETESTRING, -1, 0);
ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
res = SendMessage (hLB, LB_DELETESTRING, 4, 0);
ok((res==LB_ERR), "Expected LB_ERR items, got %d\n", res);
res = SendMessage (hLB, LB_GETCOUNT, 0, 0);
ok((res==4), "Expected 4 items, got %d\n", res);
WAIT;
DestroyWindow (hLB);
}