Skip to content

Commit

Permalink
qom/object: Don't poll cast cache for NULL objects
Browse files Browse the repository at this point in the history
object_dynamic_cast_assert used to be tolerant of NULL objects and not
assert. It's clear from the implementation that this is the expected
behavior.

The preceding check of the cast cache dereferences obj however causing
a segfault. Fix by conditionalizing the cast cache logic on obj being
non-null.

Signed-off-by: Peter Crosthwaite <[email protected]>
Reviewed-by: Andreas Färber <[email protected]>
Reviewed-by: Anthony Liguori <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Reviewed-by: Edgar E. Iglesias <[email protected]>
Message-id: 8e2bef6a55753869c50bfa32226f7fcf0439ca62.1369183592.git.peter.crosthwaite@xilinx.com
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
pete128 authored and Anthony Liguori committed May 22, 2013
1 parent 3d1bba2 commit 95916ab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions qom/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename,
int i;
Object *inst;

for (i = 0; i < OBJECT_CLASS_CAST_CACHE; i++) {
for (i = 0; obj && i < OBJECT_CLASS_CAST_CACHE; i++) {
if (obj->class->cast_cache[i] == typename) {
goto out;
}
Expand All @@ -458,7 +458,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename,

assert(obj == inst);

if (obj == inst) {
if (obj && obj == inst) {
for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) {
obj->class->cast_cache[i - 1] = obj->class->cast_cache[i];
}
Expand Down

0 comments on commit 95916ab

Please sign in to comment.