Commit cf9f1859 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: GMEM_FIXED blocks cannot be 0 size.

parent 55efd7cf
...@@ -362,7 +362,7 @@ HGLOBAL WINAPI GlobalAlloc( ...@@ -362,7 +362,7 @@ HGLOBAL WINAPI GlobalAlloc(
if((flags & GMEM_MOVEABLE)==0) /* POINTER */ if((flags & GMEM_MOVEABLE)==0) /* POINTER */
{ {
palloc=HeapAlloc(GetProcessHeap(), hpflags, size); palloc = HeapAlloc( GetProcessHeap(), hpflags, max( 1, size ));
TRACE( "(flags=%04x) returning %p\n", flags, palloc ); TRACE( "(flags=%04x) returning %p\n", flags, palloc );
return palloc; return palloc;
} }
...@@ -961,10 +961,16 @@ SIZE_T WINAPI GlobalCompact( DWORD minfree ) ...@@ -961,10 +961,16 @@ SIZE_T WINAPI GlobalCompact( DWORD minfree )
* Windows memory management does not provide a separate local heap * Windows memory management does not provide a separate local heap
* and global heap. * and global heap.
*/ */
HLOCAL WINAPI LocalAlloc( HLOCAL WINAPI LocalAlloc( UINT flags, SIZE_T size )
UINT flags, /* [in] Allocation attributes */ {
SIZE_T size /* [in] Number of bytes to allocate */ /* LocalAlloc allows a 0-size fixed block, but GlobalAlloc doesn't */
) { if (!(flags & LMEM_MOVEABLE))
{
DWORD heap_flags = (flags & LMEM_ZEROINIT) ? HEAP_ZERO_MEMORY : 0;
void *ret = HeapAlloc( GetProcessHeap(), heap_flags, size );
TRACE( "(flags=%04x) returning %p\n", flags, ret );
return ret;
}
return GlobalAlloc( flags, size ); return GlobalAlloc( flags, size );
} }
......
...@@ -306,6 +306,12 @@ static void test_heap(void) ...@@ -306,6 +306,12 @@ static void test_heap(void)
"Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); "Expected ERROR_INVALID_HANDLE or ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
} }
gbl = GlobalAlloc( GMEM_FIXED, 0 );
SetLastError(0xdeadbeef);
size = GlobalSize( gbl );
ok( size == 1, "wrong size %lu\n", size );
GlobalFree( gbl );
/* ####################################### */ /* ####################################### */
/* Local*() functions */ /* Local*() functions */
gbl = LocalAlloc(LMEM_MOVEABLE, 0); gbl = LocalAlloc(LMEM_MOVEABLE, 0);
...@@ -438,6 +444,13 @@ static void test_heap(void) ...@@ -438,6 +444,13 @@ static void test_heap(void)
broken(GetLastError() == 0xdeadbeef) /* win9x */, "got %d\n", GetLastError()); broken(GetLastError() == 0xdeadbeef) /* win9x */, "got %d\n", GetLastError());
LocalFree(gbl); LocalFree(gbl);
gbl = LocalAlloc( LMEM_FIXED, 0 );
SetLastError(0xdeadbeef);
size = LocalSize( gbl );
ok( !size || broken(size == 1), /* vistau64 */
"wrong size %lu\n", size );
LocalFree( gbl );
/* trying to lock empty memory should give an error */ /* trying to lock empty memory should give an error */
gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0); gbl = GlobalAlloc(GMEM_MOVEABLE|GMEM_ZEROINIT,0);
ok(gbl != NULL, "returned NULL\n"); ok(gbl != NULL, "returned NULL\n");
......
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