diff --git a/shared/nm-keyfile/nm-keyfile-utils.c b/shared/nm-keyfile/nm-keyfile-utils.c index 627f529978..751ff23e4b 100644 --- a/shared/nm-keyfile/nm-keyfile-utils.c +++ b/shared/nm-keyfile/nm-keyfile-utils.c @@ -150,9 +150,29 @@ fcn_name (GKeyFile *kf, \ key_file_set_fcn (kf, alias ?: group, key, list, length); \ } -DEFINE_KF_LIST_WRAPPER_SET (nm_keyfile_plugin_kf_set_integer_list, int *, g_key_file_set_integer_list); DEFINE_KF_LIST_WRAPPER_SET (nm_keyfile_plugin_kf_set_string_list, const char*const*, g_key_file_set_string_list); +void +nm_keyfile_plugin_kf_set_integer_list_uint (GKeyFile *kf, + const char *group, + const char *key, + const guint *data, + gsize length) +{ + nm_auto_str_buf NMStrBuf strbuf = { }; + gsize i; + + g_return_if_fail (kf); + g_return_if_fail (!length || data); + g_return_if_fail (group && group[0]); + g_return_if_fail (key && key[0]); + + nm_str_buf_init (&strbuf, length * 4u + 2u, FALSE); + for (i = 0; i < length; i++) + nm_str_buf_append_printf (&strbuf, "%u;", data[i]); + nm_keyfile_plugin_kf_set_value (kf, group, key, nm_str_buf_get_str (&strbuf)); +} + void nm_keyfile_plugin_kf_set_integer_list_uint8 (GKeyFile *kf, const char *group, diff --git a/shared/nm-keyfile/nm-keyfile-utils.h b/shared/nm-keyfile/nm-keyfile-utils.h index 719c32c2fc..ab9f44dc7f 100644 --- a/shared/nm-keyfile/nm-keyfile-utils.h +++ b/shared/nm-keyfile/nm-keyfile-utils.h @@ -26,7 +26,7 @@ gboolean nm_keyfile_plugin_kf_get_boolean (GKeyFile *kf, const char *group, char *nm_keyfile_plugin_kf_get_value (GKeyFile *kf, const char *group, const char *key, GError **error); void nm_keyfile_plugin_kf_set_integer_list_uint8 (GKeyFile *kf, const char *group, const char *key, const guint8 *list, gsize length); -void nm_keyfile_plugin_kf_set_integer_list (GKeyFile *kf, const char *group, const char *key, int *list, gsize length); +void nm_keyfile_plugin_kf_set_integer_list_uint (GKeyFile *kf, const char *group, const char *key, const guint *list, gsize length); void nm_keyfile_plugin_kf_set_string_list (GKeyFile *kf, const char *group, const char *key, const char *const*list, gsize length); void nm_keyfile_plugin_kf_set_string (GKeyFile *kf, const char *group, const char *key, const char *value); diff --git a/shared/nm-keyfile/nm-keyfile.c b/shared/nm-keyfile/nm-keyfile.c index 879b1b004f..474377bfcf 100644 --- a/shared/nm-keyfile/nm-keyfile.c +++ b/shared/nm-keyfile/nm-keyfile.c @@ -1851,25 +1851,19 @@ write_array_of_uint (GKeyFile *file, const GValue *value) { GArray *array; - guint i; - gs_free int *tmp_array = NULL; - array = (GArray *) g_value_get_boxed (value); + array = g_value_get_boxed (value); + + nm_assert (!array || g_array_get_element_size (array) == sizeof (guint)); + if (!array || !array->len) return; - g_return_if_fail (g_array_get_element_size (array) == sizeof (guint)); - - tmp_array = g_new (int, array->len); - for (i = 0; i < array->len; i++) { - guint v = g_array_index (array, guint, i); - - if (v > G_MAXINT) - g_return_if_reached (); - tmp_array[i] = (int) v; - } - - nm_keyfile_plugin_kf_set_integer_list (file, nm_setting_get_name (setting), key, tmp_array, array->len); + nm_keyfile_plugin_kf_set_integer_list_uint (file, + nm_setting_get_name (setting), + key, + (const guint *) array->data, + array->len); } static void