From 2fdc713e929fa43a390af6ec43ea1d3223e0b60a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 23 Sep 2020 12:24:56 +0200 Subject: [PATCH] libnm: relax asserting argument for nm_utils_hwaddr_len() nm_utils_hwaddr_len() isn't very useful. It's documented to only accept two possible input values (ARPHRD_ETHER and ARPHRD_INFINIBAND) for which the respective return values are well known. In particular, asserting that the input value is one of the two values means it becomes harder to extend the function (and make it more useful). Because, then the user would need to call: #if NM_VERSION > NM_VERSION_1_XX len = nm_utils_hwaddr_len (ARPHDR_FOO); #else len = 0 #endif and then it would introduce an unnecessary run time dependency on NM_VERSION_1_XX. Instead, just document to return 0 if the value is not supported. --- libnm-core/nm-utils.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 534e7bac31..58ec444c39 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4001,20 +4001,22 @@ nm_utils_wifi_strength_bars (guint8 strength) * * Returns the length in octets of a hardware address of type @type. * - * It is an error to call this function with any value other than + * Before 1.28, it was an error to call this function with any value other than * ARPHRD_ETHER or ARPHRD_INFINIBAND. * - * Return value: the length. + * Return value: the length or zero if the type is unrecognized. */ gsize nm_utils_hwaddr_len (int type) { - if (type == ARPHRD_ETHER) + switch (type) { + case ARPHRD_ETHER: return ETH_ALEN; - else if (type == ARPHRD_INFINIBAND) + case ARPHRD_INFINIBAND: return INFINIBAND_ALEN; - - g_return_val_if_reached (0); + default: + return 0; + } } /**