qemu-devel
[Top][All Lists]
Advanced

[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>

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]