shell32/autocomplete: Dynamically allocate hwndText so it can handle arbitrary sizes.

Signed-off-by: Gabriel Ivăncescu <gabrielopcode@gmail.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gabriel Ivăncescu 2018-09-12 22:42:15 +03:00 committed by Alexandre Julliard
parent 5815c7b520
commit cbbbb70cf2

View File

@ -134,10 +134,11 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
{ {
IAutoCompleteImpl *This = GetPropW(hwnd, autocomplete_propertyW); IAutoCompleteImpl *This = GetPropW(hwnd, autocomplete_propertyW);
HRESULT hr; HRESULT hr;
WCHAR hwndText[255]; WCHAR *hwndText;
UINT len, size, cpt;
RECT r; RECT r;
BOOL displayall = FALSE; BOOL displayall = FALSE;
int cpt, height, sel; int height, sel;
if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam); 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); return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
case WM_KEYUP: case WM_KEYUP:
{ len = SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
int len; size = len + 1;
if (!(hwndText = heap_alloc(size * sizeof(WCHAR))))
GetWindowTextW(hwnd, hwndText, ARRAY_SIZE(hwndText)); return 0;
len = SendMessageW(hwnd, WM_GETTEXT, size, (LPARAM)hwndText);
switch(wParam) { switch(wParam) {
case VK_RETURN: case VK_RETURN:
@ -165,7 +167,6 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
if (This->quickComplete && (GetKeyState(VK_CONTROL) & 0x8000)) if (This->quickComplete && (GetKeyState(VK_CONTROL) & 0x8000))
{ {
WCHAR *buf; WCHAR *buf;
size_t len = strlenW(hwndText);
size_t sz = strlenW(This->quickComplete) + 1 + len; size_t sz = strlenW(This->quickComplete) + 1 + len;
if ((buf = heap_alloc(sz * sizeof(WCHAR)))) 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) if (This->options & ACO_AUTOSUGGEST)
ShowWindow(This->hwndListBox, SW_HIDE); ShowWindow(This->hwndListBox, SW_HIDE);
heap_free(hwndText);
return 0; return 0;
case VK_LEFT: case VK_LEFT:
case VK_RIGHT: case VK_RIGHT:
heap_free(hwndText);
return 0; return 0;
case VK_UP: case VK_UP:
case VK_DOWN: case VK_DOWN:
@ -196,6 +199,7 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
/* We must display all the entries */ /* We must display all the entries */
displayall = TRUE; displayall = TRUE;
} else { } else {
heap_free(hwndText);
if (IsWindowVisible(This->hwndListBox)) { if (IsWindowVisible(This->hwndListBox)) {
int count; int count;
@ -231,21 +235,23 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
case VK_BACK: case VK_BACK:
case VK_DELETE: case VK_DELETE:
if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) { if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
heap_free(hwndText);
ShowWindow(This->hwndListBox, SW_HIDE); ShowWindow(This->hwndListBox, SW_HIDE);
return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam); return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
} }
break; break;
} }
if (len + 1 != size)
hwndText = heap_realloc(hwndText, (len + 1) * sizeof(WCHAR));
SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0); SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0);
/* Set txtbackup to point to hwndText itself (which must not be released) */
heap_free(This->txtbackup); heap_free(This->txtbackup);
len = strlenW(hwndText); This->txtbackup = hwndText;
This->txtbackup = heap_alloc((len + 1)*sizeof(WCHAR));
lstrcpyW(This->txtbackup, hwndText);
/* Returns if there is no text to search and we doesn't want to display all the entries */ if (!displayall && !len)
if ((!displayall) && (! *hwndText) )
break; break;
IEnumString_Reset(This->enumstr); IEnumString_Reset(This->enumstr);
@ -297,7 +303,6 @@ static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
} }
break; break;
}
case WM_DESTROY: case WM_DESTROY:
{ {
WNDPROC proc = This->wpOrigEditProc; WNDPROC proc = This->wpOrigEditProc;