From: Zbigniew Jędrzejewski-Szmek Date: Fri, 12 Feb 2016 04:24:14 +0000 (-0500) Subject: basic/strv: fix strv_join for first empty argument X-Git-Tag: v231.3~251 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=6766baac570c65a49f0eed23f181af1cab52b37f basic/strv: fix strv_join for first empty argument Empty strings were ignored in strv_join, but only if they were at the beginning of the string. Empty strings after at least one non-empty item were treated normally. Previously: {"x"} → "x" {"x", ""} → "x" {"x", "", ""} → "x::" {""} → "" {"", ""} → "" {"", "", ""} → "" {"", "x"} → "x" {"", "x", ""} → "x:" Now: {"x"} → "x" {"x", ""} → "x" {"x", "", ""} → "x::" {""} → "" {"", ""} → ":" {"", "", ""} → "::" {"", "x"} → ":x" {"", "x", ""} → ":x:" --- diff --git a/src/basic/strv.c b/src/basic/strv.c index 5c8261d92..3a021003f 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -375,7 +375,7 @@ char *strv_join(char **l, const char *separator) { n = 0; STRV_FOREACH(s, l) { - if (n != 0) + if (s != l) n += k; n += strlen(*s); } @@ -386,7 +386,7 @@ char *strv_join(char **l, const char *separator) { e = r; STRV_FOREACH(s, l) { - if (e != r) + if (s != l) e = stpcpy(e, separator); e = stpcpy(e, *s);