summary refs log tree commit diff stats
path: root/qom/object.c
diff options
context:
space:
mode:
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>2013-06-18 19:18:59 +1000
committerAnthony Liguori <aliguori@us.ibm.com>2013-07-10 10:53:45 -0500
commit9d6a3d58e4d1431ab3809ff621cfd1f9ec75eef5 (patch)
treedab0b5d3704708e1dbe79e4e138a077b9090a4a2 /qom/object.c
parentc1b71b0c03df575c72ea413b2f2c27a7a477c05a (diff)
downloadfocaccia-qemu-9d6a3d58e4d1431ab3809ff621cfd1f9ec75eef5.tar.gz
focaccia-qemu-9d6a3d58e4d1431ab3809ff621cfd1f9ec75eef5.zip
qom: Fix class cast of NULL classes
Its clear from the implementation that class casting is supposed to work
with a NULL class argument. Guard all dereferences of the class argument
against NULL accordingly.

Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Message-id: 94cd5ba46b74eea289a7e582635820c1c54e66fa.1371546907.git.peter.crosthwaite@xilinx.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qom/object.c')
-rw-r--r--qom/object.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/qom/object.c b/qom/object.c
index cbd7e86033..b2479d1c06 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -531,14 +531,14 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
 #ifdef CONFIG_QOM_CAST_DEBUG
     int i;
 
-    for (i = 0; i < OBJECT_CLASS_CAST_CACHE; i++) {
+    for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) {
         if (class->cast_cache[i] == typename) {
             ret = class;
             goto out;
         }
     }
 #else
-    if (!class->interfaces) {
+    if (!class || !class->interfaces) {
         return class;
     }
 #endif
@@ -551,7 +551,7 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class,
     }
 
 #ifdef CONFIG_QOM_CAST_DEBUG
-    if (ret == class) {
+    if (class && ret == class) {
         for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
             class->cast_cache[i - 1] = class->cast_cache[i];
         }