diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2019-11-14 15:08:31 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2019-11-18 13:40:48 +0100 |
commit | 62919bab43a6aadbbed753cd486540f61f93734e (patch) | |
tree | 7efee16d92cd99262420503985b4a702cf4b7f6c /libnm-core | |
parent | e1a068e93c37dd027f37aa133fae82604905d7cb (diff) | |
download | NetworkManager-62919bab43a6aadbbed753cd486540f61f93734e.tar.gz |
utils: make nm_utils_hwaddr_matches() accept NULL
This essentially aligns the implementation with the documentation.
It is also rather useful, since it allows us to use the value returned
by nm_setting_wired_get_mac_address() directly, and that one can indeed
be NULL.
Diffstat (limited to 'libnm-core')
-rw-r--r-- | libnm-core/nm-utils.c | 17 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 10 |
2 files changed, 19 insertions, 8 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index f4e55fc05c..c825bb12ba 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4276,14 +4276,15 @@ nm_utils_hwaddr_matches (gconstpointer hwaddr1, gsize l; if (hwaddr1_len == -1) { - g_return_val_if_fail (hwaddr1 != NULL, FALSE); - - if (!hwaddr_aton (hwaddr1, buf1, sizeof (buf1), &l)) { + if (hwaddr1 == NULL) { + hwaddr1_len = 0; + } else if (hwaddr_aton (hwaddr1, buf1, sizeof (buf1), &l)) { + hwaddr1 = buf1; + hwaddr1_len = l; + } else { g_return_val_if_fail ((hwaddr2_len == -1 && hwaddr2) || (hwaddr2_len > 0 && hwaddr2_len <= NM_UTILS_HWADDR_LEN_MAX), FALSE); return FALSE; } - hwaddr1 = buf1; - hwaddr1_len = l; } else { g_return_val_if_fail (hwaddr1_len > 0 && hwaddr1_len <= NM_UTILS_HWADDR_LEN_MAX, FALSE); @@ -4294,9 +4295,9 @@ nm_utils_hwaddr_matches (gconstpointer hwaddr1, } if (hwaddr2_len == -1) { - g_return_val_if_fail (hwaddr2 != NULL, FALSE); - - if (!hwaddr_aton (hwaddr2, buf2, sizeof (buf2), &l)) + if (hwaddr2 == NULL) + l = 0; + else if (!hwaddr_aton (hwaddr2, buf2, sizeof (buf2), &l)) return FALSE; if (l != hwaddr1_len) return FALSE; diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 32e3a807d0..e91bba301d 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -3950,6 +3950,16 @@ test_hwaddr_equal (void) g_assert (nm_utils_hwaddr_matches (null_binary, sizeof (null_binary), null_string, -1)); g_assert (nm_utils_hwaddr_matches (null_binary, sizeof (null_binary), null_binary, sizeof (null_binary))); g_assert (nm_utils_hwaddr_matches (null_binary, sizeof (null_binary), NULL, ETH_ALEN)); + + g_assert (nm_utils_hwaddr_matches (NULL, -1, NULL, -1)); + g_assert (!nm_utils_hwaddr_matches (NULL, -1, string, -1)); + g_assert (!nm_utils_hwaddr_matches (string, -1, NULL, -1)); + g_assert (!nm_utils_hwaddr_matches (NULL, -1, null_string, -1)); + g_assert (!nm_utils_hwaddr_matches (null_string, -1, NULL, -1)); + g_assert (!nm_utils_hwaddr_matches (NULL, -1, binary, sizeof (binary))); + g_assert (!nm_utils_hwaddr_matches (binary, sizeof (binary), NULL, -1)); + g_assert (!nm_utils_hwaddr_matches (NULL, -1, null_binary, sizeof (null_binary))); + g_assert (!nm_utils_hwaddr_matches (null_binary, sizeof (null_binary), NULL, -1)); } static void |