[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v17 02/14] util/cutils: Use qemu_strtold_finite to parse size
From: |
Markus Armbruster |
Subject: |
Re: [PATCH v17 02/14] util/cutils: Use qemu_strtold_finite to parse size |
Date: |
Mon, 25 Nov 2019 07:56:33 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) |
Tao Xu <address@hidden> writes:
> Support full 64bit precision, modify related test cases.
That's not true in general: long double need not be any wider than
double.
It might be true on the host machines we support, but I don't know. If
we decide to rely on it, we better make the build fail when the host
machine doesn't meet our expectations, preferably in configure.
>
> Signed-off-by: Tao Xu <address@hidden>
> ---
[...]
> diff --git a/util/cutils.c b/util/cutils.c
> index 5db3b2add5..d94a468954 100644
> --- a/util/cutils.c
> +++ b/util/cutils.c
> @@ -216,13 +216,13 @@ static int do_strtosz(const char *nptr, const char
> **end,
> const char *endptr;
> unsigned char c;
> int mul_required = 0;
> - double val, mul, integral, fraction;
> + long double val, mul, integral, fraction;
>
> - retval = qemu_strtod_finite(nptr, &endptr, &val);
> + retval = qemu_strtold_finite(nptr, &endptr, &val);
> if (retval) {
> goto out;
> }
> - fraction = modf(val, &integral);
> + fraction = modfl(val, &integral);
> if (fraction != 0) {
> mul_required = 1;
> }
> @@ -238,11 +238,8 @@ static int do_strtosz(const char *nptr, const char **end,
> retval = -EINVAL;
> goto out;
> }
> - /*
> - * Values >= 0xfffffffffffffc00 overflow uint64_t after their trip
> - * through double (53 bits of precision).
> - */
> - if ((val * mul >= 0xfffffffffffffc00) || val < 0) {
> + /* Values > UINT64_MAX overflow uint64_t */
> + if ((val * mul > UINT64_MAX) || val < 0) {
> retval = -ERANGE;
> goto out;
> }
Not portable. If it was, we'd have made this changd long ago :)
Re: [PATCH v17 03/14] util/cutils: refactor do_strtosz() to support suffixes list, Markus Armbruster, 2019/11/26