David Hedberg : kernel32: GlobalSize() should also work with GMEM_MOVEABLE data pointers received from GlobalLock ().
Alexandre Julliard
julliard at winehq.org
Mon Jun 13 11:49:17 CDT 2011
Module: wine
Branch: master
Commit: fed025fd42b642ae86189f329043969599ed6501
URL: http://source.winehq.org/git/wine.git/?a=commit;h=fed025fd42b642ae86189f329043969599ed6501
Author: David Hedberg <dhedberg at codeweavers.com>
Date: Mon Jun 13 08:22:15 2011 +0200
kernel32: GlobalSize() should also work with GMEM_MOVEABLE data pointers received from GlobalLock().
---
dlls/kernel32/heap.c | 6 ++++++
dlls/kernel32/tests/heap.c | 32 +++++++++++++++++++++++++++++++-
2 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/dlls/kernel32/heap.c b/dlls/kernel32/heap.c
index 7be9172..4ade995 100644
--- a/dlls/kernel32/heap.c
+++ b/dlls/kernel32/heap.c
@@ -820,6 +820,12 @@ SIZE_T WINAPI GlobalSize(HGLOBAL hmem)
if(ISPOINTER(hmem))
{
retval=HeapSize(GetProcessHeap(), 0, hmem);
+
+ if (retval == (DWORD)-1) /* It might be a GMEM_MOVEABLE data pointer */
+ {
+ retval = HeapSize(GetProcessHeap(), 0, (char*)(hmem) - HGLOBAL_STORAGE);
+ if (retval != (DWORD)-1) retval -= HGLOBAL_STORAGE;
+ }
}
else
{
diff --git a/dlls/kernel32/tests/heap.c b/dlls/kernel32/tests/heap.c
index f7ac478..26bc58f 100644
--- a/dlls/kernel32/tests/heap.c
+++ b/dlls/kernel32/tests/heap.c
@@ -85,7 +85,7 @@ static void test_heap(void)
UINT flags;
HGLOBAL gbl;
HGLOBAL hsecond;
- SIZE_T size;
+ SIZE_T size, size2;
/* Heap*() functions */
mem = HeapAlloc(GetProcessHeap(), 0, 0);
@@ -403,6 +403,36 @@ static void test_heap(void)
"MAGIC_DEAD)\n", mem, GetLastError(), GetLastError());
GlobalFree(gbl);
+
+ /* trying to get size from data pointer (GMEM_MOVEABLE) */
+ gbl = GlobalAlloc(GMEM_MOVEABLE, 0x123);
+ ok(gbl != NULL, "returned NULL\n");
+ mem = GlobalLock(gbl);
+ ok(mem != NULL, "returned NULL.\n");
+ ok(gbl != mem, "unexpectedly equal.\n");
+
+ size = GlobalSize(gbl);
+ size2 = GlobalSize(mem);
+ ok(size == 0x123, "got %lu\n", size);
+ ok(size2 == 0x123, "got %lu\n", size2);
+
+ GlobalFree(gbl);
+
+ /* trying to get size from data pointer (GMEM_FIXED) */
+ gbl = GlobalAlloc(GMEM_FIXED, 0x123);
+ ok(gbl != NULL, "returned NULL\n");
+ mem = GlobalLock(gbl);
+ ok(mem != NULL, "returned NULL.\n");
+ ok(gbl == mem, "got %p, %p.\n", gbl, mem);
+
+ size = GlobalSize(gbl);
+ ok(size == 0x123, "got %lu\n", size);
+
+ GlobalFree(gbl);
+
+ size = GlobalSize((void *)0xdeadbee0);
+ ok(size == 0, "got %lu\n", size);
+
}
static void test_obsolete_flags(void)
More information about the wine-cvs
mailing list