From 8022ed3ab25b84ec0c905e2af6960ecfe0974551 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 21 Sep 2017 13:13:27 +0200 Subject: [PATCH] core: avoid maybe-uninitialized compiler warning with nmp_cache_iter_for_each() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CC src/devices/src_libNetworkManager_la-nm-device.lo In file included from src/devices/nm-device.c:45:0: src/devices/nm-device.c: In function ‘_v4_has_shadowed_routes_detect’: ./src/platform/nmp-object.h:400:54: error: ‘o’ may be used uninitialized in this function [-Werror=maybe-uninitialized] _obj ? &_NM_CONSTCAST (NMPObject, _obj)->ip4_route : NULL; \ ^ src/devices/nm-device.c:2774:19: note: ‘o’ was declared here const NMPObject *o; ^ --- src/platform/nmp-object.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 6aeb1fb1b0..c2310eb971 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -564,10 +564,9 @@ nmp_cache_iter_next (NMDedupMultiIter *iter, const NMPObject **out_obj) gboolean has_next; has_next = nm_dedup_multi_iter_next (iter); - if (has_next) { - nm_assert (NMP_OBJECT_IS_VALID (iter->current->obj)); - NM_SET_OUT (out_obj, iter->current->obj); - } + nm_assert (!has_next || NMP_OBJECT_IS_VALID (iter->current->obj)); + if (out_obj) + *out_obj = has_next ? iter->current->obj : NULL; return has_next; } @@ -577,10 +576,9 @@ nmp_cache_iter_next_link (NMDedupMultiIter *iter, const NMPlatformLink **out_obj gboolean has_next; has_next = nm_dedup_multi_iter_next (iter); - if (has_next) { - nm_assert (NMP_OBJECT_GET_TYPE (iter->current->obj) == NMP_OBJECT_TYPE_LINK); - NM_SET_OUT (out_obj, &(((const NMPObject *) iter->current->obj)->link)); - } + nm_assert (!has_next || NMP_OBJECT_GET_TYPE (iter->current->obj) == NMP_OBJECT_TYPE_LINK); + if (out_obj) + *out_obj = has_next ? &(((const NMPObject *) iter->current->obj)->link) : NULL; return has_next; }