From 4545f1944e24d0abca16f6308b02cf2dd80c85f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alex=20Villac=C3=ADs=20Lasso?= Date: Thu, 6 Dec 2007 10:47:59 -0500 Subject: [PATCH] riched20: EM_GETTEXTEX with GT_USECRLF should not leave a single CR when running out of space. --- dlls/riched20/editor.c | 5 ++++- dlls/riched20/tests/editor.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index b1444c0f94..5a78fe4eca 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -2804,7 +2804,10 @@ int ME_GetTextW(ME_TextEditor *editor, WCHAR *buffer, int nStart, int nChars, in if (!ME_FindItemFwd(item, diRun)) /* No '\r' is appended to the last paragraph. */ nLen = 0; - else { + else if (bCRLF && nChars == 1) { + nLen = 0; + nChars = 0; + } else { *buffer = '\r'; if (bCRLF) { diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 5fb5975028..6877a101d1 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -1116,6 +1116,33 @@ static void test_EM_SETTEXTEX(void) ok(strcmp((const char *)buf, TestItem2_after) == 0, "WM_GETTEXT did *not* see \\r converted to \\r\\n pairs.\n"); + /* Baseline test for just-enough buffer space for string */ + getText.cb = (lstrlenW(TestItem2) + 1) * sizeof(WCHAR); + getText.codepage = 1200; /* no constant for unicode */ + getText.flags = GT_DEFAULT; + getText.lpDefaultChar = NULL; + getText.lpUsedDefaultChar = NULL; + memset(buf, 0, MAX_BUF_LEN); + SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + ok(lstrcmpW(buf, TestItem2) == 0, + "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n"); + + /* When there is enough space for one character, but not both, of the CRLF + pair at the end of the string, the CR is not copied at all. That is, + the caller must not see CRLF pairs truncated to CR at the end of the + string. + */ + getText.cb = (lstrlenW(TestItem2) + 1) * sizeof(WCHAR); + getText.codepage = 1200; /* no constant for unicode */ + getText.flags = GT_USECRLF; /* <-- asking for CR -> CRLF conversion */ + getText.lpDefaultChar = NULL; + getText.lpUsedDefaultChar = NULL; + memset(buf, 0, MAX_BUF_LEN); + SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf); + ok(lstrcmpW(buf, TestItem1) == 0, + "EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n"); + + /* \r\n pairs get changed into \r */ setText.codepage = 1200; /* no constant for unicode */ getText.codepage = 1200; /* no constant for unicode */ -- 2.32.0.93.g670b81a890