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 <f...@redhat.com> --- 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