提交 1ee51876 编写于 作者: M Michael Roth 提交者: Luiz Capitulino

qapi: QMP input visitor, handle floats parsed as ints

JSON numbers can be interpreted as either integers or floating point
values depending on their representation. As a result, QMP input visitor
might visit a QInt when it was expecting a QFloat, so add handling to
account for this.
Signed-off-by: NMichael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
Acked-by: NAndreas Färber <afaerber@suse.de>
上级 94d19914
......@@ -246,13 +246,18 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name,
QmpInputVisitor *qiv = to_qiv(v);
QObject *qobj = qmp_input_get_object(qiv, name);
if (!qobj || qobject_type(qobj) != QTYPE_QFLOAT) {
if (!qobj || (qobject_type(qobj) != QTYPE_QFLOAT &&
qobject_type(qobj) != QTYPE_QINT)) {
error_set(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null",
"double");
"number");
return;
}
*obj = qfloat_get_double(qobject_to_qfloat(qobj));
if (qobject_type(qobj) == QTYPE_QINT) {
*obj = qint_get_int(qobject_to_qint(qobj));
} else {
*obj = qfloat_get_double(qobject_to_qfloat(qobj));
}
}
static void qmp_input_start_optional(Visitor *v, bool *present,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册