From 4797a7d4cedec42b1e0fc991bd39ce558b90409f Mon Sep 17 00:00:00 2001 From: ceriel Date: Wed, 29 Mar 1989 12:58:18 +0000 Subject: [PATCH] make realloc behave like most Unix realloc versions when handed a null pointer --- modules/src/malloc/mal.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/modules/src/malloc/mal.c b/modules/src/malloc/mal.c index 44a19266e..b7a72ac0f 100644 --- a/modules/src/malloc/mal.c +++ b/modules/src/malloc/mal.c @@ -221,9 +221,16 @@ realloc(addr, n) char *addr; register unsigned int n; {check_mallinks("realloc entry");{ - register mallink *ml = mallink_of_block(addr), *ph_next; + register mallink *ml, *ph_next; register unsigned int size; + if (addr == 0) { + /* Behave like most Unix realloc's when handed a + null-pointer + */ + return malloc(n); + } + ml = mallink_of_block(addr); if (n < MIN_SIZE) n = align(MIN_SIZE); else n = align(n); if (free_of(ml)) { unlink_free_chunk(ml);