basic/strv: add an extra NUL after strings in strv_make_nulstr

strv_make_nulstr was creating a nulstr which was not a valid nulstr,
because it was missing the terminating NUL. This didn't cause any issues,
because strv_parse_nulstr correctly parsed the result, using the
separately specified length.

But it's confusing to have something called nulstr which really isn't.
It is likely that somebody will try to use strv_make_nulstr() in
some other place, incorrectly.

This patch changes strv_parse_nulstr() to produce a valid nulstr, and
changes the output length parameter to be the minimum number of bytes
which can be later on parsed by strv_parse_nulstr(). This allows the
only user in ask-password-api to be slightly simplified.

Based-on-patch-by: Jean-Sébastien Bour <jean-sebastien@bour.name>

Fixes #3689.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2016-07-17 15:34:57 -04:00
parent f41794d036
commit b60df13b39
3 changed files with 27 additions and 11 deletions
+1 -2
View File
@@ -659,9 +659,8 @@ static void test_strv_make_nulstr_one(char **l) {
assert_se(m == n);
assert_se(memcmp(b, c, m) == 0);
NULSTR_FOREACH(s, b) {
NULSTR_FOREACH(s, b)
assert_se(streq(s, l[i++]));
}
assert_se(i == strv_length(l));
}