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 <m...@tls.msk.ru> > --- > qemu-img.c | 118 ++++++++++++++++++++--------------------------------- > 1 file changed, 44 insertions(+), 74 deletions(-)
Reviewed-by: Daniel P. Berrangé <berra...@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 :|