Commit 99f0dc4f authored by Alex Villacís Lasso's avatar Alex Villacís Lasso Committed by Alexandre Julliard

riched20: WM_GETTEXT should return 0 on overflow but fill buffer anyway.

parent 4545f194
......@@ -2002,13 +2002,34 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
case WM_GETTEXT:
{
GETTEXTEX ex;
LRESULT rc;
LPSTR bufferA = NULL;
LPWSTR bufferW = NULL;
ex.cb = wParam;
if (unicode)
bufferW = richedit_alloc((wParam + 2) * sizeof(WCHAR));
else bufferA = richedit_alloc(wParam + 2);
ex.cb = wParam + (unicode ? 2*sizeof(WCHAR) : 2);
ex.flags = GT_USECRLF;
ex.codepage = unicode ? 1200 : CP_ACP;
ex.lpDefaultChar = NULL;
ex.lpUsedDefaultChar = NULL;
return RichEditWndProc_common(hWnd, EM_GETTEXTEX, (WPARAM)&ex, lParam, unicode);
rc = RichEditWndProc_common(hWnd, EM_GETTEXTEX, (WPARAM)&ex, unicode ? (LPARAM)bufferW : (LPARAM)bufferA, unicode);
if (unicode)
{
memcpy((LPWSTR)lParam, bufferW, wParam);
if (lstrlenW(bufferW) >= wParam / sizeof(WCHAR)) rc = 0;
}
else
{
memcpy((LPSTR)lParam, bufferA, wParam);
if (strlen(bufferA) >= wParam) rc = 0;
}
if (bufferA != NULL) richedit_free(bufferA);
if (bufferW != NULL) richedit_free(bufferW);
return rc;
}
case EM_GETTEXTEX:
{
......
......@@ -656,14 +656,48 @@ static void test_WM_GETTEXT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
static const char text[] = "Hello. My name is RichEdit!";
static const char text2[] = "Hello. My name is RichEdit!\r";
static const char text2_after[] = "Hello. My name is RichEdit!\r\n";
char buffer[1024] = {0};
int result;
/* Baseline test with normal-sized buffer */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(result == strlen(buffer),
"WM_GETTEXT returned %d, expected %d\n", result, strlen(buffer));
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,text);
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
/* Test for behavior in overflow case */
memset(buffer, 0, 1024);
result = SendMessage(hwndRichEdit, WM_GETTEXT, strlen(text), (LPARAM)buffer);
ok(result == 0,
"WM_GETTEXT returned %d, expected 0\n", result);
result = strcmp(buffer,text);
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
/* Baseline test with normal-sized buffer and carriage return */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text2);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(result == strlen(buffer),
"WM_GETTEXT returned %d, expected %d\n", result, strlen(buffer));
result = strcmp(buffer,text2_after);
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
/* Test for behavior of CRLF conversion in case of overflow */
memset(buffer, 0, 1024);
result = SendMessage(hwndRichEdit, WM_GETTEXT, strlen(text2), (LPARAM)buffer);
ok(result == 0,
"WM_GETTEXT returned %d, expected 0\n", result);
result = strcmp(buffer,text2);
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
DestroyWindow(hwndRichEdit);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment