summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Tokarev <mjt@tls.msk.ru>2025-05-31 20:15:44 +0300
committerKevin Wolf <kwolf@redhat.com>2025-07-15 20:49:01 +0200
commit443761ab3874d0ffc2df0a0cd73dd1ca833b277e (patch)
treed0fc5b62a41bcd84e152c1acbfebb694f55a04ff
parent1c47abc5779dfaaee303f0bff144e88dc8fb74d5 (diff)
downloadfocaccia-qemu-443761ab3874d0ffc2df0a0cd73dd1ca833b277e.tar.gz
focaccia-qemu-443761ab3874d0ffc2df0a0cd73dd1ca833b277e.zip
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 <mjt@tls.msk.ru>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20250531171609.197078-3-mjt@tls.msk.ru>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
-rw-r--r--qemu-img.c9
1 files changed, 3 insertions, 6 deletions
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]);