[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 28/28] qemu-img: extend cvtnum() and use it in more places
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH 28/28] qemu-img: extend cvtnum() and use it in more places |
Date: |
Mon, 26 Feb 2024 14:57:39 +0000 |
User-agent: |
Mutt/2.2.12 (2023-09-09) |
On Thu, Feb 22, 2024 at 12:16:09AM +0300, Michael Tokarev wrote:
> cvtnum() expects input string to specify some sort of size
> (optionally with KMG... suffix). However, there are a lot
> of other number conversions in there (using qemu_strtol &Co),
> also, not all conversions which use cvtnum, actually expects
> size, - like dd count=nn.
>
> Add bool issize argument to cvtnum() to specify if it should
> treat the argument as a size or something else, - this changes
> conversion routine in use and error text.
>
> Use the new cvtnum() in more places (like where strtol were used),
> since it never return negative number in successful conversion.
> When it makes sense, also specify upper or lower bounds at the
> same time. This simplifies option processing in multiple places,
> removing the need of local temporary variables and longer error
> reporting code.
>
> While at it, fix errors, like depth in measure must be >= 1,
> while the previous code allowed it to be 0.
>
> In a few places, change unsigned variables (like of type size_t)
> to be signed instead, - to avoid the need of temporary conversion
> variable. All these variables are okay to be signed, we never
> assign <0 value to them except of the cases of conversion error,
> where we return immediately.
>
> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
> ---
> qemu-img.c | 118 ++++++++++++++++++++---------------------------------
> 1 file changed, 44 insertions(+), 74 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- [PATCH 20/28] qemu-img: resize: refresh options/--help, (continued)
- [PATCH 20/28] qemu-img: resize: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 18/28] qemu-img: rebase: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 21/28] qemu-img: amend: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 22/28] qemu-img: bench: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 23/28] qemu-img: bitmap: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 24/28] qemu-img: dd: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 25/28] qemu-img: measure: refresh options/--help, Michael Tokarev, 2024/02/21
- [PATCH 26/28] qemu-img: implement short --help, remove global help() function, Michael Tokarev, 2024/02/21
- [PATCH 28/28] qemu-img: extend cvtnum() and use it in more places, Michael Tokarev, 2024/02/21
- [PATCH 27/28] qemu-img: inline list of supported commands, remove qemu-img-cmds.h include, Michael Tokarev, 2024/02/21