[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    [PATCH 5/6] user32: Fix the listbox sorting algorithm.
From:       Dmitry Timoshkov <dmitry () baikal ! ru>
Date:       2018-06-28 10:48:46
Message-ID: 20180628184846.40a938186ad449fd1dbe2b43 () baikal ! ru
[Download RAW message or body]

Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru>
---
 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 490033902c..9caccf6097 100644
--- a/dlls/user32/listbox.c
+++ b/dlls/user32/listbox.c
@@ -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;
 }
 
 
-- 
2.16.3




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic