From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:48490) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SStsQ-0004jp-LA for qemu-devel@nongnu.org; Fri, 11 May 2012 13:43:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SStsO-0003M9-VM for qemu-devel@nongnu.org; Fri, 11 May 2012 13:43:38 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:59615) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SStsO-0003M2-Oo for qemu-devel@nongnu.org; Fri, 11 May 2012 13:43:36 -0400 Received: by yenm4 with SMTP id m4so3674344yen.4 for ; Fri, 11 May 2012 10:43:35 -0700 (PDT) Sender: fluxion From: Michael Roth Date: Fri, 11 May 2012 12:43:24 -0500 Message-Id: <1336758204-9118-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 1.1] 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: aliguori@us.ibm.com, afaerber@suse.de, lcapitulino@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 | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-) diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index 4cdc47d..107d8d3 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -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, -- 1.7.4.1