From d66bd1f776784e87e8583b2c064c518c15973191 Mon Sep 17 00:00:00 2001 From: Xavier Leroy Date: Sat, 2 Feb 2019 16:11:17 +0100 Subject: : define NULL with type void * ISO C2011 7.19 para 3 says "NULL, which expands to an implementation-defined null pointer constant" ISO C2011 6.3.2.3 para 3 says "An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant." So, it seems NULL can be defined either as "0" or as "(void *) 0". However, the two definitions are not equivalent in the context of a call to a variadic or unprototyped function: passing 0 when the function expects a pointer value can go wrong if sizeof(int) != sizeof(void *). This commit changes the definition of NULL to the safer one: This is what GCC and Clang do in C mode; they use "#define NULL 0" for C++ only. Fixes issue #265 --- runtime/include/stddef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/include') diff --git a/runtime/include/stddef.h b/runtime/include/stddef.h index 6056db62..5a66215a 100644 --- a/runtime/include/stddef.h +++ b/runtime/include/stddef.h @@ -108,7 +108,7 @@ typedef signed int wchar_t; #if defined(_STDDEF_H) || defined(__need_NULL) #ifndef NULL -#define NULL 0 +#define NULL ((void *) 0) #endif #undef __need_NULL #endif -- cgit