From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9426 invoked from network); 15 Aug 2021 15:52:16 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 15 Aug 2021 15:52:16 -0000 Received: (qmail 26200 invoked by uid 550); 15 Aug 2021 15:52:15 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 26170 invoked from network); 15 Aug 2021 15:52:14 -0000 From: Ismael Luceno To: musl@lists.openwall.com Cc: Ismael Luceno Date: Sun, 15 Aug 2021 17:51:57 +0200 Message-Id: <20210815155157.692-1-ismael@iodev.co.uk> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH] Define NULL as nullptr when used in C++ This should be safer for casting and more compatible with existing code bases that wrongly assume it must be defined as a pointer. Signed-off-by: Ismael Luceno --- include/locale.h | 4 +++- include/stddef.h | 4 +++- include/stdio.h | 4 +++- include/stdlib.h | 4 +++- include/string.h | 4 +++- include/time.h | 4 +++- include/unistd.h | 4 +++- include/wchar.h | 4 +++- 8 files changed, 24 insertions(+), 8 deletions(-) diff --git a/include/locale.h b/include/locale.h index ce384381c6bd..11106fea878a 100644 --- a/include/locale.h +++ b/include/locale.h @@ -7,7 +7,9 @@ extern "C" { #include -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/stddef.h b/include/stddef.h index bd753853503d..f25b86396e80 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -1,7 +1,9 @@ #ifndef _STDDEF_H #define _STDDEF_H -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/stdio.h b/include/stdio.h index 3604198c3e50..d1ed01f03f8f 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -25,7 +25,9 @@ extern "C" { #include -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/stdlib.h b/include/stdlib.h index b54a051fe9fd..66fff9a04ca4 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -7,7 +7,9 @@ extern "C" { #include -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/string.h b/include/string.h index 795a2abcd990..43ad0942edd5 100644 --- a/include/string.h +++ b/include/string.h @@ -7,7 +7,9 @@ extern "C" { #include -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/time.h b/include/time.h index 5494df183673..3d94837205ad 100644 --- a/include/time.h +++ b/include/time.h @@ -7,7 +7,9 @@ extern "C" { #include -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/unistd.h b/include/unistd.h index 130640260368..ee2dbe8aff0c 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -15,7 +15,9 @@ extern "C" { #define SEEK_CUR 1 #define SEEK_END 2 -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) diff --git a/include/wchar.h b/include/wchar.h index 88eb55b18cc1..ed5d774dfa96 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -38,7 +38,9 @@ extern "C" { #define WCHAR_MIN (-1-0x7fffffff+L'\0') #endif -#ifdef __cplusplus +#if __cplusplus >= 201103L +#define NULL nullptr +#elif defined(__cplusplus) #define NULL 0L #else #define NULL ((void*)0) -- 2.32.0