Skip to content

Commit

Permalink
qom: Fix class cast of NULL classes
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pete128 authored and Anthony Liguori committed Jul 10, 2013
1 parent c1b71b0 commit 9d6a3d5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions qom/object.c
Expand Up @@ -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
Expand All @@ -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];
}
Expand Down

0 comments on commit 9d6a3d5

Please sign in to comment.