summaryrefslogtreecommitdiffstats
path: root/tests/check-qjson.c
diff options
context:
space:
mode:
authorMarkus Armbruster2018-08-23 18:40:14 +0200
committerMarkus Armbruster2018-08-24 20:26:37 +0200
commitdd98e8481992741a6b5ec0bdfcee05c1c8f602d6 (patch)
tree8d75ba8eb3fa29da29bb243efff2fc65488add72 /tests/check-qjson.c
parentjson: Assert json_parser_parse() consumes all tokens on success (diff)
downloadqemu-dd98e8481992741a6b5ec0bdfcee05c1c8f602d6.tar.gz
qemu-dd98e8481992741a6b5ec0bdfcee05c1c8f602d6.tar.xz
qemu-dd98e8481992741a6b5ec0bdfcee05c1c8f602d6.zip
qjson: Have qobject_from_json() & friends reject empty and blank
The last case where qobject_from_json() & friends return null without setting an error is empty or blank input. Callers: * block.c's parse_json_protocol() reports "Could not parse the JSON options". It's marked as a work-around, because it also covered actual bugs, but they got fixed in the previous few commits. * qobject_input_visitor_new_str() reports "JSON parse error". Also marked as work-around. The recent fixes have made this unreachable, because it currently gets called only for input starting with '{'. * check-qjson.c's empty_input() and blank_input() demonstrate the behavior. * The other callers are not affected since they only pass input with exactly one JSON value or, in the case of negative tests, one error. Fail with "Expecting a JSON value" instead of returning null, and simplify callers. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20180823164025.12553-48-armbru@redhat.com>
Diffstat (limited to 'tests/check-qjson.c')
-rw-r--r--tests/check-qjson.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/tests/check-qjson.c b/tests/check-qjson.c
index 0ca4b3c823..936258ddd4 100644
--- a/tests/check-qjson.c
+++ b/tests/check-qjson.c
@@ -1291,13 +1291,21 @@ static void simple_interpolation(void)
static void empty_input(void)
{
- QObject *obj = qobject_from_json("", &error_abort);
+ Error *err = NULL;
+ QObject *obj;
+
+ obj = qobject_from_json("", &err);
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}
static void blank_input(void)
{
- QObject *obj = qobject_from_json("\n ", &error_abort);
+ Error *err = NULL;
+ QObject *obj;
+
+ obj = qobject_from_json("\n ", &err);
+ error_free_or_abort(&err);
g_assert(obj == NULL);
}