aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2019-02-02 16:11:17 +0100
committerXavier Leroy <xavierleroy@users.noreply.github.com>2019-02-04 16:18:43 +0100
commitd66bd1f776784e87e8583b2c064c518c15973191 (patch)
treeb474ccb49d680a279b0556fbefd5d34341ffabc6
parent5382c3cc9b24f59a050b4ef862cab392fa33ed30 (diff)
downloadcompcert-d66bd1f776784e87e8583b2c064c518c15973191.tar.gz
compcert-d66bd1f776784e87e8583b2c064c518c15973191.zip
<stddef.h>: 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
-rw-r--r--runtime/include/stddef.h2
1 files changed, 1 insertions, 1 deletions
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