aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2019-11-25 15:05:52 +0000
committerPeter Maydell <peter.maydell@linaro.org>2019-11-25 15:05:53 +0000
commit6d05e39d69a6876d8a604773157a303da9bec16b (patch)
tree21cd63561c8b6558943e983a5d0a9548e909b28d
parent122e6d2a9c1bf8aa1d51409c15809a82621515b1 (diff)
parent25f74087c695364dfaa87443b1040a3aa5c29008 (diff)
Merge remote-tracking branch 'remotes/armbru/tags/pull-misc-2019-11-25' into staging
Miscellaneous patches for 2019-11-25 # gpg: Signature made Mon 25 Nov 2019 06:00:24 GMT # gpg: using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653 # gpg: issuer "armbru@redhat.com" # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [full] # gpg: aka "Markus Armbruster <armbru@pond.sub.org>" [full] # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867 4E5F 3870 B400 EB91 8653 * remotes/armbru/tags/pull-misc-2019-11-25: util/cutils: Fix incorrect integer->float conversion caught by clang Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--util/cutils.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/util/cutils.c b/util/cutils.c
index fd591cadf0..77acadc70a 100644
--- a/util/cutils.c
+++ b/util/cutils.c
@@ -239,10 +239,12 @@ static int do_strtosz(const char *nptr, const char **end,
goto out;
}
/*
- * Values >= 0xfffffffffffffc00 overflow uint64_t after their trip
- * through double (53 bits of precision).
+ * Values near UINT64_MAX overflow to 2**64 when converting to double
+ * precision. Compare against the maximum representable double precision
+ * value below 2**64, computed as "the next value after 2**64 (0x1p64) in
+ * the direction of 0".
*/
- if ((val * mul >= 0xfffffffffffffc00) || val < 0) {
+ if ((val * mul > nextafter(0x1p64, 0)) || val < 0) {
retval = -ERANGE;
goto out;
}