summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-11-23 16:56:17 +0100
committerDoug Goldstein <cardoe@cardoe.com>2012-12-13 15:31:59 -0600
commitfa830675f2d112a33b81d5345b07ad609d3e922e (patch)
tree4393008708c86dc759e5b7b17fa8687cc31454c9
parentblock: Fix regression for MinGW (assertion caused by short string) (diff)
downloadqemu-kvm-fa830675f2d112a33b81d5345b07ad609d3e922e.tar.gz
qemu-kvm-fa830675f2d112a33b81d5345b07ad609d3e922e.tar.bz2
qemu-kvm-fa830675f2d112a33b81d5345b07ad609d3e922e.zip
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 <armbru@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> (cherry picked from commit b7f43fe46029d8fd0594cd599fa2599dcce0f553) Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> (cherry picked from commit 5e19e498b4b2a31c985dc96b1aff078c34e40488)
-rw-r--r--qom/object.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/qom/object.c b/qom/object.c
index e3e924263..f33e84da7 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();