From 53ab539dd1168ab808f953f346c345c700152abb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Apr 2019 13:21:47 +0200 Subject: [PATCH] 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. (cherry picked from commit 720bc30bd9d9cf5aaf0995b55413a8ac6515340f) --- clients/common/nm-meta-setting-desc.c | 12 ++++++++---- 1 file 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