diff options
author | Thomas Haller <thaller@redhat.com> | 2016-01-29 14:07:16 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-01-29 14:29:28 +0100 |
commit | 17c5e4ec654bcea00ac729886ca2ed31cc4cee5b (patch) | |
tree | e762b731570a6ab8627ad54f3166fba7e65c13b8 | |
parent | bb868770316fbc19231b3f0aaed7d7cc5c89c30f (diff) | |
download | NetworkManager-17c5e4ec654bcea00ac729886ca2ed31cc4cee5b.tar.gz |
device: don't iterate over a va_list more then once
Calling va_start() (with va_end()) in between seems to work and
is done by systemd and other code occasionally.
However, it's not clear that this really works on every architecture.
So just replace thise one instance with a different implementation
by passing the arguments as an array.
-rw-r--r-- | src/devices/nm-device.c | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 84b50451e7..d1b5c0d7dd 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -7094,25 +7094,23 @@ _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type) addrconf6_cleanup (self); } -G_GNUC_NULL_TERMINATED static gboolean -_hash_check_invalid_keys (GHashTable *hash, const char *setting_name, GError **error, ...) +_hash_check_invalid_keys_impl (GHashTable *hash, const char *setting_name, GError **error, const char **argv) { - va_list ap; - const char *key; guint found_keys = 0; + guint i; + + nm_assert (argv && argv[0]); #if NM_MORE_ASSERTS > 10 /* Assert that the keys are unique. */ { gs_unref_hashtable GHashTable *check_dups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL); - va_start (ap, error); - while ((key = va_arg (ap, const char *))) { - if (!g_hash_table_add (check_dups, (char *) key)) + for (i = 0; argv[i]; i++) { + if (!g_hash_table_add (check_dups, (char *) argv[i])) nm_assert (FALSE); } - va_end (ap); nm_assert (g_hash_table_size (check_dups) > 0); } #endif @@ -7120,12 +7118,10 @@ _hash_check_invalid_keys (GHashTable *hash, const char *setting_name, GError **e if (!hash || g_hash_table_size (hash) == 0) return TRUE; - va_start (ap, error); - while ((key = va_arg (ap, const char *))) { - if (g_hash_table_contains (hash, key)) + for (i = 0; argv[i]; i++) { + if (g_hash_table_contains (hash, argv[i])) found_keys++; } - va_end (ap); if (found_keys != g_hash_table_size (hash)) { GHashTableIter iter; @@ -7137,14 +7133,12 @@ _hash_check_invalid_keys (GHashTable *hash, const char *setting_name, GError **e g_hash_table_iter_init (&iter, hash); while (g_hash_table_iter_next (&iter, (gpointer *) &k, NULL)) { - va_start (ap, error); - while ((key = va_arg (ap, const char *))) { - if (!strcmp (key, k)) { + for (i = 0; argv[i]; i++) { + if (!strcmp (argv[i], k)) { first_invalid_key = k; break; } } - va_end (ap); if (first_invalid_key) break; } @@ -7161,6 +7155,7 @@ _hash_check_invalid_keys (GHashTable *hash, const char *setting_name, GError **e return TRUE; } +#define _hash_check_invalid_keys(hash, setting_name, error, ...) _hash_check_invalid_keys_impl (hash, setting_name, error, ((const char *[]) { __VA_ARGS__, NULL })) void nm_device_reactivate_ip4_config (NMDevice *self, @@ -7262,16 +7257,14 @@ reapply_connection (NMDevice *self, if (!_hash_check_invalid_keys (diffs, NULL, error, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP6_CONFIG_SETTING_NAME, - NM_SETTING_CONNECTION_SETTING_NAME, - NULL)) + NM_SETTING_CONNECTION_SETTING_NAME)) return FALSE; if (!_hash_check_invalid_keys (diffs ? g_hash_table_lookup (diffs, NM_SETTING_CONNECTION_SETTING_NAME) : NULL, NM_SETTING_CONNECTION_SETTING_NAME, error, NM_SETTING_CONNECTION_ZONE, - NM_SETTING_CONNECTION_METERED, - NULL)) + NM_SETTING_CONNECTION_METERED)) return FALSE; _LOGD (LOGD_DEVICE, "reapply"); |