Commit 839f00a9 authored by Detlef Riekenberg's avatar Detlef Riekenberg Committed by Alexandre Julliard

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

parent 714b66e9
......@@ -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());
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment