[PATCH v4 06/10] shell32/autocomplete: Dynamically allocate hwndText so it can handle arbitrary sizes
Huw Davies
huw at codeweavers.com
Tue Sep 11 05:55:45 CDT 2018
On Mon, Sep 10, 2018 at 10:09:36PM +0300, Gabriel Ivăncescu wrote:
> Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
> ---
> dlls/shell32/autocomplete.c | 31 ++++++++++++++++++-------------
> 1 file changed, 18 insertions(+), 13 deletions(-)
>
> diff --git a/dlls/shell32/autocomplete.c b/dlls/shell32/autocomplete.c
> index 6f97665..7421679 100644
> --- a/dlls/shell32/autocomplete.c
> +++ b/dlls/shell32/autocomplete.c
> @@ -134,10 +134,11 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
> {
> IAutoCompleteImpl *This = GetPropW(hwnd, autocomplete_propertyW);
> HRESULT hr;
> - WCHAR hwndText[255];
> + WCHAR *hwndText;
> + UINT len, size, cpt;
> RECT r;
> BOOL displayall = FALSE;
> - int cpt, height, sel;
> + int height, sel;
>
> if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
>
> @@ -154,10 +155,11 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
> }
> return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
> case WM_KEYUP:
> - {
> - int len;
> -
> - GetWindowTextW(hwnd, hwndText, ARRAY_SIZE(hwndText));
> + len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
> + size = len + 1;
> + if (!(hwndText = heap_alloc(size * sizeof(WCHAR))))
> + return 0;
> + len = SendMessageW(hwnd, WM_GETTEXT, size, (LPARAM)hwndText);
>
> switch(wParam) {
> case VK_RETURN:
> @@ -165,7 +167,6 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
> if (This->quickComplete && (GetKeyState(VK_CONTROL) & 0x8000))
> {
> WCHAR *buf;
> - size_t len = strlenW(hwndText);
> size_t sz = strlenW(This->quickComplete) + 1 + len;
> if ((buf = heap_alloc(sz * sizeof(WCHAR))))
> {
> @@ -178,9 +179,11 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
>
> if (This->options & ACO_AUTOSUGGEST)
> ShowWindow(This->hwndListBox, SW_HIDE);
> + heap_free(hwndText);
> return 0;
> case VK_LEFT:
> case VK_RIGHT:
> + heap_free(hwndText);
> return 0;
> case VK_UP:
> case VK_DOWN:
> @@ -196,6 +199,7 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
> /* We must display all the entries */
> displayall = TRUE;
> } else {
> + heap_free(hwndText);
> if (IsWindowVisible(This->hwndListBox)) {
> int count;
>
> @@ -231,21 +235,23 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
> case VK_BACK:
> case VK_DELETE:
> if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
> + heap_free(hwndText);
> ShowWindow(This->hwndListBox, SW_HIDE);
> return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
> }
> break;
> }
>
> + if (len + 1 != size)
> + hwndText = heap_realloc(hwndText, len + 1);
(len + 1) * sizeof(WCHAR)
This is a good example of why we want small patches. It would have
been much harder to spot that in one of your earlier versions.
Huw.
More information about the wine-devel
mailing list