From: "Andreas Färber" <afaerber@suse.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: aliguori@us.ibm.com, lcapitulino@redhat.com,
qemu-devel@nongnu.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1.3 1/2] qom: dynamic_cast of NULL is always NULL
Date: Fri, 23 Nov 2012 17:30:24 +0100 [thread overview]
Message-ID: <50AFA4A0.1070903@suse.de> (raw)
In-Reply-To: <50AFA36D.7030502@redhat.com>
Am 23.11.2012 17:25, schrieb Paolo Bonzini:
> Il 23/11/2012 17:16, Andreas Färber ha scritto:
>>>> @@ -430,7 +430,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename)
>>>>
>>>> inst = object_dynamic_cast(obj, typename);
>>>>
>>>> - if (!inst) {
>>>> + if (!inst && obj) {
>>>> fprintf(stderr, "Object %p is not an instance of type %s\n",
>>>> obj, typename);
>>>> abort();
>> This is followed by return inst;
>>
>> Since this function clearly has assert in the name I don't think this is
>> right. I would expect %p to print 0x0 and the function to abort.
>
> I think it's okay to segfault in this case.
>
> Otherwise you need to replace this simple cast+check pair:
>
> SCSIDevice *s = SCSI_DEVICE(some->long.expressio[n]);
> if (!s) {
> return;
> }
>
> with something that is more complex:
>
> DeviceState *d = some->long.expressio[n];
> SCSIDevice *s;
>
> if (!d) {
> return;
> }
> s = SCSI_DEVICE(d);
Right now our use of those macros guarantees that the result is never
NULL, so there are no such checks! That expectation is broken by your
patch - I'm guessing without reviewing all derived macros.
If having SCSI_BUS() return NULL was your intent you would not have
needed to switch to object_dynamic_cast in your second patch. :)
But let's leave it for Anthony to decide how he wants his macros to work. ;)
Andreas
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
next prev parent reply other threads:[~2012-11-23 16:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-23 15:56 [Qemu-devel] [PATCH 1.3 0/2] "drive_add NN if=scsi" fixes Paolo Bonzini
2012-11-23 15:56 ` [Qemu-devel] [PATCH 1.3 1/2] qom: dynamic_cast of NULL is always NULL Paolo Bonzini
2012-11-23 16:16 ` Andreas Färber
2012-11-23 16:25 ` Paolo Bonzini
2012-11-23 16:30 ` Andreas Färber [this message]
2012-11-23 16:51 ` Paolo Bonzini
2012-11-23 15:56 ` [Qemu-devel] [PATCH 1.3 2/2] hmp: do not crash on invalid SCSI hotplug Paolo Bonzini
2012-11-26 12:50 ` Luiz Capitulino
2012-11-26 21:48 ` [Qemu-devel] [PATCH 1.3 0/2] "drive_add NN if=scsi" fixes Anthony Liguori
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=50AFA4A0.1070903@suse.de \
--to=afaerber@suse.de \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.com \
--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).