Author: amunger
Date: Thu Jun 28 11:05:24 2007
New Revision: 27299
URL:
http://svn.reactos.org/svn/reactos?rev=27299&view=rev
Log:
Fix realloc behavior when size == 0 and ptr != NULL.
Patch by DrV, bug 2347.
Modified:
trunk/reactos/lib/sdk/crt/stdlib/malloc.c
Modified: trunk/reactos/lib/sdk/crt/stdlib/malloc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/stdlib/malloc.…
==============================================================================
--- trunk/reactos/lib/sdk/crt/stdlib/malloc.c (original)
+++ trunk/reactos/lib/sdk/crt/stdlib/malloc.c Thu Jun 28 11:05:24 2007
@@ -72,19 +72,23 @@
void* realloc(void* _ptr, size_t _size)
{
size_t nSize;
-
- if (( _size == 0) && (_ptr !=NULL))
+
+ if (_ptr == NULL)
+ return malloc(_size);
+
+ if (_size == 0)
+ {
+ free(_ptr);
return NULL;
+ }
nSize = ROUND_SIZE(_size);
+ /* check for integer overflow */
if (nSize<_size)
return NULL;
-
- if (!_ptr) return malloc(_size);
- if (_size) return HeapReAlloc(hHeap, 0, _ptr, nSize);
- free(_ptr);
- return NULL;
+
+ return HeapReAlloc(hHeap, 0, _ptr, nSize);
}
/*