From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55328) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aJk70-0002M3-UM for qemu-devel@nongnu.org; Thu, 14 Jan 2016 10:47:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aJk6w-0001bz-TO for qemu-devel@nongnu.org; Thu, 14 Jan 2016 10:46:58 -0500 References: <1452744489-3513-1-git-send-email-famz@redhat.com> <1452744489-3513-2-git-send-email-famz@redhat.com> From: Max Reitz Message-ID: <5697C2E5.2010908@redhat.com> Date: Thu, 14 Jan 2016 16:46:45 +0100 MIME-Version: 1.0 In-Reply-To: <1452744489-3513-2-git-send-email-famz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7ApmVSAXm2Vi2FTaOm7koiKOO2PnS4bju" Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v3 1/2] blockdev: Error out on negative throttling option values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng , qemu-devel@nongnu.org Cc: Kevin Wolf , Markus Armbruster , qemu-block@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7ApmVSAXm2Vi2FTaOm7koiKOO2PnS4bju Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: quoted-printable On 14.01.2016 05:08, Fam Zheng wrote: > The implicit casting from unsigned int to double changes negative value= s > into large positive numbers and accepts them. We should instead print > an error. >=20 > Check the number range so this case is caught and reported. >=20 > Signed-off-by: Fam Zheng > --- > blockdev.c | 3 ++- > include/qemu/throttle.h | 2 ++ > util/throttle.c | 16 ++++++---------- > 3 files changed, 10 insertions(+), 11 deletions(-) Reviewed-by: Max Reitz > diff --git a/blockdev.c b/blockdev.c > index 2df0c6d..1afef87 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -348,7 +348,8 @@ static bool check_throttle_config(ThrottleConfig *c= fg, Error **errp) > } > =20 > if (!throttle_is_valid(cfg)) { > - error_setg(errp, "bps/iops/maxs values must be 0 or greater");= > + error_setg(errp, "bps/iops/maxs values must be within [0, %" P= RId64 > + ")", (int64_t)THROTTLE_VALUE_MAX); I personally would have liked a simpler %lli and no cast, but I can see why you want an explicit int64_t here. > return false; > } > =20 > diff --git a/include/qemu/throttle.h b/include/qemu/throttle.h > index 12faaad..d0c98ed 100644 > --- a/include/qemu/throttle.h > +++ b/include/qemu/throttle.h > @@ -29,6 +29,8 @@ > #include "qemu-common.h" > #include "qemu/timer.h" > =20 > +#define THROTTLE_VALUE_MAX 1000000000000000LL But then you could use UINT64_C(1000000000000000) here. --7ApmVSAXm2Vi2FTaOm7koiKOO2PnS4bju Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJWl8LlAAoJEDuxQgLoOKytKqYIAIiu+oKOz63TccADxUIfcR5Y cMf5Di2t/4geVrIhuns4qrFgIC8qTiVzhaCXqxND5jHU9tiu002k81GvTTDcnZOW t59Y24MMCSNpsrLhksqcpr7VU8QVHY0gk4F6H0HY7nFy8Ob9jvkwP6JwRHZqeNim jxwa6WRM9dE4onVpUCX2/+yrXLbOFGUga6VERF8gn+6UmyC3HSCZZLrt4PpIFqj2 RicUjE7HgekdpZUZzdEzb4SuWsYnUDXUUBgNxQrU0jIfNfXlotCaS+Gm5yo0aesi harvMVfQNTaPvCsCiVzGrHwU1GgMGzCrkdRrAIk32Z2eUZA6FEQR6AIbuBfyBWo= =NuUG -----END PGP SIGNATURE----- --7ApmVSAXm2Vi2FTaOm7koiKOO2PnS4bju--