atomics: Use type of destination in CAS implementation
authorTobias Brunner <tobias@strongswan.org>
Fri, 22 Jun 2018 08:25:25 +0000 (10:25 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 3 Jul 2018 09:31:31 +0000 (11:31 +0200)
The type of the value was incorrect (void**) if NULL was passed to cas_ptr()
as expected value, which caused a compiler warning with Clang because
__atomic_compare_exchange_n() expects the types of the first two arguments
to be the same.

src/libstrongswan/utils/utils/atomics.h

index 4b530eb..c23b361 100644 (file)
@@ -53,7 +53,7 @@ typedef u_int refcount_t;
 #define ref_put(ref) (!__atomic_sub_fetch(ref, 1, __ATOMIC_ACQ_REL))
 #define ref_cur(ref) __atomic_load_n(ref, __ATOMIC_RELAXED)
 
-#define _cas_impl(ptr, oldval, newval) ({ typeof(oldval) _old = oldval; \
+#define _cas_impl(ptr, oldval, newval) ({ typeof(*ptr) _old = oldval; \
                        __atomic_compare_exchange_n(ptr, &_old, newval, FALSE, \
                                                                                __ATOMIC_SEQ_CST, __ATOMIC_RELAXED); })
 #define cas_bool(ptr, oldval, newval) _cas_impl(ptr, oldval, newval)