Detlef Riekenberg : kernel: Fix handling of invalid parameter in GlobalSize ().

Alexandre Julliard julliard at wine.codeweavers.com
Fri Mar 31 13:05:15 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 839f00a967045250ac5d77f7af4b0f00269ff76a
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=839f00a967045250ac5d77f7af4b0f00269ff76a

Author: Detlef Riekenberg <wine.dev at web.de>
Date:   Fri Mar 31 12:27:30 2006 +0200

kernel: Fix handling of invalid parameter in GlobalSize().

---

 dlls/kernel/heap.c       |   19 +++++++++++++------
 dlls/kernel/tests/heap.c |   10 ++++++++++
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/dlls/kernel/heap.c b/dlls/kernel/heap.c
index c76f876..730379c 100644
--- a/dlls/kernel/heap.c
+++ b/dlls/kernel/heap.c
@@ -751,13 +751,19 @@ HGLOBAL WINAPI GlobalFree(HGLOBAL hmem)
  *
  * Get the size of a global memory object.
  *
+ * PARAMS
+ *  hmem [I] Handle of the global memory object
+ *
  * RETURNS
- *      Size in bytes of the global memory object
- *      0: Failure
+ *  Failure: 0
+ *  Success: Size in Bytes of the global memory object
+ *
+ * NOTES
+ *   When the handle is invalid, last error is set to ERROR_INVALID_HANDLE
+ *
  */
-SIZE_T WINAPI GlobalSize(
-             HGLOBAL hmem /* [in] Handle of global memory object */
-) {
+SIZE_T WINAPI GlobalSize(HGLOBAL hmem)
+{
    DWORD                retval;
    PGLOBAL32_INTERN     pintern;
 
@@ -785,7 +791,8 @@ SIZE_T WINAPI GlobalSize(
       }
       else
       {
-         WARN("invalid handle\n");
+         WARN("invalid handle %p (Magic: 0x%04x)\n", hmem, pintern->Magic);
+         SetLastError(ERROR_INVALID_HANDLE);
          retval=0;
       }
       RtlUnlockHeap(GetProcessHeap());
diff --git a/dlls/kernel/tests/heap.c b/dlls/kernel/tests/heap.c
index fee1830..089c502 100644
--- a/dlls/kernel/tests/heap.c
+++ b/dlls/kernel/tests/heap.c
@@ -92,6 +92,11 @@ START_TEST(heap)
     ok( (flags == GMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
         "returned 0x%04x with 0x%08lx (expected GMEM_INVALID_HANDLE with " \
         "ERROR_INVALID_HANDLE)\n", flags, GetLastError());
+    SetLastError(MAGIC_DEAD);
+    size = GlobalSize(gbl);
+    ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE),
+        "returned %ld with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n",
+        size, GetLastError());
 
 
     /* Local*() functions */
@@ -128,6 +133,11 @@ START_TEST(heap)
     ok( (flags == LMEM_INVALID_HANDLE) && (GetLastError() == ERROR_INVALID_HANDLE),
         "returned 0x%04x with 0x%08lx (expected LMEM_INVALID_HANDLE with " \
         "ERROR_INVALID_HANDLE)\n", flags, GetLastError());
+    SetLastError(MAGIC_DEAD);
+    size = LocalSize(gbl);
+    ok( (size == 0) && (GetLastError() == ERROR_INVALID_HANDLE),
+        "returned %ld with 0x%08lx (expected '0' with ERROR_INVALID_HANDLE)\n",
+        size, GetLastError());
 
 
     /* trying to lock empty memory should give an error */




More information about the wine-cvs mailing list