Module: wine
Branch: master
Commit: 4545f1944e24d0abca16f6308b02cf2dd80c85f9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4545f1944e24d0abca16f6308…
Author: Alex Villacís Lasso <a_villacis(a)palosanto.com>
Date: Thu Dec 6 10:47:59 2007 -0500
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 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index b1444c0..5a78fe4 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 5fb5975..6877a10 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 */