From: Zbigniew Jędrzejewski-Szmek Date: Sun, 10 Feb 2019 17:31:54 +0000 (+0100) Subject: test-json: do not pass ephemeral array as intializer to JSON_BUILD_STRV X-Git-Tag: v241~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=14648b762f90b72a356e745cee3435531203704a;p=platform%2Fupstream%2Fsystemd.git test-json: do not pass ephemeral array as intializer to JSON_BUILD_STRV Fixes #11600. The code was effectively doing: json_build(..., ({ char **_x = ((char**) ((const char*[]) {"one", "two", "three", "four", NULL })); _x; })); but there was no guarantee that the storage for the array that _x points to survives pass the end of the block. Essentially, STRV_MAKE cannot be used inline inside of a block like this. --- diff --git a/src/test/test-json.c b/src/test/test-json.c index 9a9b01a..fdf1b4f 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -282,6 +282,7 @@ static void test_build(void) { a = json_variant_unref(a); b = json_variant_unref(b); + const char* arr_1234[] = {"one", "two", "three", "four", NULL}; assert_se(json_build(&a, JSON_BUILD_ARRAY(JSON_BUILD_OBJECT(JSON_BUILD_PAIR("x", JSON_BUILD_BOOLEAN(true)), JSON_BUILD_PAIR("y", JSON_BUILD_OBJECT(JSON_BUILD_PAIR("this", JSON_BUILD_NULL)))), JSON_BUILD_VARIANT(NULL), @@ -289,8 +290,9 @@ static void test_build(void) { JSON_BUILD_STRING(NULL), JSON_BUILD_NULL, JSON_BUILD_INTEGER(77), - JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")), JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))), - JSON_BUILD_STRV(STRV_MAKE("one", "two", "three", "four")))) >= 0); + JSON_BUILD_ARRAY(JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("foobar")), + JSON_BUILD_VARIANT(JSON_VARIANT_STRING_CONST("zzz"))), + JSON_BUILD_STRV((char**) arr_1234))) >= 0); assert_se(json_variant_format(a, 0, &s) >= 0); log_info("GOT: %s\n", s);