[PATCH v3 02/10] shell32/autocomplete: Handle heap_alloc failure

Huw Davies huw at codeweavers.com
Mon Sep 10 03:40:09 CDT 2018


On Sat, Sep 08, 2018 at 02:50:48PM +0300, Gabriel Ivăncescu wrote:
> Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
> ---
>  dlls/shell32/autocomplete.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/dlls/shell32/autocomplete.c b/dlls/shell32/autocomplete.c
> index 39df45e..2f9d16f 100644
> --- a/dlls/shell32/autocomplete.c
> +++ b/dlls/shell32/autocomplete.c
> @@ -209,10 +209,10 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
>                              SendMessageW(This->hwndListBox, LB_SETCURSEL, sel, 0);
>                              if (sel != -1) {
>                                  WCHAR *msg;
> -                                int len;
> +                                UINT len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
>  
> -                                len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);

Changing the type of len and making moving the declaration into an
assignment don't belong in this patch.  What you really want here
is a check against LB_ERR, but that again is a different patch.

> -                                msg = heap_alloc((len + 1)*sizeof(WCHAR));
> +                                if (!(msg = heap_alloc((len + 1) * sizeof(WCHAR))))
> +                                    return 0;
>                                  SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
>                                  SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
>                                  SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
> @@ -319,7 +319,8 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
>  {
>      IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
>      WCHAR *msg;
> -    int sel, len;
> +    UINT len;
> +    INT sel;

Same goes for these changes.

>  
>      switch (uMsg) {
>          case WM_MOUSEMOVE:
> @@ -331,7 +332,8 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
>              if (sel < 0)
>                  break;
>              len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
> -            msg = heap_alloc((len + 1)*sizeof(WCHAR));
> +            if (!(msg = heap_alloc((len + 1) * sizeof(WCHAR))))
> +                break;
>              SendMessageW(hwnd, LB_GETTEXT, sel, (LPARAM)msg);
>              SendMessageW(This->hwndEdit, WM_SETTEXT, 0, (LPARAM)msg);
>              SendMessageW(This->hwndEdit, EM_SETSEL, 0, lstrlenW(msg));
> -- 
> 1.9.1
> 
> 
> 



More information about the wine-devel mailing list