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.
This commit is contained in:
Dylan Smith 2008-06-25 11:33:26 -04:00 committed by Alexandre Julliard
parent ba747f4514
commit 6d76d43718
3 changed files with 46 additions and 2 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);
}