Commit 95916abc authored by Peter Crosthwaite's avatar Peter Crosthwaite Committed by Anthony Liguori
Browse files

qom/object: Don't poll cast cache for NULL objects



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: default avatarPeter Crosthwaite <peter.crosthwaite@xilinx.com>
Reviewed-by: default avatarAndreas Färber <afaerber@suse.de>
Reviewed-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
Reviewed-by: default avatarEdgar E. Iglesias <edgar.iglesias@gmail.com>
Message-id: 8e2bef6a55753869c50bfa32226f7fcf0439ca62.1369183592.git.peter.crosthwaite@xilinx.com
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent 3d1bba20
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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;
        }
@@ -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];
        }