From bfcbb918834017f74b01fdb61ebc6f9cb3c25b57 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 21 Jul 2022 11:51:11 -0400 Subject: [PATCH] fix: clang warning '-Wnull-pointer-subtraction' in lttng_ust_is_pointer_type Some versions of Clang enable '-Wnull-pointer-subtraction' in '-Wall' which results in the following message: ././ust-utils-common.h:166:2: warning: performing pointer subtraction with a null pointer has undefined behavior [-Wnull-pointer-subtraction] ok_is_pointer_type(void *); ^~~~~~~~~~~~~~~~~~~~~~~~~~ ././ust-utils-common.h:120:5: note: expanded from macro 'ok_is_pointer_type' ok(lttng_ust_is_pointer_type(_type) == true, "lttng_ust_is_pointer_type - '" lttng_ust_stringify(_type) "' is a pointer") ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../../include/lttng/ust-utils.h:71:45: note: expanded from macro 'lttng_ust_is_pointer_type' (lttng_ust_is_integer_type(typeof(((type)0 - (type)0))) && !lttng_ust_is_integer_type(type)) ^ Since this macro is used only the determine if the type is a pointer we can use any value other than NULL and thus not depend on undefined behavior. Change-Id: Iab7a182f580ce7431a817ab006ecdf3f1da09ae0 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- include/lttng/ust-utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/lttng/ust-utils.h b/include/lttng/ust-utils.h index fa97bf35..7cb0ea34 100644 --- a/include/lttng/ust-utils.h +++ b/include/lttng/ust-utils.h @@ -68,7 +68,7 @@ #else /* The difference between two pointers is an integer. */ #define lttng_ust_is_pointer_type(type) \ - (lttng_ust_is_integer_type(typeof(((type)0 - (type)0))) && !lttng_ust_is_integer_type(type)) + (lttng_ust_is_integer_type(typeof(((type)1 - (type)1))) && !lttng_ust_is_integer_type(type)) #endif -- 2.34.1