]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qom: dynamic_cast of NULL is always NULL
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 23 Nov 2012 15:56:17 +0000 (16:56 +0100)
committerMichael Roth <mdroth@linux.vnet.ibm.com>
Mon, 3 Dec 2012 20:26:56 +0000 (14:26 -0600)
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 <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
(cherry picked from commit b7f43fe46029d8fd0594cd599fa2599dcce0f553)

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
qom/object.c

index e3e9242638dbe6e99efba9b7184158f7c55ec8f2..f33e84da7d4ca2151773f24e46c53407df772734 100644 (file)
@@ -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();