test-qobject-input-visitor: Avoid format string ambiguity

When visitor_input_test_init_internal()'s argument @ap is null, then
@json_string is interpreted literally, else it's gets %-escapes
interpolated.  This is awkward.

One caller always passes null @ap, and the others never do.  Lift the
building of the QObject into the callers, where it can be done without
such ambiguity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20180806065344.7103-10-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2018-08-06 08:53:30 +02:00
parent 69f0cb661a
commit eac78bd430
1 changed files with 10 additions and 9 deletions

View File

@ -47,15 +47,13 @@ static void visitor_input_teardown(TestInputVisitorData *data,
/* The various test_init functions are provided instead of a test setup /* The various test_init functions are provided instead of a test setup
function so that the JSON string used by the tests are kept in the test function so that the JSON string used by the tests are kept in the test
functions (and not in main()). */ functions (and not in main()). */
static Visitor *visitor_input_test_init_internal(TestInputVisitorData *data,
bool keyval, static Visitor *test_init_internal(TestInputVisitorData *data, bool keyval,
const char *json_string, QObject *obj)
va_list *ap)
{ {
visitor_input_teardown(data, NULL); visitor_input_teardown(data, NULL);
data->obj = qobject_from_jsonv(json_string, ap, &error_abort); data->obj = obj;
g_assert(data->obj);
if (keyval) { if (keyval) {
data->qiv = qobject_input_visitor_new_keyval(data->obj); data->qiv = qobject_input_visitor_new_keyval(data->obj);
@ -75,7 +73,8 @@ Visitor *visitor_input_test_init_full(TestInputVisitorData *data,
va_list ap; va_list ap;
va_start(ap, json_string); va_start(ap, json_string);
v = visitor_input_test_init_internal(data, keyval, json_string, &ap); v = test_init_internal(data, keyval,
qobject_from_vjsonf_nofail(json_string, ap));
va_end(ap); va_end(ap);
return v; return v;
} }
@ -88,7 +87,8 @@ Visitor *visitor_input_test_init(TestInputVisitorData *data,
va_list ap; va_list ap;
va_start(ap, json_string); va_start(ap, json_string);
v = visitor_input_test_init_internal(data, false, json_string, &ap); v = test_init_internal(data, false,
qobject_from_vjsonf_nofail(json_string, ap));
va_end(ap); va_end(ap);
return v; return v;
} }
@ -103,7 +103,8 @@ Visitor *visitor_input_test_init(TestInputVisitorData *data,
static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data, static Visitor *visitor_input_test_init_raw(TestInputVisitorData *data,
const char *json_string) const char *json_string)
{ {
return visitor_input_test_init_internal(data, false, json_string, NULL); return test_init_internal(data, false,
qobject_from_json(json_string, &error_abort));
} }
static void test_visitor_in_int(TestInputVisitorData *data, static void test_visitor_in_int(TestInputVisitorData *data,