From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53329) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4dJ9-0006A5-NZ for qemu-devel@nongnu.org; Mon, 05 Mar 2012 14:10:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4dJ8-0000Of-0G for qemu-devel@nongnu.org; Mon, 05 Mar 2012 14:10:55 -0500 Received: from mail-pz0-f46.google.com ([209.85.210.46]:48349) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4dJ7-0000OF-Nt for qemu-devel@nongnu.org; Mon, 05 Mar 2012 14:10:53 -0500 Received: by dajr28 with SMTP id r28so6798513daj.33 for ; Mon, 05 Mar 2012 11:10:51 -0800 (PST) Sender: fluxion From: Michael Roth Date: Mon, 5 Mar 2012 13:10:30 -0600 Message-Id: <1330974634-7527-4-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1330974634-7527-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1330974634-7527-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v3 3/7] qapi: QMP input visitor, handle floats parsed as ints List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de 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: Michael Roth --- qapi/qmp-input-visitor.c | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index e6b6152..f7ffb59 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -209,13 +209,18 @@ static void qmp_input_type_number(Visitor *v, double *obj, const char *name, QmpInputVisitor *qiv = to_qiv(v); const 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"); 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, -- 1.7.4.1