[PATCH v3 1/2] riched20: Check for NULL in fnTextSrv_TxSetText and add test

Fabian Maurer dark.shadow4 at web.de
Mon Jan 9 11:08:11 CST 2017


Fixes https://bugs.winehq.org/show_bug.cgi?id=12185

v3: Followed suggestion by Nikolay Sivov and extend test

Signed-off-by: Fabian Maurer <dark.shadow4 at web.de>
---
 dlls/riched20/tests/txtsrv.c | 10 ++++++++++
 dlls/riched20/txtsrv.c       |  7 +++----
 2 files changed, 13 insertions(+), 4 deletions(-)

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);
diff --git a/dlls/riched20/txtsrv.c b/dlls/riched20/txtsrv.c
index 3df779834b..307b484352 100644
--- a/dlls/riched20/txtsrv.c
+++ b/dlls/riched20/txtsrv.c
@@ -286,10 +286,9 @@ DECLSPEC_HIDDEN HRESULT WINAPI fnTextSrv_TxSetText(ITextServices *iface, LPCWSTR
    ME_Cursor cursor;
 
    ME_SetCursorToStart(This->editor, &cursor);
-   ME_InternalDeleteText(This->editor, &cursor,
-                         ME_GetTextLength(This->editor), FALSE);
-   ME_InsertTextFromCursor(This->editor, 0, pszText, -1,
-                           This->editor->pBuffer->pDefaultStyle);
+   ME_InternalDeleteText(This->editor, &cursor, ME_GetTextLength(This->editor), FALSE);
+   if(pszText)
+       ME_InsertTextFromCursor(This->editor, 0, pszText, -1, This->editor->pBuffer->pDefaultStyle);
    ME_SetSelection(This->editor, 0, 0);
    This->editor->nModifyStep = 0;
    OleFlushClipboard();
-- 
2.11.0




More information about the wine-patches mailing list