Only allocate even-numbered window handles, MS Project depends on that

(found by Dmitry Timoshkov).
This commit is contained in:
Alexandre Julliard 2004-05-28 19:35:37 +00:00
parent a8877ba6dc
commit ed8a41c7b5
2 changed files with 9 additions and 8 deletions

View File

@ -35,7 +35,7 @@ static int allocated_handles;
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 @@ static struct user_handle *handle_to_entry( user_handle_t handle )
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 @@ inline static struct user_handle *alloc_user_entry(void)
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 @@ void *next_user_handle( user_handle_t *handle, enum user_object type )
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 */
}

View File

@ -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 @@ static WND *create_window_handle( HWND parent, HWND owner, ATOM atom,
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 *create_window_handle( HWND parent, HWND owner, ATOM atom,
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 @@ static void get_server_window_text( HWND hwnd, LPWSTR text, INT count )
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;