diff mbox series

[02/27] qemu-img: create: convert img_size to signed, simplify handling

Message ID 20240927061121.573271-3-mjt@tls.msk.ru (mailing list archive)
State New, archived
Headers show
Series qemu-img: refersh options and --help handling, cleanups | expand

Commit Message

Michael Tokarev Sept. 27, 2024, 6:10 a.m. UTC
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>
---
 qemu-img.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Kevin Wolf Nov. 5, 2024, 7:27 p.m. UTC | #1
Am 27.09.2024 um 08:10 hat Michael Tokarev geschrieben:
> 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>
diff mbox series

Patch

diff --git a/qemu-img.c b/qemu-img.c
index 6e7ac2048f..fe22986931 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]);