summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-09-23 12:24:56 +0200
committerThomas Haller <thaller@redhat.com>2020-09-23 13:57:38 +0200
commit2fdc713e929fa43a390af6ec43ea1d3223e0b60a (patch)
treec2db7f37f93be0131455f11cd6be77058d2baeb4
parent2d360d8293ffe72b656865ef643bec77b84546f0 (diff)
downloadNetworkManager-2fdc713e929fa43a390af6ec43ea1d3223e0b60a.tar.gz
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.
-rw-r--r--libnm-core/nm-utils.c14
1 files 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
* <literal>ARPHRD_ETHER</literal> or <literal>ARPHRD_INFINIBAND</literal>.
*
- * 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;
+ }
}
/**