[PATCH] Check for bad scroll value and fix return values in EDIT_EM_Scroll

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Wed Jan 14 03:33:08 CST 2009


---
 dlls/user32/edit.c       |   18 +++++++++++---
 dlls/user32/tests/edit.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c
index 6914906..4cd1497 100644
--- a/dlls/user32/edit.c
+++ b/dlls/user32/edit.c
@@ -3430,13 +3430,23 @@ static LRESULT EDIT_EM_Scroll(EDITSTATE *es, INT action)
 	    INT vlc = get_vertical_line_count(es);
 	    /* check if we are going to move too far */
 	    if(es->y_offset + dy > es->line_count - vlc)
-		dy = es->line_count - vlc - es->y_offset;
+		{
+			dy = es->line_count - vlc - es->y_offset;
+
+			/* Make sure we're not trying to scroll backwards here */
+			if(es->y_offset + dy < 0)
+				dy = 0;
+		}
 
-	    /* Notification is done in EDIT_EM_LineScroll */
-	    if(dy)
+		/* Notification is done in EDIT_EM_LineScroll */
+		if(dy)
 		EDIT_EM_LineScroll(es, 0, dy);
 	}
-	return MAKELONG((INT16)dy, (BOOL16)TRUE);
+
+	if(dy)
+		return MAKELONG((INT16)dy, (BOOL16)TRUE);
+	else
+		return (LRESULT)FALSE;
 }
 
 
diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c
index b1a9820..ec4759e 100644
--- a/dlls/user32/tests/edit.c
+++ b/dlls/user32/tests/edit.c
@@ -1205,6 +1205,60 @@ static void test_edit_control_5(void)
     DestroyWindow(hWnd);
 }
 
+static void test_edit_control_6(void)
+{
+    HWND hwEdit;
+    LONG r;
+
+    static const char *single_line_str = "a";
+    static const char *multiline_str = "Test\nText";
+
+    /* Check the return value when EM_SCROLL doesn't actually scroll anything. */
+
+    hwEdit = CreateWindow(
+              "EDIT",
+              single_line_str,
+              WS_VSCROLL | ES_MULTILINE,
+              1, 1, 35, 35,
+              NULL, NULL, hinst, NULL);
+
+    assert(hwEdit);
+
+    trace("EDIT: Scrolling down one page \n");
+    r = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
+    ok(!r, "Returned %x\n", r);
+
+    trace("EDIT: Scrolling up one page \n");
+    r = SendMessage(hwEdit, EM_SCROLL, SB_PAGEUP, 0);
+    ok(!r, "Returned %x\n", r);
+
+    trace("EDIT: Scrolling up one line\n");
+    r = SendMessage(hwEdit, EM_SCROLL, SB_LINEUP, 0);
+    ok(!r, "Returned %x\n", r);
+
+    trace("EDIT: Scrolling down one line\n");
+    r = SendMessage(hwEdit, EM_SCROLL, SB_LINEDOWN, 0);
+    ok(!r, "Returned %x\n", r);
+
+    DestroyWindow (hwEdit);
+
+    /* Check for bug in wine where sending SB_PAGEDOWN causes
+       EDIT_EM_Scroll to return a negative amount of scrolled lines. */
+
+    hwEdit = CreateWindow(
+                "EDIT",
+                multiline_str,
+                ES_MULTILINE,
+                0, 0, 50, 1000,
+                NULL, NULL, hinst, NULL);
+    assert(hwEdit);
+
+    r = SendMessage(hwEdit, EM_SCROLL, SB_PAGEDOWN, 0);
+    ok(!r, "Returned %x\n", r);
+
+    DestroyWindow (hwEdit);
+}
+
 static void test_edit_control_limittext(void)
 {
     HWND hwEdit;
@@ -2058,6 +2112,7 @@ START_TEST(edit)
     test_edit_control_3();
     test_edit_control_4();
     test_edit_control_5();
+    test_edit_control_6();
     test_edit_control_limittext();
     test_margins();
     test_margins_font_change();
-- 
1.5.4.3


--------------000600020804050309080908--



More information about the wine-patches mailing list