From 90af05f060e61707381f17728ee3266e0f38d613 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Sat, 7 May 2005 15:03:00 +0000 Subject: [PATCH] Treat 0xffff the same as 0 for the handle generation field to avoid sign extension problems. --- dlls/user/win.c | 5 +++-- server/user.c | 8 +++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/dlls/user/win.c b/dlls/user/win.c index 5c26ed7d455..90c17b6fae4 100644 --- a/dlls/user/win.c +++ b/dlls/user/win.c @@ -307,13 +307,14 @@ WND *WIN_GetPtr( HWND hwnd ) USER_Lock(); if ((ptr = user_handles[index])) { - if (ptr->dwMagic == WND_MAGIC && (!HIWORD(hwnd) || hwnd == ptr->hwndSelf)) + if (ptr->dwMagic == WND_MAGIC && + (hwnd == ptr->hwndSelf || !HIWORD(hwnd) || HIWORD(hwnd) == 0xffff)) return ptr; ptr = NULL; } else if (index == USER_HANDLE_TO_INDEX(hwndDesktop)) { - if (!HIWORD(hwnd) || hwnd == GetDesktopWindow()) ptr = WND_DESKTOP; + if (hwnd == GetDesktopWindow() || !HIWORD(hwnd) || HIWORD(hwnd) == 0xffff) ptr = WND_DESKTOP; else ptr = NULL; } else ptr = WND_OTHER_PROCESS; diff --git a/server/user.c b/server/user.c index 0429b135fb3..2f7135b8d5b 100644 --- a/server/user.c +++ b/server/user.c @@ -35,12 +35,14 @@ static int allocated_handles; static struct user_handle *handle_to_entry( user_handle_t handle ) { + unsigned short generation; int index = (((unsigned int)handle & 0xffff) - FIRST_USER_HANDLE) >> 1; if (index < 0 || index >= nb_handles) return NULL; if (!handles[index].type) return NULL; - if (((unsigned int)handle >> 16) && ((unsigned int)handle >> 16 != handles[index].generation)) - return NULL; - return &handles[index]; + generation = (unsigned int)handle >> 16; + if (generation == handles[index].generation || !generation || generation == 0xffff) + return &handles[index]; + return NULL; } inline static user_handle_t entry_to_handle( struct user_handle *ptr )