[PATCH v3 3/4] comctl32/listbox: Use a helper to get the size of an item

Gabriel Ivăncescu gabrielopcode at gmail.com
Wed Feb 27 06:19:16 CST 2019


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/comctl32/listbox.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index f2d0615..46b2304 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -127,6 +127,11 @@ static TIMER_DIRECTION LISTBOX_Timer = LB_TIMER_NONE;
 
 static LRESULT LISTBOX_GetItemRect( const LB_DESCR *descr, INT index, RECT *rect );
 
+static size_t get_item_size( const LB_DESCR *descr )
+{
+    return sizeof(LB_ITEMDATA);
+}
+
 static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
 {
     LB_ITEMDATA *items;
@@ -137,7 +142,7 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
         items_size = (items_size + LB_ARRAY_GRANULARITY - 1) & ~(LB_ARRAY_GRANULARITY - 1);
         if ((descr->style & (LBS_NODATA | LBS_MULTIPLESEL | LBS_EXTENDEDSEL)) != LBS_NODATA)
         {
-            items = heap_realloc(descr->items, items_size * sizeof(LB_ITEMDATA));
+            items = heap_realloc(descr->items, items_size * get_item_size(descr));
             if (!items)
             {
                 SEND_NOTIFICATION(descr, LBN_ERRSPACE);
@@ -151,7 +156,7 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
     if ((descr->style & LBS_NODATA) && descr->items && items_size > descr->nb_items)
     {
         memset(&descr->items[descr->nb_items], 0,
-               (items_size - descr->nb_items) * sizeof(LB_ITEMDATA));
+               (items_size - descr->nb_items) * get_item_size(descr));
     }
     return TRUE;
 }
@@ -202,7 +207,7 @@ static void insert_item_data(LB_DESCR *descr, UINT index, WCHAR *str, ULONG_PTR
 
     item = descr->items + index;
     if (index < descr->nb_items)
-        memmove(item + 1, item, (descr->nb_items - index) * sizeof(LB_ITEMDATA));
+        memmove(item + 1, item, (descr->nb_items - index) * get_item_size(descr));
 
     item->str      = str;
     item->data     = HAS_STRINGS(descr) ? 0 : data;
@@ -218,7 +223,7 @@ static void remove_item_data(LB_DESCR *descr, UINT index)
 
     item = descr->items + index;
     if (index < descr->nb_items)
-        memmove(item, item + 1, (descr->nb_items - index) * sizeof(LB_ITEMDATA));
+        memmove(item, item + 1, (descr->nb_items - index) * get_item_size(descr));
 }
 
 /***********************************************************************
-- 
2.20.1




More information about the wine-devel mailing list