From patchwork Mon May 14 13:25:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 158996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 0FEE9B7034 for ; Mon, 14 May 2012 23:25:46 +1000 (EST) Received: from localhost ([::1]:33768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STvHT-0002jM-SO for incoming@patchwork.ozlabs.org; Mon, 14 May 2012 09:25:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STvHD-0002Rd-Ao for qemu-devel@nongnu.org; Mon, 14 May 2012 09:25:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1STvH2-00023g-FE for qemu-devel@nongnu.org; Mon, 14 May 2012 09:25:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43143) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1STvH2-00023T-7C for qemu-devel@nongnu.org; Mon, 14 May 2012 09:25:16 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q4EDPD0n010512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 May 2012 09:25:13 -0400 Received: from localhost (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q4EDPBho013178; Mon, 14 May 2012 09:25:12 -0400 From: Luiz Capitulino To: aliguori@us.ibm.com Date: Mon, 14 May 2012 10:25:25 -0300 Message-Id: <1337001925-8992-2-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1337001925-8992-1-git-send-email-lcapitulino@redhat.com> References: <1337001925-8992-1-git-send-email-lcapitulino@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-MIME-Autoconverted: from 8bit to quoted-printable by mx1.redhat.com id q4EDPD0n010512 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, Michael Roth Subject: [Qemu-devel] [PULL 1/1] qapi: QMP input visitor, handle floats parsed as ints X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Michael Roth 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 Signed-off-by: Luiz Capitulino Acked-by: Andreas Färber --- qapi/qmp-input-visitor.c | 11 ++++++++--- 1 file 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,