From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39919) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamFq-0003j0-CW for qemu-devel@nongnu.org; Fri, 10 May 2013 08:16:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UamFp-0007j7-A6 for qemu-devel@nongnu.org; Fri, 10 May 2013 08:16:54 -0400 Received: from mail-wi0-x22f.google.com ([2a00:1450:400c:c05::22f]:52083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UamFp-0007iw-4a for qemu-devel@nongnu.org; Fri, 10 May 2013 08:16:53 -0400 Received: by mail-wi0-f175.google.com with SMTP id h11so558958wiv.8 for ; Fri, 10 May 2013 05:16:52 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 10 May 2013 14:16:36 +0200 Message-Id: <1368188203-3407-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1368188203-3407-1-git-send-email-pbonzini@redhat.com> References: <1368188203-3407-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH for-1.5 2/9] qom: allow casting of a NULL class List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Anthony Liguori , Andreas Faerber , Aurelien Jarno , mst@redhat.com This mimics what we do in object_dynamic_cast_assert. Signed-off-by: Paolo Bonzini --- qom/object.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index 75e6aac..35f4694 100644 --- a/qom/object.c +++ b/qom/object.c @@ -449,10 +449,16 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename) ObjectClass *object_class_dynamic_cast(ObjectClass *class, const char *typename) { - TypeImpl *target_type = type_get_by_name(typename); - TypeImpl *type = class->type; ObjectClass *ret = NULL; + TypeImpl *target_type; + TypeImpl *type; + if (!class) { + return NULL; + } + + type = class->type; + target_type = type_get_by_name(typename); if (!target_type) { /* target class type unknown, so fail the cast */ return NULL; @@ -488,7 +494,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, { ObjectClass *ret = object_class_dynamic_cast(class, typename); - if (!ret) { + if (!ret && class) { fprintf(stderr, "Object %p is not an instance of type %s\n", class, typename); abort(); -- 1.8.1.4