[PATCH v4 5/7] comctl32/listbox: Use a helper to retrieve item string by index

Gabriel Ivăncescu gabrielopcode at gmail.com
Tue Feb 12 07:47:01 CST 2019


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---

v4: Dumb mistake with get_item_string, sorry for noise.

I've left FindStringPos alone because I'm not 100% sure if a listbox with
strings is allowed to have a NULL str (which would give a different code
path than currently, if I were to check for NULL from get_item_string
instead). LISTBOX_lstrcmpiW ends up using CompareStringW which does check
for NULL, so I'm not entirely certain about it.

 dlls/comctl32/listbox.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index 34d555a..f99406a 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -132,6 +132,11 @@ static ULONG_PTR get_item_data( const LB_DESCR *descr, UINT index )
     return (descr->style & LBS_NODATA) ? 0 : descr->items[index].data;
 }
 
+static WCHAR *get_item_string( const LB_DESCR *descr, UINT index )
+{
+    return HAS_STRINGS(descr) ? descr->items[index].str : NULL;
+}
+
 static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
 {
     LB_ITEMDATA *items;
@@ -573,7 +578,7 @@ static void LISTBOX_PaintItem( LB_DESCR *descr, HDC hdc, const RECT *rect,
         dis.itemData     = get_item_data(descr, index);
         dis.rcItem       = *rect;
         TRACE("[%p]: drawitem %d (%s) action=%02x state=%02x rect=%s\n",
-              descr->self, index, item ? debugstr_w(item->str) : "", action,
+              descr->self, index, debugstr_w(get_item_string(descr, index)), action,
               dis.itemState, wine_dbgstr_rect(rect) );
         SendMessageW(descr->owner, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
         SelectClipRgn( hdc, hrgn );
@@ -1646,7 +1651,7 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index )
 {
     /* save the item data before it gets freed by LB_RESETCONTENT */
     ULONG_PTR item_data = get_item_data(descr, index);
-    LPWSTR item_str = descr->items[index].str;
+    LPWSTR item_str = get_item_string(descr, index);
 
     if (!descr->nb_items)
         SendMessageW( descr->self, LB_RESETCONTENT, 0, 0 );
@@ -1668,8 +1673,7 @@ static void LISTBOX_DeleteItem( LB_DESCR *descr, INT index )
         dis.itemData = item_data;
         SendMessageW( descr->owner, WM_DELETEITEM, id, (LPARAM)&dis );
     }
-    if (HAS_STRINGS(descr))
-        HeapFree( GetProcessHeap(), 0, item_str );
+    HeapFree( GetProcessHeap(), 0, item_str );
 }
 
 
-- 
2.20.1




More information about the wine-devel mailing list