summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-04-12 13:21:47 +0200
committerThomas Haller <thaller@redhat.com>2019-04-17 11:09:28 +0200
commit720bc30bd9d9cf5aaf0995b55413a8ac6515340f (patch)
tree81a3e3fdd15ea8807b15298e377eafc846704837
parentf4afb38bd90f2d96d5f8f4e60d50d7d65d24cbbe (diff)
downloadNetworkManager-720bc30bd9d9cf5aaf0995b55413a8ac6515340f.tar.gz
cli: avoid duplicate delimiters when printing objlist property
Usually, obj_to_str_fcn() should not fail and always add something. If not, remove the delimiter again.
-rw-r--r--clients/common/nm-meta-setting-desc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/clients/common/nm-meta-setting-desc.c b/clients/common/nm-meta-setting-desc.c
index 1de51dc191..83959ec653 100644
--- a/clients/common/nm-meta-setting-desc.c
+++ b/clients/common/nm-meta-setting-desc.c
@@ -3053,9 +3053,7 @@ _get_fcn_objlist (ARGS_GET_FCN)
num = property_info->property_typ_data->subtype.objlist.get_num_fcn (setting);
for (idx = 0; idx < num; idx++) {
-#if NM_MORE_ASSERTS
gsize start_offset;
-#endif
if (!str)
str = g_string_new (NULL);
@@ -3067,15 +3065,21 @@ _get_fcn_objlist (ARGS_GET_FCN)
g_string_append (str, ", ");
}
-#if NM_MORE_ASSERTS
start_offset = str->len;
-#endif
property_info->property_typ_data->subtype.objlist.obj_to_str_fcn (get_type,
setting,
idx,
str);
+ if (start_offset == str->len) {
+ /* nothing was appended. Remove the delimiter again. */
+ nm_assert_not_reached ();
+ if (str->len > 0)
+ g_string_truncate (str, str->len - 2);
+ continue;
+ }
+
#if NM_MORE_ASSERTS
nm_assert (start_offset < str->len);
if ( property_info->property_typ_data->subtype.objlist.strsplit_with_escape