From 09802e2c764847ecccd2c82d891d887b97982baf Mon Sep 17 00:00:00 2001 From: Dylan Smith Date: Tue, 28 Oct 2008 18:16:23 -0400 Subject: [PATCH] richedit: Handle negative position given to EM_POSFROMCHAR. --- dlls/riched20/editor.c | 1 + dlls/riched20/tests/editor.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c index e35e3cb155..ce754b9f2b 100644 --- a/dlls/riched20/editor.c +++ b/dlls/riched20/editor.c @@ -3544,6 +3544,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam, nCharOfs = lParam; nLength = ME_GetTextLength(editor); nCharOfs = min(nCharOfs, nLength); + nCharOfs = max(nCharOfs, 0); ME_RunOfsFromCharOfs(editor, nCharOfs, &pRun, &nOffset); assert(pRun->type == diRun); diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c index 2c803aee6e..7748d9243d 100644 --- a/dlls/riched20/tests/editor.c +++ b/dlls/riched20/tests/editor.c @@ -649,6 +649,10 @@ static void test_EM_POSFROMCHAR(void) SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0)+1); ok(pt.x == xpos, "pt.x = %d\n", pt.x); + /* Try a negative position. */ + SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt, -1); + ok(pt.x == 1, "pt.x = %d\n", pt.x); + DestroyWindow(hwndRichEdit); }