[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 02/27] qemu-img: create: convert img_size to signed, simplify han
From: |
Michael Tokarev |
Subject: |
[PATCH 02/27] qemu-img: create: convert img_size to signed, simplify handling |
Date: |
Wed, 24 Apr 2024 11:50:10 +0300 |
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(-)
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]);
--
2.39.2
- [PATCH v3 00/27] qemu-img: refersh options and --help handling, cleanups, Michael Tokarev, 2024/04/24
- [PATCH 01/27] qemu-img: measure: convert img_size to signed, simplify handling, Michael Tokarev, 2024/04/24
- [PATCH 02/27] qemu-img: create: convert img_size to signed, simplify handling,
Michael Tokarev <=
- [PATCH 03/27] qemu-img: global option processing and error printing, Michael Tokarev, 2024/04/24
- [PATCH 04/27] qemu-img: pass current cmd info into command handlers, Michael Tokarev, 2024/04/24
- [PATCH 05/27] qemu-img: create: refresh options/--help, Michael Tokarev, 2024/04/24
- [PATCH 06/27] qemu-img: factor out parse_output_format() and use it in the code, Michael Tokarev, 2024/04/24
- [PATCH 10/27] qemu-img: compare: refresh options/--help, Michael Tokarev, 2024/04/24
- [PATCH 11/27] qemu-img: convert: refresh options/--help, Michael Tokarev, 2024/04/24
- [PATCH 07/27] qemu-img: check: refresh options/--help, Michael Tokarev, 2024/04/24
- [PATCH 08/27] qemu-img: simplify --repair error message, Michael Tokarev, 2024/04/24
- [PATCH 09/27] qemu-img: commit: refresh options/--help, Michael Tokarev, 2024/04/24
- [PATCH 13/27] qemu-img: map: refresh options/--help, Michael Tokarev, 2024/04/24