[PATCH v4 08/11] comctl32/listbox: Fix InitStorage heap extension
Gabriel Ivăncescu
gabrielopcode at gmail.com
Wed Nov 21 13:15:11 CST 2018
Only increase the item array if we actually have to. Previously, sending
for example just 1 to nb_items repeatedly would always increase the array
by LB_ARRAY_GRANULARITY, even if there was plenty of space available.
Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
dlls/comctl32/listbox.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
index afa6700..f7ed2b8 100644
--- a/dlls/comctl32/listbox.c
+++ b/dlls/comctl32/listbox.c
@@ -36,6 +36,7 @@
#include "wine/unicode.h"
#include "wine/exception.h"
#include "wine/debug.h"
+#include "wine/heap.h"
#include "comctl32.h"
@@ -675,22 +676,19 @@ static void LISTBOX_DrawFocusRect( LB_DESCR *descr, BOOL on )
/***********************************************************************
* LISTBOX_InitStorage
*/
-static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items )
+static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, UINT nb_items )
{
LB_ITEMDATA *item;
- nb_items += LB_ARRAY_GRANULARITY - 1;
- nb_items -= (nb_items % LB_ARRAY_GRANULARITY);
if (descr->items) {
- nb_items += descr->array_size;
- item = HeapReAlloc( GetProcessHeap(), 0, descr->items,
- nb_items * sizeof(LB_ITEMDATA));
- }
- else {
- item = HeapAlloc( GetProcessHeap(), 0,
- nb_items * sizeof(LB_ITEMDATA));
+ nb_items += descr->nb_items;
+ if (nb_items <= descr->array_size) return LB_OKAY;
}
+ nb_items += LB_ARRAY_GRANULARITY - 1;
+ nb_items -= nb_items % LB_ARRAY_GRANULARITY;
+ item = heap_realloc(descr->items, nb_items * sizeof(*item));
+
if (!item)
{
SEND_NOTIFICATION( descr, LBN_ERRSPACE );
--
2.19.1
More information about the wine-devel
mailing list