From 17ff856bf464b9efb6b9e5ce1db2c08ca4375fe7 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 10 Dec 2017 12:20:38 +0100 Subject: [PATCH] libnm: sort attribute names in nm_ip_address_get_attribute_names() The order in which the attribute names are returns should be defined and stable. Sort them and re-use the helper functions. Sorting is good, because it gives a consistent order. Maybe we don't want to commit to this in the API, officially the order is still arbitrary. In practice, we rely on the order of attribute names when converting the attributes to a string. The same configuration should produce the same string representation. That doesn't mean we commit to a fixed order in the string representation. It does not mean, that the order must always be this way, we can still change it. But between multiple runs of the same binary, the order should be stable. Note that our hash tables are seeded with a random number. Hence, their order is not only abitrary, it is also unstable and changes for each run of the application. --- libnm-core/nm-setting-ip-config.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index 45a0ce901..b1b76256a 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -537,22 +537,12 @@ nm_ip_address_set_prefix (NMIPAddress *address, char ** nm_ip_address_get_attribute_names (NMIPAddress *address) { - GHashTableIter iter; - const char *key; - GPtrArray *names; + const char **names; - g_return_val_if_fail (address != NULL, NULL); + g_return_val_if_fail (address, NULL); - names = g_ptr_array_new (); - - if (address->attributes) { - g_hash_table_iter_init (&iter, address->attributes); - while (g_hash_table_iter_next (&iter, (gpointer *) &key, NULL)) - g_ptr_array_add (names, g_strdup (key)); - } - g_ptr_array_add (names, NULL); - - return (char **) g_ptr_array_free (names, FALSE); + names = nm_utils_strdict_get_keys (address->attributes, TRUE, NULL); + return nm_utils_strv_make_deep_copied_nonnull (names); } /**