AT&T Unix PC : 15-realloc-null

Alain Knaff <[email protected]> Sun, 17 Nov 2024 19:50:58 +0100
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
Hi,

On UnixPC, realloc of a NULL pointer returns NULL, whereas on most
today's architectures it behaves the same way as malloc.

So we just wrap it.

Regards,

Alain

diff -X ../exclude.txt -urN dash-0.5.12+14-broken-wait-h/src/memalloc.c dash-0.5.12+15-realloc-null/src/memalloc.c
--- dash-0.5.12+14-broken-wait-h/src/memalloc.c	2024-10-27 20:32:54.604833876 +0000
+++ dash-0.5.12+15-realloc-null/src/memalloc.c	2024-10-27 20:32:44.700597405 +0000
@@ -68,7 +68,10 @@
 pointer
 ckrealloc(pointer p, size_t nbytes)
 {
-	p = realloc(p, nbytes);
+	if(p == NULL)
+		p = malloc(nbytes);
+	else
+		p = realloc(p, nbytes);
 	if (p == NULL)
 		sh_error("Out of space");
 	return p;