Dmitry Timoshkov : user32: Fix the listbox sorting algorithm.

Alexandre Julliard julliard at winehq.org
Thu Sep 13 03:49:15 CDT 2018


Module: wine
Branch: stable
Commit: fa1d30d84ab10e755979f0146ef0cd5a888ddfc0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fa1d30d84ab10e755979f0146ef0cd5a888ddfc0

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Thu Jun 28 18:48:46 2018 +0800

user32: Fix the listbox sorting algorithm.

Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 5c765431e2cdf5529713f321b70645c9632529dd)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>

---

 dlls/user32/listbox.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/dlls/user32/listbox.c b/dlls/user32/listbox.c
index b2a6a96..bb392cd 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -837,10 +837,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))
@@ -863,10 +864,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;
 }
 
 




More information about the wine-cvs mailing list