Author: greatlrd
Date: Sat Jun 3 21:40:23 2006
New Revision: 22197
URL:
http://svn.reactos.ru/svn/reactos?rev=22197&view=rev
Log:
fixing malloc and realloc so it return right value
do not mix the doc over malloc and realloc. Thanks filip
<filip2307> malloc(0) -> valid buffer
<GreatLord> then I revert that change
<filip2307> realloc(<non-null pointer>, 0) -> NULL
<filip2307> realloc(NULL, 0) -> valid buffer
Modified:
trunk/reactos/lib/crt/stdlib/malloc.c
Modified: trunk/reactos/lib/crt/stdlib/malloc.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/lib/crt/stdlib/malloc.c?rev…
==============================================================================
--- trunk/reactos/lib/crt/stdlib/malloc.c (original)
+++ trunk/reactos/lib/crt/stdlib/malloc.c Sat Jun 3 21:40:23 2006
@@ -36,12 +36,7 @@
*/
void* malloc(size_t _size)
{
- size_t nSize;
-
- if ( _size == 0)
- return NULL;
-
- nSize = ROUND_SIZE(_size);
+ size_t nSize = ROUND_SIZE(_size);
if (nSize<_size)
return NULL;
@@ -65,7 +60,7 @@
size_t nSize = _nmemb * _size;
size_t cSize = ROUND_SIZE(nSize);
- if ((_nmemb > ((size_t)-1 / _size) || (nSize == 0) || (cSize<nSize))
+ if ((_nmemb > ((size_t)-1 / _size) || (cSize<nSize))
return NULL;
return HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cSize );
@@ -78,7 +73,7 @@
{
size_t nSize;
- if ( _size == 0)
+ if (( _size == 0) && (_ptr !=NULL)
return NULL;
nSize = ROUND_SIZE(_size);
@@ -98,10 +93,7 @@
void* _expand(void* _ptr, size_t _size)
{
size_t nSize;
-
- if ( _size == 0)
- return NULL;
-
+
nSize = ROUND_SIZE(_size);
if (nSize<_size)