[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
signature.asc
Description: OpenPGP digital signature
- [Qemu-devel] [PATCH 00/16] Make qemu-io commands available in the monitor, Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 01/16] qemu-io: Remove unused args_command, Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 02/16] cutils: Support 'P' and 'E' suffixes in strtosz(), Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 03/16] qemu-io: Make cvtnum() a wrapper around strtosz_suffix(), Kevin Wolf, 2013/05/28
- Re: [Qemu-devel] [PATCH 03/16] qemu-io: Make cvtnum() a wrapper around strtosz_suffix(),
Eric Blake <=
- [Qemu-devel] [PATCH 04/16] qemu-io: Handle cvtnum() errors in 'alloc', Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 05/16] qemu-io: Don't use global bs in command implementations, Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 08/16] qemu-io: Move 'help' function, Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 07/16] qemu-io: Factor out qemuio_command, Kevin Wolf, 2013/05/28
- [Qemu-devel] [PATCH 09/16] qemu-io: Move 'quit' function, Kevin Wolf, 2013/05/28