fix: clang warning '-Wnull-pointer-subtraction' in lttng_ust_is_pointer_type
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 21 Jul 2022 15:51:11 +0000 (11:51 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 21 Jul 2022 17:56:22 +0000 (13:56 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-utils.h

index 25b8c7fdb835d55c9f815278c4c2aa1386c1a648..d815cf0cc465ef5f3a8864e12d5125fed85057ff 100644 (file)
@@ -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
 
 
This page took 0.025186 seconds and 4 git commands to generate.