mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[gnc-glib-utils] gnc_g_list_stringjoin skips NULL data
This commit is contained in:
parent
0f13471438
commit
ecd2cdf425
@ -335,18 +335,25 @@ gnc_g_list_stringjoin (GList *list_of_strings, const gchar *sep)
|
||||
gint length = -seplen;
|
||||
gchar *retval, *p;
|
||||
|
||||
if (!list_of_strings)
|
||||
return NULL;
|
||||
|
||||
for (GList *n = list_of_strings; n; n = n->next)
|
||||
length += strlen ((gchar*)n->data) + seplen;
|
||||
{
|
||||
gchar *str = n->data;
|
||||
if (str && *str)
|
||||
length += strlen (str) + seplen;
|
||||
}
|
||||
|
||||
if (length <= 0)
|
||||
return NULL;
|
||||
|
||||
p = retval = (gchar*) g_malloc0 (length * sizeof (gchar) + 1);
|
||||
for (GList *n = list_of_strings; n; n = n->next)
|
||||
{
|
||||
p = g_stpcpy (p, (gchar*)n->data);
|
||||
if (n->next && sep)
|
||||
gchar *str = n->data;
|
||||
if (!str || !str[0])
|
||||
continue;
|
||||
if (sep && (p != retval))
|
||||
p = g_stpcpy (p, sep);
|
||||
p = g_stpcpy (p, str);
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -79,6 +79,11 @@ test_g_list_stringjoin (gconstpointer data)
|
||||
g_assert_cmpstr (ret, ==, "one");
|
||||
g_free (ret);
|
||||
|
||||
/* The following inserts a NULL between "two" and "one". As a
|
||||
result, the stringjoin effectively skips a step, i.e. it does
|
||||
not insert separator repeatedly between NULL strings */
|
||||
test = g_list_prepend (test, NULL);
|
||||
|
||||
test = g_list_prepend (test, "two");
|
||||
|
||||
ret = gnc_g_list_stringjoin (test, NULL);
|
||||
|
Loading…
Reference in New Issue
Block a user