From 6f189da7b6b240bd9e01eebb8b461b2187fb80df Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 22 Feb 2020 12:07:01 +0100 Subject: [PATCH] platform: avoid compiler warning in _NMP_OBJECT_TYPE_IS_OBJ_WITH_IFINDEX() Surisingly, the compiler may detect the remaining obj_type in the default switch. Then, inlining nmp_class_from_type() it may detect that this is only possible to hit with an out or range access to _nmp_classes array. Rework the code to avoid that compiler warning. It's either way not supposed to happen. Also, drop the default switch case and explicitly list the enum values. Otherwise it is error prone to forget a switch case. (cherry picked from commit 9848589fbf89b890946cbda4d0a95b38ad53d1f0) --- src/platform/nmp-object.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index d52cc132d2..0c0796c31b 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -496,10 +496,16 @@ _NMP_OBJECT_TYPE_IS_OBJ_WITH_IFINDEX (NMPObjectType obj_type) case NMP_OBJECT_TYPE_LNK_VXLAN: case NMP_OBJECT_TYPE_LNK_WIREGUARD: return TRUE; - default: - nm_assert (nmp_class_from_type (obj_type)); + + case NMP_OBJECT_TYPE_ROUTING_RULE: return FALSE; + + case NMP_OBJECT_TYPE_UNKNOWN: + case __NMP_OBJECT_TYPE_LAST: + break; } + nm_assert_not_reached (); + return FALSE; } #define NMP_OBJECT_CAST_OBJECT(obj) \