Dmitry Timoshkov : comctl32/listbox: Fix the listbox sorting algorithm.

Alexandre Julliard julliard at winehq.org
Thu Jul 5 15:25:54 CDT 2018


Module: wine
Branch: master
Commit: 02c36b52b0071482d369deacb3a617a7f01e8a85
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=02c36b52b0071482d369deacb3a617a7f01e8a85

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Thu Jul  5 08:14:34 2018 +0300

comctl32/listbox: Fix the listbox sorting algorithm.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=42602
Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/comctl32/listbox.c       | 11 ++++++-----
 dlls/comctl32/tests/listbox.c |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index a1fdf83..e033975 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -791,10 +791,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))
@@ -817,10 +818,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;
 }
 
 
diff --git a/dlls/comctl32/tests/listbox.c b/dlls/comctl32/tests/listbox.c
index 69d3381..9af675b 100644
--- a/dlls/comctl32/tests/listbox.c
+++ b/dlls/comctl32/tests/listbox.c
@@ -2032,7 +2032,7 @@ static void test_WM_MEASUREITEM(void)
     ret = SendMessageA(listbox, LB_ADDSTRING, 0, (LPARAM)"item 2");
     ok(ret == 2, "expected 2, got %ld\n", ret);
 
-    ok_sequence(sequences, PARENT_SEQ_INDEX, lb_addstring_sort_parent_seq, "LB_ADDSTRING (LBS_SORT)", TRUE);
+    ok_sequence(sequences, PARENT_SEQ_INDEX, lb_addstring_sort_parent_seq, "LB_ADDSTRING (LBS_SORT)", FALSE);
     DestroyWindow(listbox);
 
     /* LBS_HASSTRINGS */




More information about the wine-cvs mailing list