From: Mathieu Desnoyers Date: Thu, 28 Nov 2013 17:41:13 +0000 (+0100) Subject: Fix undefined NULL pointer arithmetic X-Git-Tag: v0.8.2~16 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=842f5c90d7f3c4cec72c4dc35ac4be093d8b8963;p=userspace-rcu.git Fix undefined NULL pointer arithmetic Clang 3.3 with -O2 optimisations is especially picky about arithmetic on NULL pointers. This undefined behavior is turned into optimized out NULL checks by clang 3.3. Fix the undefined behavior by checking against the pointer directly, without going back and forth around NULL with pointer arithmetic. Reported-by: Zifei Tong Signed-off-by: Mathieu Desnoyers --- diff --git a/urcu/rculfhash.h b/urcu/rculfhash.h index 7a411ad..d8c85bc 100644 --- a/urcu/rculfhash.h +++ b/urcu/rculfhash.h @@ -471,7 +471,7 @@ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size); for (cds_lfht_first(ht, iter), \ pos = caa_container_of(cds_lfht_iter_get_node(iter), \ __typeof__(*(pos)), member); \ - &(pos)->member != NULL; \ + cds_lfht_iter_get_node(iter) != NULL; \ cds_lfht_next(ht, iter), \ pos = caa_container_of(cds_lfht_iter_get_node(iter), \ __typeof__(*(pos)), member)) @@ -481,7 +481,7 @@ void cds_lfht_resize(struct cds_lfht *ht, unsigned long new_size); for (cds_lfht_lookup(ht, hash, match, key, iter), \ pos = caa_container_of(cds_lfht_iter_get_node(iter), \ __typeof__(*(pos)), member); \ - &(pos)->member != NULL; \ + cds_lfht_iter_get_node(iter) != NULL; \ cds_lfht_next_duplicate(ht, match, key, iter), \ pos = caa_container_of(cds_lfht_iter_get_node(iter), \ __typeof__(*(pos)), member))