From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:52058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbvcM-0004ox-Jp for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:56:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TbvcG-0000n2-2P for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:56:38 -0500 Received: from mail-ie0-f173.google.com ([209.85.223.173]:56771) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TbvcF-0000me-U5 for qemu-devel@nongnu.org; Fri, 23 Nov 2012 10:56:31 -0500 Received: by mail-ie0-f173.google.com with SMTP id e13so3265827iej.4 for ; Fri, 23 Nov 2012 07:56:31 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 23 Nov 2012 16:56:17 +0100 Message-Id: <1353686178-27520-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1353686178-27520-1-git-send-email-pbonzini@redhat.com> References: <1353686178-27520-1-git-send-email-pbonzini@redhat.com> Subject: [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: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, armbru@redhat.com, lcapitulino@redhat.com Trying to cast a NULL value will cause a crash. Returning NULL is also sensible, and it is also what the type-unsafe DO_UPCAST macro does. Reported-by: Markus Armbruster Signed-off-by: Paolo Bonzini --- qom/object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/qom/object.c b/qom/object.c index d7092b0..2e18c9a 100644 --- a/qom/object.c +++ b/qom/object.c @@ -417,7 +417,7 @@ void object_delete(Object *obj) Object *object_dynamic_cast(Object *obj, const char *typename) { - if (object_class_dynamic_cast(object_get_class(obj), typename)) { + if (obj && object_class_dynamic_cast(object_get_class(obj), typename)) { return obj; } @@ -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(); -- 1.8.0