From 5bb35772b3008805ba7a212d19098cead9abf1d4 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin (Intel)" Date: Fri, 16 Aug 2019 00:29:04 -0700 Subject: BR 3392597: the system malloc() can return NULL malloc(0) can legitimately return NULL; it does on some systems and not others. Force the size to 1 byte if the size is 0 coming in, except for realloc() where this is legitimate and equivalent to free(). Since this is an abnormal case, and can't even happen with most C libraries, handle it on the error path, after we already got back a NULL pointer. Reported-by: Ozkan Sezer Signed-off-by: H. Peter Anvin (Intel) --- include/nasmlib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/nasmlib.h') diff --git a/include/nasmlib.h b/include/nasmlib.h index eb3a637d..2e2519f5 100644 --- a/include/nasmlib.h +++ b/include/nasmlib.h @@ -109,7 +109,7 @@ static inline size_t nasm_last_string_size(void) #define nasm_assert_pointer(p) ((void)sizeof(*(p))) #define nasm_new(p) ((p) = nasm_zalloc(sizeof(*(p)))) -#define nasm_newn(p,n) ((p) = nasm_calloc(sizeof(*(p)),(n))) +#define nasm_newn(p,n) ((p) = nasm_calloc((n), sizeof(*(p)))) /* * This is broken on platforms where there are pointers which don't * match void * in their internal layout. It unfortunately also -- cgit