diff mbox series

AT&T Unix PC : 15-realloc-null

Message ID 69f0a5dd-cd31-48c3-a633-9d26ab93714f@knaff.lu (mailing list archive)
State New
Headers show
Series AT&T Unix PC : 15-realloc-null | expand

Commit Message

Alain Knaff Nov. 17, 2024, 6:50 p.m. UTC
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 mbox series

Patch

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;