From 11ee08e78a67bb6f5d185bbd7dbd4fbb4d963ac2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 25 Oct 2023 17:36:59 +0200 Subject: [PATCH] libnm: simplify assertions in _property_infos_sort_cmp_setting_connection() What we sort is very static, the names of properties in NMSettingConnection. We know that the list contains no two identical names. There were already assertions for that, just rework them a bit to make the code clearer. --- src/libnm-core-impl/nm-setting.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 9fc3df7743..f9329d28c8 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -250,10 +250,8 @@ _property_infos_sort_cmp_setting_connection(gconstpointer p_a, { const NMSettInfoProperty *a = *((const NMSettInfoProperty *const *) p_a); const NMSettInfoProperty *b = *((const NMSettInfoProperty *const *) p_b); - int c_name; - c_name = strcmp(a->name, b->name); - nm_assert(c_name != 0); + nm_assert(a->name && b->name && !nm_streq(a->name, b->name)); #define CMP_AND_RETURN(n_a, n_b, name) \ G_STMT_START \ @@ -266,15 +264,14 @@ _property_infos_sort_cmp_setting_connection(gconstpointer p_a, G_STMT_END /* for [connection], report first id, uuid, type in that order. */ - if (c_name != 0) { - CMP_AND_RETURN(a->name, b->name, NM_SETTING_CONNECTION_ID); - CMP_AND_RETURN(a->name, b->name, NM_SETTING_CONNECTION_UUID); - CMP_AND_RETURN(a->name, b->name, NM_SETTING_CONNECTION_TYPE); - } + CMP_AND_RETURN(a->name, b->name, NM_SETTING_CONNECTION_ID); + CMP_AND_RETURN(a->name, b->name, NM_SETTING_CONNECTION_UUID); + CMP_AND_RETURN(a->name, b->name, NM_SETTING_CONNECTION_TYPE); #undef CMP_AND_RETURN - return c_name; + NM_CMP_FIELD_STR(a, b, name); + return nm_assert_unreachable_val(0); } static const NMSettInfoProperty *const *