[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v3 05/12] tests: Clean up string interpolation i
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH v3 05/12] tests: Clean up string interpolation into QMP input (simple cases) |
Date: |
Fri, 28 Jul 2017 13:32:42 +0100 |
User-agent: |
Mutt/1.8.3 (2017-05-23) |
On Tue, Jul 25, 2017 at 04:15:16PM -0500, Eric Blake wrote:
> From: Markus Armbruster <address@hidden>
>
> When you build QMP input manually like this
>
> cmd = g_strdup_printf("{ 'execute': 'migrate',"
> "'arguments': { 'uri': '%s' } }",
> uri);
> rsp = qmp(cmd);
> g_free(cmd);
>
> you're responsible for escaping the interpolated values for JSON. Not
> done here, and therefore works only for sufficiently nice @uri. For
> instance, if @uri contained a single "'", qobject_from_jsonv() would
> fail, qmp_fd_sendv() would misinterpret the failure as empty input and
> do nothing, and the test would hang waiting for a response that never
> comes.
>
> Leaving interpolation into JSON to qmp() is more robust:
>
> rsp = qmp("{ 'execute': 'migrate', 'arguments': { 'uri': %s } }", uri);
>
> It's also more concise.
>
> Clean up the simple cases where we interpolate exactly a JSON value.
>
> Bonus: gets rid of non-literal format strings. A step towards
> compile-time format string checking without triggering
> -Wformat-nonliteral.
>
> Signed-off-by: Markus Armbruster <address@hidden>
> Message-Id: <address@hidden>
> Signed-off-by: Eric Blake <address@hidden>
> ---
> tests/libqos/libqos.c | 16 +----
> tests/libqos/pci-pc.c | 9 +--
> tests/postcopy-test.c | 8 +--
> tests/test-qga.c | 160
> +++++++++++++++++++++---------------------------
> tests/vhost-user-test.c | 6 +-
> 5 files changed, 77 insertions(+), 122 deletions(-)
Reviewed-by: Stefan Hajnoczi <address@hidden>
signature.asc
Description: PGP signature
- Re: [Qemu-devel] [PATCH v3 01/12] qobject: Accept "%"PRId64 in qobject_from_jsonf(), (continued)
- [Qemu-devel] [PATCH v3 02/12] qtest: Avoid passing raw strings through hmp(), Eric Blake, 2017/07/25
- [Qemu-devel] [PATCH v3 03/12] qtest: Document calling conventions, Eric Blake, 2017/07/25
- [Qemu-devel] [PATCH v3 05/12] tests: Clean up string interpolation into QMP input (simple cases), Eric Blake, 2017/07/25
- Re: [Qemu-devel] [PATCH v3 05/12] tests: Clean up string interpolation into QMP input (simple cases),
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH v3 06/12] tests/libqos/usb: Clean up string interpolation into QMP input, Eric Blake, 2017/07/25
- [Qemu-devel] [PATCH v3 04/12] tests: Pass literal format strings directly to qmp_FOO(), Eric Blake, 2017/07/25
- [Qemu-devel] [PATCH v3 07/12] qtest: Add a new helper qmp_cmd() and friends, Eric Blake, 2017/07/25