提交 b7f43fe4 编写于 作者: P Paolo Bonzini 提交者: Anthony Liguori

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: NMarkus Armbruster <armbru@redhat.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 74c856e9
...@@ -417,7 +417,7 @@ void object_delete(Object *obj) ...@@ -417,7 +417,7 @@ void object_delete(Object *obj)
Object *object_dynamic_cast(Object *obj, const char *typename) 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; return obj;
} }
...@@ -430,7 +430,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename) ...@@ -430,7 +430,7 @@ Object *object_dynamic_cast_assert(Object *obj, const char *typename)
inst = object_dynamic_cast(obj, typename); inst = object_dynamic_cast(obj, typename);
if (!inst) { if (!inst && obj) {
fprintf(stderr, "Object %p is not an instance of type %s\n", fprintf(stderr, "Object %p is not an instance of type %s\n",
obj, typename); obj, typename);
abort(); abort();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册