From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: afaerber@suse.de, Anthony Liguori <anthony@codemonkey.ws>
Subject: [Qemu-devel] [PATCH v2 2/2] qom: Fix invalid error check in property_get_str()
Date: Tue, 25 Aug 2015 20:00:46 +0200 [thread overview]
Message-ID: <1440525646-22428-3-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1440525646-22428-1-git-send-email-armbru@redhat.com>
When a function returns a null pointer on error and only on error, you
can do
if (!foo(foos, errp)) {
... handle error ...
}
instead of the more cumbersome
Error *err = NULL;
if (!foo(foos, &err)) {
error_propagate(errp, err);
... handle error ...
}
A StringProperty's getter, however, may return null on success! We
then fail to call visit_type_str().
Screwed up in 6a146eb, v1.1.
Fails tests/qom-test in my current, heavily hacked QAPI branch. No
reproducer for master known (but I didn't look hard).
Cc: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
qom/object.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/qom/object.c b/qom/object.c
index 6173da8..4c4df55 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -1591,14 +1591,18 @@ typedef struct StringProperty
static void property_get_str(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
+ Error *err = NULL;
StringProperty *prop = opaque;
char *value;
- value = prop->get(obj, errp);
- if (value) {
- visit_type_str(v, &value, name, errp);
- g_free(value);
+ value = prop->get(obj, &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
}
+
+ visit_type_str(v, &value, name, errp);
+ g_free(value);
}
static void property_set_str(Object *obj, Visitor *v, void *opaque,
--
2.4.3
next prev parent reply other threads:[~2015-08-25 18:00 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-25 18:00 [Qemu-devel] [PATCH v2 0/2] qom: Fix misuse of Error API Markus Armbruster
2015-08-25 18:00 ` [Qemu-devel] [PATCH v2 1/2] qom: Do not reuse errp after a possible error Markus Armbruster
2015-08-25 18:00 ` Markus Armbruster [this message]
2015-09-03 10:06 ` [Qemu-devel] [PATCH v2 0/2] qom: Fix misuse of Error API Markus Armbruster
2015-09-03 14:34 ` Eric Blake
2015-09-03 16:15 ` Markus Armbruster
2015-09-06 18:55 ` Andreas Färber
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=1440525646-22428-3-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=afaerber@suse.de \
--cc=anthony@codemonkey.ws \
--cc=qemu-devel@nongnu.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 NNTP newsgroup(s).