From d686636bf043a6f02e592658cad7ef6a091003d2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Aug 2017 14:05:16 +0200 Subject: [PATCH] core: avoid compiler warning in nm_ip_config_iter_ip4_address_for_each() macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In file included from src/nm-ip6-config.c:24:0: src/nm-ip6-config.c: In function ‘nm_ip6_config_create_setting’: src/nm-ip6-config.c:734:62: error: the address of ‘address’ will always evaluate as ‘true’ [-Werror=address] nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, self, &address) { ^ src/nm-ip6-config.h:60:17: note: in definition of macro ‘nm_ip_config_iter_ip6_address_for_each’ for (({ if (address) { *(((const NMPlatformIP6Address **) address)) = NULL; } }), nm_ip_config_iter_ip6_address_init ((iter), (self)); \ ^ Fixes: 6e9aa9402a67bab563320fb0b37df242df15214c --- shared/nm-utils/nm-macros-internal.h | 15 +++++++++++++++ src/nm-ip4-config.h | 4 ++-- src/nm-ip6-config.h | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 66b4aa8d60..613e0432e1 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -687,6 +687,21 @@ nm_clear_g_cancellable (GCancellable **cancellable) /*****************************************************************************/ +/* Only useful inside a macro to avoid compiler warning. + * + * Otherwise compiler might warn for "if (ptr)" + * the address of ‘a’ will always evaluate as ‘true’ [-Werror=address] + * + * The trivial function avoids the compiler warning. + */ +static inline int +_nm_is_null (const void *ptr) +{ + return !!ptr; +} + +/*****************************************************************************/ + /* Determine whether @x is a power of two (@x being an integer type). * Basically, this returns TRUE, if @x has exactly one bit set. * For negative values and zero, this always returns FALSE. */ diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h index 4d42cee35a..b8019f3f6d 100644 --- a/src/nm-ip4-config.h +++ b/src/nm-ip4-config.h @@ -64,12 +64,12 @@ nm_ip_config_iter_ip4_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatfor } #define nm_ip_config_iter_ip4_address_for_each(iter, self, address) \ - for (({ if (address) { *((const NMPlatformIP4Address **) (address)) = NULL; } }), nm_ip_config_iter_ip4_address_init ((iter), (self)); \ + for (({ if (!_nm_is_null (address)) { *((const NMPlatformIP4Address **) (address)) = NULL; } }), nm_ip_config_iter_ip4_address_init ((iter), (self)); \ nm_ip_config_iter_ip4_address_next ((iter), (address)); \ ) #define nm_ip_config_iter_ip4_route_for_each(iter, self, route) \ - for (({ if (route) { *((const NMPlatformIP4Route **) (route)) = NULL; } }), nm_ip_config_iter_ip4_route_init ((iter), (self)); \ + for (({ if (!_nm_is_null (route)) { *((const NMPlatformIP4Route **) (route)) = NULL; } }), nm_ip_config_iter_ip4_route_init ((iter), (self)); \ nm_ip_config_iter_ip4_route_next ((iter), (route)); \ ) diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h index 9f798041a4..3b42d4960c 100644 --- a/src/nm-ip6-config.h +++ b/src/nm-ip6-config.h @@ -57,12 +57,12 @@ nm_ip_config_iter_ip6_route_next (NMDedupMultiIter *ipconf_iter, const NMPlatfor } #define nm_ip_config_iter_ip6_address_for_each(iter, self, address) \ - for (({ if (address) { *(((const NMPlatformIP6Address **) address)) = NULL; } }), nm_ip_config_iter_ip6_address_init ((iter), (self)); \ + for (({ if (!_nm_is_null (address)) { *(((const NMPlatformIP6Address **) address)) = NULL; } }), nm_ip_config_iter_ip6_address_init ((iter), (self)); \ nm_ip_config_iter_ip6_address_next ((iter), (address)); \ ) #define nm_ip_config_iter_ip6_route_for_each(iter, self, route) \ - for (({ if (route) { *((const NMPlatformIP6Route **) (route)) = NULL; } }), nm_ip_config_iter_ip6_route_init ((iter), (self)); \ + for (({ if (!_nm_is_null (route)) { *((const NMPlatformIP6Route **) (route)) = NULL; } }), nm_ip_config_iter_ip6_route_init ((iter), (self)); \ nm_ip_config_iter_ip6_route_next ((iter), (route)); \ )