Module: wine Branch: refs/heads/master Commit: ea755999f1c768644f507067107e471d3385ac76 URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=ea755999f1c768644f507067...
Author: Clinton Stimpson clinton@elemtech.com Date: Tue Aug 8 21:12:33 2006 -0600
riched20: Fix crash with NULL lParam in EM_SETTEXTEX.
---
dlls/riched20/editor.c | 4 +- dlls/riched20/tests/editor.c | 75 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index 77bb7a0..28f371a 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -1622,7 +1622,7 @@ LRESULT WINAPI RichEditANSIWndProc(HWND { LPWSTR wszText = (LPWSTR)lParam; SETTEXTEX *pStruct = (SETTEXTEX *)wParam; - size_t len = lstrlenW(wszText); + size_t len = wszText ? lstrlenW(wszText) : 0; int from, to; ME_Style *style; TRACE("EM_SETTEXEX - %s, flags %d, cp %d\n", debugstr_w(wszText), (int)pStruct->flags, pStruct->codepage); @@ -1640,7 +1640,7 @@ LRESULT WINAPI RichEditANSIWndProc(HWND } else { ME_InternalDeleteText(editor, 0, ME_GetTextLength(editor)); - ME_InsertTextFromCursor(editor, 0, wszText, -1, editor->pBuffer->pDefaultStyle); + ME_InsertTextFromCursor(editor, 0, wszText, len, editor->pBuffer->pDefaultStyle); len = 1; } ME_CommitUndo(editor); diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 6153e6e..5c1f7c1 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -898,6 +898,80 @@ static void test_ES_PASSWORD() "EM_GETPASSWORDCHAR returned %c (%d) when set to 'x', instead of x (120)\n",result,result); }
+static void test_EM_SETTEXTEX() +{ + HWND hwndRichEdit = new_richedit(NULL); + SETTEXTEX setText; + GETTEXTEX getText; + WCHAR TestItem1[] = {'T', 'e', 's', 't', + 'S', 'o', 'm', 'e', + 'T', 'e', 'x', 't', 0}; +#define MAX_BUF_LEN 1024 + WCHAR buf[MAX_BUF_LEN]; + int result; + CHARRANGE cr; + + setText.codepage = 1200; /* no constant for unicode */ + getText.codepage = 1200; /* no constant for unicode */ + getText.cb = MAX_BUF_LEN; + getText.flags = GT_DEFAULT; + + setText.flags = 0; + SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1); + SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + ok(lstrcmpW(buf, TestItem1) == 0, + "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n"); + + result = SendMessage(hwndRichEdit, EM_SETTEXTEX, + (WPARAM)&setText, (LPARAM) NULL); + SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + + ok (result == 1, + "EM_SETTEXTEX returned %d, instead of 1\n",result); + ok(lstrlenW(buf) == 0, + "EM_SETTEXTEX with NULL lParam should clear rich edit.\n"); + + /* put some text back */ + setText.flags = 0; + SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1); + /* select some text */ + cr.cpMax = 1; + cr.cpMin = 3; + SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr); + /* replace current selection */ + setText.flags = ST_SELECTION; + result = SendMessage(hwndRichEdit, EM_SETTEXTEX, + (WPARAM)&setText, (LPARAM) NULL); + ok(result == 0, + "EM_SETTEXTEX with NULL lParam to replace selection" + " with no text should return 0. Got %i\n", + result); + + /* put some text back */ + setText.flags = 0; + SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1); + /* select some text */ + cr.cpMax = 1; + cr.cpMin = 3; + SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr); + /* replace current selection */ + setText.flags = ST_SELECTION; + result = SendMessage(hwndRichEdit, EM_SETTEXTEX, + (WPARAM)&setText, (LPARAM) TestItem1); + /* get text */ + SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + ok(result == lstrlenW(TestItem1), + "EM_SETTEXTEX with NULL lParam to replace selection" + " with no text should return 0. Got %i\n", + result); + ok(lstrlenW(buf) == 22, + "EM_SETTEXTEX to replace selection with more text failed: %i.\n", + lstrlenW(buf) ); + + DestroyWindow(hwndRichEdit); +} + + START_TEST( editor ) { MSG msg; @@ -918,6 +992,7 @@ START_TEST( editor ) test_EM_AUTOURLDETECT(); test_EM_SETUNDOLIMIT(); test_ES_PASSWORD(); + test_EM_SETTEXTEX();
/* Set the environment variable WINETEST_RICHED20 to keep windows * responsive and open for 30 seconds. This is useful for debugging.