[PATCH 2/2] user32: Fix error handling in MapWindowPoints, ClientToScreen and ScreenToClient. (try 7)

Christian Costa titan.costa at gmail.com
Tue Nov 13 14:16:52 CST 2012


Try 7: Put tests in a separate patch
---
 dlls/user32/tests/win.c |   38 ++++++++---------
 dlls/user32/winpos.c    |  106 ++++++++++++++++++++++++++++++++++-------------
 2 files changed, 94 insertions(+), 50 deletions(-)

diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 8217cb7..a977ac2 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -7168,7 +7168,7 @@ static void test_map_points(void)
     err = GetLastError();
     ok(n == 0, "Got %d, expected %d\n", n, 0);
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
@@ -7176,7 +7176,7 @@ static void test_map_points(void)
     err = GetLastError();
     ok(n == 0, "Got %d, expected %d\n", n, 0);
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
@@ -7184,7 +7184,7 @@ static void test_map_points(void)
     err = GetLastError();
     ok(n == 0, "Got %d, expected %d\n", n, 0);
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
@@ -7192,7 +7192,7 @@ static void test_map_points(void)
     err = GetLastError();
     ok(n == 0, "Got %d, expected %d\n", n, 0);
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
@@ -7200,7 +7200,7 @@ static void test_map_points(void)
     err = GetLastError();
     ok(n == 0, "Got %d, expected %d\n", n, 0);
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
@@ -7252,29 +7252,27 @@ static void test_map_points(void)
 
     /* ClientToScreen(wnd, NULL); crashes on Windows */
 
-#if 0 /* Crash happens with current Wine implementation */
     SetLastError(0xdeadbeef);
     ret = ClientToScreen(NULL, NULL);
     err = GetLastError();
-    todo_wine ok(!ret, "Should fail\n");
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
-#endif
+    ok(!ret, "Should fail\n");
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
     ret = ClientToScreen(NULL, &p);
     err = GetLastError();
-    todo_wine ok(!ret, "Should fail\n");
+    ok(!ret, "Should fail\n");
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
     ret = ClientToScreen(dwnd, &p);
     err = GetLastError();
-    todo_wine ok(!ret, "Should fail\n");
+    ok(!ret, "Should fail\n");
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     p.x = p.y = 100;
     ret = ClientToScreen(wnd, &p);
@@ -7291,29 +7289,27 @@ static void test_map_points(void)
 
     /* ScreenToClient(wnd, NULL); crashes on Windows */
 
-#if 0 /* Crash happens with current Wine implementation */
     SetLastError(0xdeadbeef);
     ret = ScreenToClient(NULL, NULL);
     err = GetLastError();
-    todo_wine ok(!ret, "Should fail\n");
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
-#endif
+    ok(!ret, "Should fail\n");
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
     ret = ScreenToClient(NULL, &p);
     err = GetLastError();
-    todo_wine ok(!ret, "Should fail\n");
+    ok(!ret, "Should fail\n");
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     SetLastError(0xdeadbeef);
     p.x = p.y = 100;
     ret = ScreenToClient(dwnd, &p);
     err = GetLastError();
-    todo_wine ok(!ret, "Should fail\n");
+    ok(!ret, "Should fail\n");
     ok(p.x == 100 && p.y == 100, "Failed got(%d, %d), expected (%d, %d)\n", p.x, p.y, 100, 100);
-    todo_wine ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
+    ok(err == ERROR_INVALID_WINDOW_HANDLE, "Got %x, expected %x\n", err, ERROR_INVALID_WINDOW_HANDLE);
 
     p.x = p.y = 100;
     ret = ScreenToClient(wnd, &p);
diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c
index eda5b78..68c6a5c 100644
--- a/dlls/user32/winpos.c
+++ b/dlls/user32/winpos.c
@@ -235,26 +235,6 @@ BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
 }
 
 
-/*******************************************************************
- *		ClientToScreen (USER32.@)
- */
-BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
-{
-    MapWindowPoints( hwnd, 0, lppnt, 1 );
-    return TRUE;
-}
-
-
-/*******************************************************************
- *		ScreenToClient (USER32.@)
- */
-BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
-{
-    MapWindowPoints( 0, hwnd, lppnt, 1 );
-    return TRUE;
-}
-
-
 /***********************************************************************
  *           list_children_from_point
  *
@@ -422,7 +402,7 @@ HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
  * Calculate the offset between the origin of the two windows. Used
  * to implement MapWindowPoints.
  */
-static POINT WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, BOOL *mirrored )
+static BOOL WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, BOOL *mirrored, POINT *point )
 {
     WND * wndPtr;
     POINT offset;
@@ -432,10 +412,20 @@ static POINT WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, BOOL *mirrored )
     offset.x = offset.y = 0;
     *mirrored = mirror_from = mirror_to = FALSE;
 
+    if ((hwndFrom && !IsWindow(hwndFrom)) || (hwndTo && !IsWindow(hwndTo)))
+    {
+        *point = offset;
+        return FALSE;
+    }
+
     /* Translate source window origin to screen coords */
     if (hwndFrom)
     {
-        if (!(wndPtr = WIN_GetPtr( hwndFrom ))) return offset;
+        if (!(wndPtr = WIN_GetPtr( hwndFrom )))
+        {
+            *point = offset;
+            return FALSE;
+        }
         if (wndPtr == WND_OTHER_PROCESS) goto other_process;
         if (wndPtr != WND_DESKTOP)
         {
@@ -466,7 +456,11 @@ static POINT WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, BOOL *mirrored )
     /* Translate origin to destination window coords */
     if (hwndTo)
     {
-        if (!(wndPtr = WIN_GetPtr( hwndTo ))) return offset;
+        if (!(wndPtr = WIN_GetPtr( hwndTo )))
+        {
+            *point = offset;
+            return FALSE;
+        }
         if (wndPtr == WND_OTHER_PROCESS) goto other_process;
         if (wndPtr != WND_DESKTOP)
         {
@@ -496,9 +490,10 @@ static POINT WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, BOOL *mirrored )
 
     *mirrored = mirror_from ^ mirror_to;
     if (mirror_from) offset.x = -offset.x;
-    return offset;
+    *point = offset;
+    return TRUE;
 
- other_process:  /* one of the parents may belong to another process, do it the hard way */
+other_process:  /* one of the parents may belong to another process, do it the hard way */
     offset.x = offset.y = 0;
     SERVER_START_REQ( get_windows_offset )
     {
@@ -512,19 +507,22 @@ static POINT WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, BOOL *mirrored )
         }
     }
     SERVER_END_REQ;
-    return offset;
+    *point = offset;
+    return TRUE;
 }
 
 /* map coordinates of a window region */
 void map_window_region( HWND from, HWND to, HRGN hrgn )
 {
     BOOL mirrored;
-    POINT offset = WINPOS_GetWinOffset( from, to, &mirrored );
+    POINT offset;
     UINT i, size;
     RGNDATA *data;
     HRGN new_rgn;
     RECT *rect;
 
+    WINPOS_GetWinOffset( from, to, &mirrored, &offset );
+
     if (!mirrored)
     {
         OffsetRgn( hrgn, offset.x, offset.y );
@@ -552,14 +550,20 @@ void map_window_region( HWND from, HWND to, HRGN hrgn )
 
 
 /*******************************************************************
- *		MapWindowPoints (USER32.@)
+ *             MapWindowPoints (USER32.@)
  */
 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
 {
     BOOL mirrored;
-    POINT offset = WINPOS_GetWinOffset( hwndFrom, hwndTo, &mirrored );
+    POINT offset;
     UINT i;
 
+    if (!WINPOS_GetWinOffset( hwndFrom, hwndTo, &mirrored, &offset ))
+    {
+        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        return 0;
+    }
+
     for (i = 0; i < count; i++)
     {
         lppt[i].x += offset.x;
@@ -576,6 +580,50 @@ INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count
 }
 
 
+/*******************************************************************
+ *             ClientToScreen (USER32.@)
+ */
+BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
+{
+    BOOL mirrored;
+    POINT offset;
+
+    if (!hwnd || !WINPOS_GetWinOffset( hwnd, NULL, &mirrored, &offset ))
+    {
+        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        return FALSE;
+    }
+
+    lppnt->x += offset.x;
+    lppnt->y += offset.y;
+    if (mirrored) lppnt->x -= lppnt->x;
+
+    return TRUE;
+}
+
+
+/*******************************************************************
+ *             ScreenToClient (USER32.@)
+ */
+BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
+{
+    BOOL mirrored;
+    POINT offset;
+
+    if (!hwnd || !WINPOS_GetWinOffset( NULL, hwnd, &mirrored, &offset ))
+    {
+        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        return FALSE;
+    }
+
+    lppnt->x += offset.x;
+    lppnt->y += offset.y;
+    if (mirrored) lppnt->x -= lppnt->x;
+
+    return TRUE;
+}
+
+
 /***********************************************************************
  *		IsIconic (USER32.@)
  */




More information about the wine-patches mailing list