user32: Fix the listbox sorting algorithm.

Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Dmitry Timoshkov 2018-06-28 18:48:46 +08:00 committed by Alexandre Julliard
parent 18420c24c9
commit 5c765431e2
1 changed files with 6 additions and 5 deletions

View File

@ -828,10 +828,11 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact )
{
INT index, min, max, res;
if (!(descr->style & LBS_SORT)) return -1; /* Add it at the end */
if (!descr->nb_items || !(descr->style & LBS_SORT)) return -1; /* Add it at the end */
min = 0;
max = descr->nb_items;
while (min != max)
max = descr->nb_items - 1;
while (min <= max)
{
index = (min + max) / 2;
if (HAS_STRINGS(descr))
@ -854,10 +855,10 @@ static INT LISTBOX_FindStringPos( LB_DESCR *descr, LPCWSTR str, BOOL exact )
res = SendMessageW( descr->owner, WM_COMPAREITEM, id, (LPARAM)&cis );
}
if (!res) return index;
if (res > 0) max = index;
if (res > 0) max = index - 1;
else min = index + 1;
}
return exact ? -1 : max;
return exact ? -1 : min;
}