From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52456) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0fFZ-0001uF-Lg for qemu-devel@nongnu.org; Thu, 23 Feb 2012 15:26:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0fFX-0000ij-5M for qemu-devel@nongnu.org; Thu, 23 Feb 2012 15:26:49 -0500 Received: from mail-pz0-f45.google.com ([209.85.210.45]:60149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0fFW-0000fd-Vf for qemu-devel@nongnu.org; Thu, 23 Feb 2012 15:26:47 -0500 Received: by mail-pz0-f45.google.com with SMTP id p14so1976039dad.4 for ; Thu, 23 Feb 2012 12:26:46 -0800 (PST) Sender: fluxion From: Michael Roth Date: Thu, 23 Feb 2012 14:22:23 -0600 Message-Id: <1330028546-13183-4-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1330028546-13183-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1330028546-13183-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 3/6] 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 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