[systemd-devel] [PATCH] util: allow strappenda to take any number of args

Lennart Poettering lennart at poettering.net
Wed Aug 13 16:28:15 PDT 2014


On Wed, 13.08.14 16:35, Dave Reisner (dreisner at archlinux.org) wrote:

Looks good. The code is certainly not any more complicated than the
current strapenda3(), so it sounds like something to apply.

>                  /* If the passed init is actually the same as the
>                   * systemd binary, then let's suppress it. */
> diff --git a/src/test/test-util.c b/src/test/test-util.c
> index 16f89b4..8776899 100644
> --- a/src/test/test-util.c
> +++ b/src/test/test-util.c
> @@ -907,6 +907,12 @@ static void test_strshorten(void) {
>          assert_se(strlen(strshorten(s, 0)) == 0);
>  }
>  
> +static void test_strappenda(void) {
> +        assert_se(streq(strappenda("", "foo", "bar"), "foobar"));
> +        assert_se(streq(strappenda("foo", "bar", "baz"), "foobarbaz"));
> +        assert_se(streq(strappenda("foo", "", "bar", "baz"), "foobarbaz"));
> +}

it's not portable to avoid alloca() when invoking a function (which the
strlen() in streq() is). This is documented in the alloca(3) man page,
see section "BUGS".

Can you change the test to first place the result of strappenda() in a
variable, and then pass that on to streq()? 

Please commit then! 

Thanks!

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list