[PATCH 5/5] comctl32/listbox: Shrink the item array with resize_storage

Huw Davies huw at codeweavers.com
Thu Feb 7 03:54:08 CST 2019


On Thu, Jan 31, 2019 at 05:23:23PM +0200, Gabriel Ivăncescu wrote:
> Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
> ---
>  dlls/comctl32/listbox.c | 22 ++++++----------------
>  1 file changed, 6 insertions(+), 16 deletions(-)
> 
> diff --git a/dlls/comctl32/listbox.c b/dlls/comctl32/listbox.c
> index f1ecc52..4ff98d4 100644
> --- a/dlls/comctl32/listbox.c
> +++ b/dlls/comctl32/listbox.c
> @@ -131,7 +131,8 @@ static BOOL resize_storage(LB_DESCR *descr, UINT items_size)
>  {
>      LB_ITEMDATA *items;
>  
> -    if (items_size > descr->items_size)
> +    if (items_size > descr->items_size ||
> +        items_size + LB_ARRAY_GRANULARITY * 2 < descr->items_size)
>      {
>          items_size = (items_size + LB_ARRAY_GRANULARITY - 1) & ~(LB_ARRAY_GRANULARITY - 1);
>          items = heap_realloc(descr->items, items_size * sizeof(LB_ITEMDATA));
> @@ -704,7 +705,9 @@ static void LISTBOX_DrawFocusRect( LB_DESCR *descr, BOOL on )
>   */
>  static LRESULT LISTBOX_InitStorage( LB_DESCR *descr, INT nb_items )
>  {
> -    if (!resize_storage(descr, descr->nb_items + nb_items))
> +    UINT new_size = descr->nb_items + nb_items;
> +
> +    if (new_size > descr->items_size && !resize_storage(descr, new_size))
>          return LB_ERRSPACE;
>      return descr->items_size;

To avoid patching something you changed in [2/5] you could move this hunk to [2/5].



More information about the wine-devel mailing list