From: Paolo Bonzini Date: Fri, 23 Nov 2012 15:56:17 +0000 (+0100) Subject: qom: dynamic_cast of NULL is always NULL X-Git-Tag: v1.2.2~15 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=5e19e498b4b2a31c985dc96b1aff078c34e40488;p=users%2Fdwmw2%2Fqemu.git qom: dynamic_cast of NULL is always NULL 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 Signed-off-by: Paolo Bonzini Signed-off-by: Anthony Liguori (cherry picked from commit b7f43fe46029d8fd0594cd599fa2599dcce0f553) Signed-off-by: Michael Roth --- diff --git a/qom/object.c b/qom/object.c index e3e9242638..f33e84da7d 100644 --- a/qom/object.c +++ b/qom/object.c @@ -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();