From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: qemu-devel@nongnu.org,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
qemu-ppc@nongnu.org, xen-devel@lists.xenproject.org,
"Laurent Vivier" <lvivier@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Daniel Henrique Barboza" <danielhb413@gmail.com>,
virtio-fs@redhat.com, "Michael Roth" <michael.roth@amd.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
qemu-block@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
qemu-arm@nongnu.org, "Paul Durrant" <paul@xen.org>,
"Anthony Perard" <anthony.perard@citrix.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Cédric Le Goater" <clg@kaod.org>, "John Snow" <jsnow@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Gerd Hoffmann" <kraxel@redhat.com>, "Greg Kurz" <groug@kaod.org>
Subject: Re: [Virtio-fs] [PATCH 5/6] tests: add G_GNUC_PRINTF for various functions
Date: Mon, 9 Jan 2023 11:55:00 +0000 [thread overview]
Message-ID: <Y7wAlHEIafbNzsdf@redhat.com> (raw)
In-Reply-To: <27da4d93-38e6-1c40-4a60-92f3343f380f@redhat.com>
On Thu, Dec 29, 2022 at 10:34:55AM +0100, Thomas Huth wrote:
> On 19/12/2022 14.02, Daniel P. Berrangé wrote:
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> > tests/qtest/ahci-test.c | 3 +++
> > tests/qtest/arm-cpu-features.c | 1 +
> > tests/qtest/erst-test.c | 2 +-
> > tests/qtest/ide-test.c | 3 ++-
> > tests/qtest/ivshmem-test.c | 4 ++--
> > tests/qtest/libqmp.c | 2 +-
> > tests/qtest/libqos/libqos-pc.h | 6 ++++--
> > tests/qtest/libqos/libqos-spapr.h | 6 ++++--
> > tests/qtest/libqos/libqos.h | 6 ++++--
> > tests/qtest/libqos/virtio-9p.c | 1 +
> > tests/qtest/migration-helpers.h | 1 +
> > tests/qtest/rtas-test.c | 2 +-
> > tests/qtest/usb-hcd-uhci-test.c | 4 ++--
> > tests/unit/test-qmp-cmds.c | 13 +++++++++----
> > 14 files changed, 36 insertions(+), 18 deletions(-)
> ...
> > diff --git a/tests/unit/test-qmp-cmds.c b/tests/unit/test-qmp-cmds.c
> > index 2373cd64cb..6d52b4e5d8 100644
> > --- a/tests/unit/test-qmp-cmds.c
> > +++ b/tests/unit/test-qmp-cmds.c
> > @@ -138,6 +138,7 @@ void qmp___org_qemu_x_command(__org_qemu_x_EnumList *a,
> > }
> > +G_GNUC_PRINTF(2, 3)
> > static QObject *do_qmp_dispatch(bool allow_oob, const char *template, ...)
> > {
> > va_list ap;
> > @@ -160,6 +161,7 @@ static QObject *do_qmp_dispatch(bool allow_oob, const char *template, ...)
> > return ret;
> > }
> > +G_GNUC_PRINTF(3, 4)
> > static void do_qmp_dispatch_error(bool allow_oob, ErrorClass cls,
> > const char *template, ...)
> > {
> > @@ -269,7 +271,7 @@ static void test_dispatch_cmd_io(void)
> > static void test_dispatch_cmd_deprecated(void)
> > {
> > - const char *cmd = "{ 'execute': 'test-command-features1' }";
> > + #define cmd "{ 'execute': 'test-command-features1' }"
> > QDict *ret;
>
> That looks weird, why is this required?
This means that the compiler can see we're passing a constant string
into the API call a few lines lower. Without it, the compiler can't
see that 'cmd' doesn't contain any printf format specifiers, and thus
it would force us to use func('%s', cmd)... except that's not actually
possible since our crazy json printf formatter doesn't allow arbitrary
'%s', the '%s' can only occur at well defined points in the JSON doc.
Using a constant string via #define was the easiest way to give the
compiler visibility of the safety.
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2023-01-09 11:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-19 13:01 [Virtio-fs] [PATCH 0/6] enforce use of G_GNUC_PRINTF annotations Daniel P. Berrangé
2022-12-19 13:02 ` [Virtio-fs] [PATCH 1/6] disas: add G_GNUC_PRINTF to gstring_printf Daniel P. Berrangé
2022-12-19 20:43 ` Stefan Weil
2022-12-19 13:02 ` [Virtio-fs] [PATCH 2/6] hw/xen: use G_GNUC_PRINTF/SCANF for various functions Daniel P. Berrangé
2022-12-19 14:10 ` Anthony PERARD
2022-12-19 13:02 ` [Virtio-fs] [PATCH 3/6] tools/virtiofsd: add G_GNUC_PRINTF for logging functions Daniel P. Berrangé
2023-01-04 19:46 ` Dr. David Alan Gilbert
2022-12-19 13:02 ` [Virtio-fs] [PATCH 4/6] util/error: add G_GNUC_PRINTF for various functions Daniel P. Berrangé
2022-12-19 14:13 ` Philippe Mathieu-Daudé
2022-12-29 9:29 ` Thomas Huth
2022-12-19 13:02 ` [Virtio-fs] [PATCH 5/6] tests: " Daniel P. Berrangé
2022-12-29 9:34 ` Thomas Huth
2023-01-09 11:55 ` Daniel P. Berrangé [this message]
2022-12-19 13:02 ` [Virtio-fs] [PATCH 6/6] enforce use of G_GNUC_PRINTF attributes Daniel P. Berrangé
2022-12-22 8:31 ` [Virtio-fs] [PATCH 0/6] enforce use of G_GNUC_PRINTF annotations Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7wAlHEIafbNzsdf@redhat.com \
--to=berrange@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=anthony.perard@citrix.com \
--cc=armbru@redhat.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--cc=david@gibson.dropbear.id.au \
--cc=dgilbert@redhat.com \
--cc=groug@kaod.org \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=michael.roth@amd.com \
--cc=paul@xen.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=sstabellini@kernel.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
--cc=virtio-fs@redhat.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).