From: Michael Jeanson Date: Thu, 21 Jul 2022 15:51:11 +0000 (-0400) Subject: fix: clang warning '-Wnull-pointer-subtraction' in lttng_ust_is_pointer_type X-Git-Tag: v2.13.4~12 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=bfcbb918834017f74b01fdb61ebc6f9cb3c25b57;p=lttng-ust.git 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 --- 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