mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Allow xrealloc to act as a free() when size=0, per SuS2.
-Erik
This commit is contained in:
parent
ec23c4920f
commit
029b4a0422
@ -44,7 +44,17 @@ extern void *xmalloc(size_t size)
|
||||
|
||||
extern void *xrealloc(void *old, size_t size)
|
||||
{
|
||||
void *ptr = realloc(old, size);
|
||||
void *ptr;
|
||||
|
||||
/* SuS2 says "If size is 0 and ptr is not a null pointer, the
|
||||
* object pointed to is freed." Do that here, in case realloc
|
||||
* returns a NULL, since we don't want to choke in that case. */
|
||||
if (size==0 && old) {
|
||||
free(old);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr = realloc(old, size);
|
||||
if (!ptr)
|
||||
error_msg_and_die(memory_exhausted);
|
||||
return ptr;
|
||||
|
Loading…
Reference in New Issue
Block a user