From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIVFw-0003ew-Je for qemu-devel@nongnu.org; Mon, 11 Jan 2016 00:43:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIVFu-0002Fi-5N for qemu-devel@nongnu.org; Mon, 11 Jan 2016 00:43:04 -0500 From: Fam Zheng Date: Mon, 11 Jan 2016 13:42:38 +0800 Message-Id: <1452490959-10387-2-git-send-email-famz@redhat.com> In-Reply-To: <1452490959-10387-1-git-send-email-famz@redhat.com> References: <1452490959-10387-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] blockdev: Error out on negative throttling option values List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Markus Armbruster , qemu-block@nongnu.org The implicit casting from unsigned int to double changes negative values into large positive numbers, whereas explicitly casting to signed integer first will let us catch the invalid value and report error correctly: $ qemu-system-x86_64 -drive file=null-co://,iops=-1 qemu-system-x86_64: -drive file=null-co://,iops=-1: bps/iops/maxs values must be 0 or greater Signed-off-by: Fam Zheng --- blockdev.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/blockdev.c b/blockdev.c index 2df0c6d..8b6b398 100644 --- a/blockdev.c +++ b/blockdev.c @@ -407,33 +407,33 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags, if (throttle_cfg) { memset(throttle_cfg, 0, sizeof(*throttle_cfg)); throttle_cfg->buckets[THROTTLE_BPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.bps-total", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.bps-total", 0); throttle_cfg->buckets[THROTTLE_BPS_READ].avg = - qemu_opt_get_number(opts, "throttling.bps-read", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.bps-read", 0); throttle_cfg->buckets[THROTTLE_BPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.bps-write", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.bps-write", 0); throttle_cfg->buckets[THROTTLE_OPS_TOTAL].avg = - qemu_opt_get_number(opts, "throttling.iops-total", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-total", 0); throttle_cfg->buckets[THROTTLE_OPS_READ].avg = - qemu_opt_get_number(opts, "throttling.iops-read", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-read", 0); throttle_cfg->buckets[THROTTLE_OPS_WRITE].avg = - qemu_opt_get_number(opts, "throttling.iops-write", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-write", 0); throttle_cfg->buckets[THROTTLE_BPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.bps-total-max", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.bps-total-max", 0); throttle_cfg->buckets[THROTTLE_BPS_READ].max = - qemu_opt_get_number(opts, "throttling.bps-read-max", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.bps-read-max", 0); throttle_cfg->buckets[THROTTLE_BPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.bps-write-max", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.bps-write-max", 0); throttle_cfg->buckets[THROTTLE_OPS_TOTAL].max = - qemu_opt_get_number(opts, "throttling.iops-total-max", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-total-max", 0); throttle_cfg->buckets[THROTTLE_OPS_READ].max = - qemu_opt_get_number(opts, "throttling.iops-read-max", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-read-max", 0); throttle_cfg->buckets[THROTTLE_OPS_WRITE].max = - qemu_opt_get_number(opts, "throttling.iops-write-max", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-write-max", 0); throttle_cfg->op_size = - qemu_opt_get_number(opts, "throttling.iops-size", 0); + (int64_t)qemu_opt_get_number(opts, "throttling.iops-size", 0); if (!check_throttle_config(throttle_cfg, errp)) { return; -- 2.4.3