From: Fabian Maurer Subject: [PATCH v2] riched20: Check for NULL in ME_InsertTextFromCursor and add test Message-Id: <20170105160642.31411-1-dark.shadow4@web.de> Date: Thu, 5 Jan 2017 17:06:42 +0100 It already works with a null-pointer, but will crash if len is -1. Since null-pointer means no text, we just return to avoid crashes. v2: Followed suggestion by Nikolay Sivov, moved check and extend test Fixes https://bugs.winehq.org/show_bug.cgi?id=12185 Signed-off-by: Fabian Maurer --- dlls/riched20/caret.c | 3 +++ dlls/riched20/tests/txtsrv.c | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/dlls/riched20/caret.c b/dlls/riched20/caret.c index 26af743518..a4651fa87b 100644 --- a/dlls/riched20/caret.c +++ b/dlls/riched20/caret.c @@ -516,6 +516,9 @@ void ME_InsertTextFromCursor(ME_TextEditor *editor, int nCursor, if (ME_IsSelection(editor)) ME_DeleteSelection(editor); + if(!str) + return; + /* FIXME: is this too slow? */ /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */ oldLen = ME_GetTextLength(editor); diff --git a/dlls/riched20/tests/txtsrv.c b/dlls/riched20/tests/txtsrv.c index 1a6ca61052..4be3106514 100644 --- a/dlls/riched20/tests/txtsrv.c +++ b/dlls/riched20/tests/txtsrv.c @@ -681,6 +681,16 @@ static void test_TxSetText(void) ok(memcmp(rettext,settext,SysStringByteLen(rettext)) == 0, "String returned differs\n"); + /* Null-pointer should behave the same as empty-string */ + + hres = ITextServices_TxSetText(txtserv, 0); + ok(hres == S_OK, "ITextServices_TxSetText failed (result = %x)\n", hres); + + hres = ITextServices_TxGetText(txtserv, &rettext); + ok(hres == S_OK, "ITextServices_TxGetText failed (result = %x)\n", hres); + ok(SysStringLen(rettext) == 0, + "String returned of wrong length (expected 0, got %d)\n", SysStringLen(rettext)); + SysFreeString(rettext); ITextServices_Release(txtserv); ITextHost_Release(host); -- 2.11.0