From: Michael Tokarev Date: Sat, 31 May 2025 17:15:44 +0000 (+0300) Subject: qemu-img: create: convert img_size to signed, simplify handling X-Git-Tag: v10.1.0-rc0~13^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=443761ab3874d0ffc2df0a0cd73dd1ca833b277e;p=thirdparty%2Fqemu.git qemu-img: create: convert img_size to signed, simplify handling Initializing an unsigned as -1, or using temporary sval for conversion is awkward. Since we don't allow other "negative" values anyway, use signed value and pass it to bdrv_img_create() (where it is properly converted to unsigned), simplifying code. Signed-off-by: Michael Tokarev Reviewed-by: Daniel P. Berrangé Reviewed-by: Kevin Wolf Message-ID: <20250531171609.197078-3-mjt@tls.msk.ru> Signed-off-by: Kevin Wolf --- diff --git a/qemu-img.c b/qemu-img.c index e676602fc7..6750d0657c 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -511,7 +511,7 @@ static int64_t cvtnum(const char *name, const char *value) static int img_create(int argc, char **argv) { int c; - uint64_t img_size = -1; + int64_t img_size = -1; const char *fmt = "raw"; const char *base_fmt = NULL; const char *filename; @@ -582,13 +582,10 @@ static int img_create(int argc, char **argv) /* Get image size, if specified */ if (optind < argc) { - int64_t sval; - - sval = cvtnum("image size", argv[optind++]); - if (sval < 0) { + img_size = cvtnum("image size", argv[optind++]); + if (img_size < 0) { goto fail; } - img_size = (uint64_t)sval; } if (optind != argc) { error_exit("Unexpected argument: %s", argv[optind]);