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.
This commit is contained in:
committed by
Lennart Poettering
parent
ed2dc503da
commit
14648b762f
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user