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 12:27:43 +0200
commit94a2b442556ef7d00e2a3037e3ec722bdba2a53d (patch)
treef902a7e29a4ac0ab2bfb61b6f4b3dc791ab064aa
parent665b5ce6da9f7f8bbb0c904a88b5369c56563923 (diff)
downloadNetworkManager-th/hwaddr-cleanup.tar.gz
libnm: relax asserting argument for nm_utils_hwaddr_len()th/hwaddr-cleanup
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..cef629ae1d 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 zeor 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;
+ }
}
/**