mirror of
https://github.com/reactos/reactos.git
synced 2024-10-30 11:35:58 +00:00
alloc at minimum 16 bytes (spotted by WaxDragon)
realloc should free passed mem if new size is 0 svn path=/trunk/; revision=18404
This commit is contained in:
parent
1fc06afd71
commit
b1761726b2
|
@ -29,6 +29,9 @@
|
|||
/* fixme: should have this in common header */
|
||||
#define ROUND_UP(a,b) ((a + (b-1)) & ~(b-1))
|
||||
|
||||
/* round to 16 bytes + alloc at minimum 16 bytes */
|
||||
#define ROUND_SIZE(size) (max(16, ROUND_UP(size, 16)))
|
||||
|
||||
extern HANDLE hHeap;
|
||||
|
||||
/*
|
||||
|
@ -36,7 +39,7 @@ extern HANDLE hHeap;
|
|||
*/
|
||||
void* malloc(size_t _size)
|
||||
{
|
||||
return HeapAlloc(hHeap, 0, ROUND_UP(_size, 16));
|
||||
return HeapAlloc(hHeap, 0, ROUND_SIZE(_size));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -52,7 +55,7 @@ void free(void* _ptr)
|
|||
*/
|
||||
void* calloc(size_t _nmemb, size_t _size)
|
||||
{
|
||||
return HeapAlloc(hHeap, HEAP_ZERO_MEMORY, ROUND_UP(_nmemb*_size, 16) );
|
||||
return HeapAlloc(hHeap, HEAP_ZERO_MEMORY, ROUND_SIZE(_nmemb*_size) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -60,9 +63,10 @@ void* calloc(size_t _nmemb, size_t _size)
|
|||
*/
|
||||
void* realloc(void* _ptr, size_t _size)
|
||||
{
|
||||
if (!_ptr)
|
||||
return HeapAlloc(hHeap, 0, ROUND_UP(_size, 16));
|
||||
return HeapReAlloc(hHeap, 0, _ptr, ROUND_UP(_size, 16));
|
||||
if (!_ptr) return malloc(_size);
|
||||
if (_size) return HeapReAlloc(hHeap, 0, _ptr, ROUND_SIZE(_size));
|
||||
free(_ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -70,7 +74,7 @@ void* realloc(void* _ptr, size_t _size)
|
|||
*/
|
||||
void* _expand(void* _ptr, size_t _size)
|
||||
{
|
||||
return HeapReAlloc(hHeap, HEAP_REALLOC_IN_PLACE_ONLY, _ptr, ROUND_UP(_size, 16));
|
||||
return HeapReAlloc(hHeap, HEAP_REALLOC_IN_PLACE_ONLY, _ptr, ROUND_SIZE(_size));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue