Module: wine Branch: master Commit: 99f0dc4ff4e875a376967a15488973a03d5a060d URL: http://source.winehq.org/git/wine.git/?a=commit;h=99f0dc4ff4e875a376967a1548...
Author: Alex Villacís Lasso a_villacis@palosanto.com Date: Thu Dec 6 10:50:48 2007 -0500
riched20: WM_GETTEXT should return 0 on overflow but fill buffer anyway.
---
dlls/riched20/editor.c | 25 +++++++++++++++++++++++-- dlls/riched20/tests/editor.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 5a78fe4..1ffb1ea 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -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: { diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 6877a10..83fe42d 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -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); }