From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:55512) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbw9B-0003BK-MY for qemu-devel@nongnu.org; Fri, 23 Nov 2012 11:30:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tbw95-0003Bp-QD for qemu-devel@nongnu.org; Fri, 23 Nov 2012 11:30:33 -0500 Received: from cantor2.suse.de ([195.135.220.15]:52448 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tbw95-0003Bf-HR for qemu-devel@nongnu.org; Fri, 23 Nov 2012 11:30:27 -0500 Message-ID: <50AFA4A0.1070903@suse.de> Date: Fri, 23 Nov 2012 17:30:24 +0100 From: =?ISO-8859-15?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <1353686178-27520-1-git-send-email-pbonzini@redhat.com> <1353686178-27520-2-git-send-email-pbonzini@redhat.com> <50AFA158.4020502@suse.de> <50AFA36D.7030502@redhat.com> In-Reply-To: <50AFA36D.7030502@redhat.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1.3 1/2] qom: dynamic_cast of NULL is always NULL List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: aliguori@us.ibm.com, lcapitulino@redhat.com, qemu-devel@nongnu.org, armbru@redhat.com Am 23.11.2012 17:25, schrieb Paolo Bonzini: > Il 23/11/2012 17:16, Andreas F=E4rber ha scritto: >>>> @@ -430,7 +430,7 @@ Object *object_dynamic_cast_assert(Object *obj, = const char *typename) >>>> =20 >>>> inst =3D object_dynamic_cast(obj, typename); >>>> =20 >>>> - 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. >=20 > I think it's okay to segfault in this case. >=20 > Otherwise you need to replace this simple cast+check pair: >=20 > SCSIDevice *s =3D SCSI_DEVICE(some->long.expressio[n]); > if (!s) { > return; > } >=20 > with something that is more complex: >=20 > DeviceState *d =3D some->long.expressio[n]; > SCSIDevice *s; >=20 > if (!d) { > return; > } > s =3D 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 --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg