Dylan Smith : richedit: Fixed a bug preventing NULL pointers from being in text.

Alexandre Julliard julliard at winehq.org
Thu Jun 26 14:50:48 CDT 2008


Module: wine
Branch: master
Commit: 6d76d4371829143acede26018913af952f8976b2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=6d76d4371829143acede26018913af952f8976b2

Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date:   Wed Jun 25 11:33:26 2008 -0400

richedit: Fixed a bug preventing NULL pointers from being in text.

Opening a text file with a NULL terminated character in it was causing
an assertion error after a run was being split due to word wrap.
Windows allows NULL terminated characters to be in the text.

---

 dlls/riched20/editor.c       |    2 +-
 dlls/riched20/string.c       |    2 +-
 dlls/riched20/tests/editor.c |   44 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index e71c384..7fab00c 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -2618,7 +2618,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
       buffer = heap_alloc((crlfmul*nCount + 1) * sizeof(WCHAR));
 
       buflen = ME_GetTextW(editor, buffer, nStart, nCount, ex->flags & GT_USECRLF);
-      rc = WideCharToMultiByte(ex->codepage, flags, buffer, -1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
+      rc = WideCharToMultiByte(ex->codepage, flags, buffer, buflen+1, (LPSTR)lParam, ex->cb, ex->lpDefaultChar, ex->lpUsedDefChar);
       if (rc) rc--; /* do not count 0 terminator */
 
       heap_free(buffer);
diff --git a/dlls/riched20/string.c b/dlls/riched20/string.c
index 84efdbe..97b5a67 100644
--- a/dlls/riched20/string.c
+++ b/dlls/riched20/string.c
@@ -128,7 +128,7 @@ ME_String *ME_VSplitString(ME_String *orig, int charidx)
   assert(charidx>=0);
   assert(charidx<=orig->nLen);
 
-  s = ME_MakeString(orig->szData+charidx);
+  s = ME_MakeStringN(orig->szData+charidx, orig->nLen-charidx);
   orig->nLen = charidx;
   orig->szData[charidx] = '\0';
   return s;
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 50b69b8..409c600 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -3616,6 +3616,30 @@ static DWORD CALLBACK test_EM_STREAMIN_esCallback(DWORD_PTR dwCookie,
   return 0;
 }
 
+struct StringWithLength {
+    int length;
+    char *buffer;
+};
+
+/* This callback is used to handled the null characters in a string. */
+static DWORD CALLBACK test_EM_STREAMIN_esCallback2(DWORD_PTR dwCookie,
+                                                   LPBYTE pbBuff,
+                                                   LONG cb,
+                                                   LONG *pcb)
+{
+    struct StringWithLength* str = (struct StringWithLength*)dwCookie;
+    int size = str->length;
+    *pcb = cb;
+    if (*pcb > size) {
+      *pcb = size;
+    }
+    if (*pcb > 0) {
+      memcpy(pbBuff, str->buffer, *pcb);
+      str->buffer += *pcb;
+      str->length -= *pcb;
+    }
+    return 0;
+}
 
 static void test_EM_STREAMIN(void)
 {
@@ -3645,6 +3669,15 @@ static void test_EM_STREAMIN(void)
 
   const char * streamText3 = "RichEdit1";
 
+  struct StringWithLength cookieForStream4;
+  const char * streamText4 =
+      "This text just needs to be long enough to cause run to be split onto "\
+      "two seperate lines and make sure the null terminating character is "\
+      "handled properly.\0";
+  int length4 = strlen(streamText4) + 1;
+  cookieForStream4.buffer = (char *)streamText4;
+  cookieForStream4.length = length4;
+
   /* Minimal test without \par at the end */
   es.dwCookie = (DWORD_PTR)&streamText0;
   es.dwError = 0;
@@ -3728,6 +3761,17 @@ static void test_EM_STREAMIN(void)
       "EM_STREAMIN: Test 3 set wrong text: Result: %s\n",buffer);
   ok(es.dwError == -16, "EM_STREAMIN: Test 3 set error %d, expected %d\n", es.dwError, -16);
 
+  es.dwCookie = (DWORD_PTR)&cookieForStream4;
+  es.dwError = 0;
+  es.pfnCallback = test_EM_STREAMIN_esCallback2;
+  SendMessage(hwndRichEdit, EM_STREAMIN,
+              (WPARAM)(SF_TEXT), (LPARAM)&es);
+
+  result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
+  ok (result  == length4,
+      "EM_STREAMIN: Test 4 returned %ld, expected %d\n", result, length4);
+  ok(es.dwError == 0, "EM_STREAMIN: Test 4 set error %d, expected %d\n", es.dwError, 0);
+
   DestroyWindow(hwndRichEdit);
 }
 




More information about the wine-cvs mailing list