From f14e79319713639f7f62bf643595457995deb65d Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 8 Aug 2022 21:48:32 +0200 Subject: [PATCH] Make NULL conform to POSIX POSIX.1-2008 tightened the definition of NULL to be 0 cast to the type 'void *'. Defining NULL as 0 is problematic, because it requires users to cast NULL to a pointer type before passing it to variadic functions. Using POSIX's definition is safer, because NULL can be used in all contexts without a cast, due to the alignment of 'void *' and 'char *' being the same. It also helps the compiler be able to detect when NULL is being used in an integer context. Link: Signed-off-by: Alejandro Colomar --- include/stddef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stddef.h b/include/stddef.h index 3230a32b0..ca93edf62 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -54,7 +54,7 @@ typedef unsigned size_t; /* NULL pointer */ #ifndef _HAVE_NULL -#define NULL 0 +#define NULL ((void *) 0) #define _HAVE_NULL #endif