Only allocate even-numbered window handles, MS Project depends on that
(found by Dmitry Timoshkov).
diff --git a/server/user.c b/server/user.c
index 6f99ac4..0429b13 100644
--- a/server/user.c
+++ b/server/user.c
@@ -35,7 +35,7 @@
static struct user_handle *handle_to_entry( user_handle_t handle )
{
- int index = ((unsigned int)handle & 0xffff) - FIRST_USER_HANDLE;
+ 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))
@@ -46,7 +46,7 @@
inline static user_handle_t entry_to_handle( struct user_handle *ptr )
{
int index = ptr - handles;
- return (user_handle_t)((index + FIRST_USER_HANDLE) + (ptr->generation << 16));
+ return (user_handle_t)(((index << 1) + FIRST_USER_HANDLE) + (ptr->generation << 16));
}
inline static struct user_handle *alloc_user_entry(void)
@@ -64,7 +64,7 @@
struct user_handle *new_handles;
/* grow array by 50% (but at minimum 32 entries) */
int growth = max( 32, allocated_handles / 2 );
- int new_size = min( allocated_handles + growth, LAST_USER_HANDLE-FIRST_USER_HANDLE+1 );
+ int new_size = min( allocated_handles + growth, (LAST_USER_HANDLE-FIRST_USER_HANDLE+1) >> 1 );
if (new_size <= allocated_handles) return NULL;
if (!(new_handles = realloc( handles, new_size * sizeof(*handles) )))
return NULL;
@@ -147,7 +147,7 @@
if (!*handle) entry = handles;
else
{
- int index = ((unsigned int)*handle & 0xffff) - FIRST_USER_HANDLE;
+ int index = (((unsigned int)*handle & 0xffff) - FIRST_USER_HANDLE) >> 1;
if (index < 0 || index >= nb_handles) return NULL;
entry = handles + index + 1; /* start from the next one */
}
diff --git a/windows/win.c b/windows/win.c
index e47ea3f..52259d9 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -45,7 +45,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(win);
WINE_DECLARE_DEBUG_CHANNEL(msg);
-#define NB_USER_HANDLES (LAST_USER_HANDLE - FIRST_USER_HANDLE + 1)
+#define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
+#define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
/**********************************************************************/
@@ -110,7 +111,7 @@
USER_Lock();
- index = LOWORD(handle) - FIRST_USER_HANDLE;
+ index = USER_HANDLE_TO_INDEX(handle);
assert( index < NB_USER_HANDLES );
user_handles[index] = win;
win->hwndSelf = handle;
@@ -131,7 +132,7 @@
static WND *free_window_handle( HWND hwnd )
{
WND *ptr;
- WORD index = LOWORD(hwnd) - FIRST_USER_HANDLE;
+ WORD index = USER_HANDLE_TO_INDEX(hwnd);
if (index >= NB_USER_HANDLES) return NULL;
USER_Lock();
@@ -234,7 +235,7 @@
WND *WIN_GetPtr( HWND hwnd )
{
WND * ptr;
- WORD index = LOWORD(hwnd) - FIRST_USER_HANDLE;
+ WORD index = USER_HANDLE_TO_INDEX(hwnd);
if (index >= NB_USER_HANDLES) return NULL;