[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 03/16] qemu-io: Make cvtnum() a wrapper around s

From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 03/16] qemu-io: Make cvtnum() a wrapper around strtosz_suffix()
Date: Tue, 28 May 2013 10:42:39 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6

On 05/28/2013 09:27 AM, Kevin Wolf wrote:
> No reason to implement the same thing multiple times. A nice side effect
> is that fractional numbers like 0.5M can be used in qemu-io now.
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
>  cmd.c     | 37 -------------------------------------
>  cmd.h     |  1 -
>  qemu-io.c |  6 ++++++
>  3 files changed, 6 insertions(+), 38 deletions(-)

> -
> -     i = strtoll(s, &sp, 0);
> -     if (i == 0 && sp == s)
> -             return -1LL;
> -     if (*sp == '\0')
> -             return i;

Another nice side effect: you are also getting rid of poor handling that
fails to check for errors after strtoll() (such as clamping at INT64_MAX
on EOVERFLOW).  On the other hand, strtosz_suffix uses strtod() which
may inadvertently cause rounding of low-order bits of large input
numbers (that is, parsing with only 53 significant bits instead of 64
may cause us to round a value that was previously exact); but I'd rather
deal with consistent behavior even if it rounds some values, than
question which of multiple slightly different implementations will be
parsing my values (we can also argue that perhaps strtosz_suffix could
be improved to guarantee 64 bits of precision if there is no '.' in the
value being parsed, while still providing the flexibility of 0.5G
parsing when precision isn't important).

Reviewed-by: Eric Blake <address@hidden>

Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]