All of lore.kernel.org
 help / color / mirror / Atom feed
* [PULL 0/1] Miscellaneous patches for 2019-11-25
@ 2019-11-25  6:04 Markus Armbruster
  2019-11-25  6:04 ` [PULL 1/1] util/cutils: Fix incorrect integer->float conversion caught by clang Markus Armbruster
  2019-11-25 15:47 ` [PULL 0/1] Miscellaneous patches for 2019-11-25 Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Markus Armbruster @ 2019-11-25  6:04 UTC (permalink / raw)
  To: qemu-devel

The following changes since commit 2061735ff09f9d5e67c501a96227b470e7de69b1:

  Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2019-11-21 17:18:40 +0000)

are available in the Git repository at:

  git://repo.or.cz/qemu/armbru.git tags/pull-misc-2019-11-25

for you to fetch changes up to 25f74087c695364dfaa87443b1040a3aa5c29008:

  util/cutils: Fix incorrect integer->float conversion caught by clang (2019-11-25 06:00:05 +0100)

----------------------------------------------------------------
Miscellaneous patches for 2019-11-25

----------------------------------------------------------------
Fangrui Song (1):
      util/cutils: Fix incorrect integer->float conversion caught by clang

 util/cutils.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

-- 
2.21.0



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PULL 1/1] util/cutils: Fix incorrect integer->float conversion caught by clang
  2019-11-25  6:04 [PULL 0/1] Miscellaneous patches for 2019-11-25 Markus Armbruster
@ 2019-11-25  6:04 ` Markus Armbruster
  2019-11-25 15:47 ` [PULL 0/1] Miscellaneous patches for 2019-11-25 Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2019-11-25  6:04 UTC (permalink / raw)
  To: qemu-devel; +Cc: Fangrui Song, Richard Henderson, Juan Quintela

From: Fangrui Song <i@maskray.me>

Clang does not like do_strtosz()'s code to guard against overflow:

    qemu/util/cutils.c:245:23: error: implicit conversion from 'unsigned long' to 'double' changes value from 18446744073709550592 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]

The warning will be enabled by default in clang 10. It is not
available for clang <= 9.

val * mul >= 0xfffffffffffffc00 is indeed wrong.  0xfffffffffffffc00
is not representable exactly as double.  It's half-way between the
representable values 0xfffffffffffff800 and 0x10000000000000000.
Which one we get is implementation-defined.  Bad.

We want val * mul > (the largest uint64_t exactly representable as
double).  That's 0xfffffffffffff800.  Write it as nextafter(0x1p64, 0)
with a suitable comment.

Signed-off-by: Fangrui Song <i@maskray.me>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
[Patch split, commit message improved]
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20191122080039.12771-3-armbru@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Juan Quintela <quintela@redhat.com>
---
 util/cutils.c | 8 +++++---
 1 file 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;
     }
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PULL 0/1] Miscellaneous patches for 2019-11-25
  2019-11-25  6:04 [PULL 0/1] Miscellaneous patches for 2019-11-25 Markus Armbruster
  2019-11-25  6:04 ` [PULL 1/1] util/cutils: Fix incorrect integer->float conversion caught by clang Markus Armbruster
@ 2019-11-25 15:47 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2019-11-25 15:47 UTC (permalink / raw)
  To: Markus Armbruster; +Cc: QEMU Developers

On Mon, 25 Nov 2019 at 06:06, Markus Armbruster <armbru@redhat.com> wrote:
>
> The following changes since commit 2061735ff09f9d5e67c501a96227b470e7de69b1:
>
>   Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging (2019-11-21 17:18:40 +0000)
>
> are available in the Git repository at:
>
>   git://repo.or.cz/qemu/armbru.git tags/pull-misc-2019-11-25
>
> for you to fetch changes up to 25f74087c695364dfaa87443b1040a3aa5c29008:
>
>   util/cutils: Fix incorrect integer->float conversion caught by clang (2019-11-25 06:00:05 +0100)
>
> ----------------------------------------------------------------
> Miscellaneous patches for 2019-11-25
>
> ----------------------------------------------------------------
> Fangrui Song (1):
>       util/cutils: Fix incorrect integer->float conversion caught by clang
>
>  util/cutils.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> --


Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.2
for any user-visible changes.

-- PMM


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-25 15:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-25  6:04 [PULL 0/1] Miscellaneous patches for 2019-11-25 Markus Armbruster
2019-11-25  6:04 ` [PULL 1/1] util/cutils: Fix incorrect integer->float conversion caught by clang Markus Armbruster
2019-11-25 15:47 ` [PULL 0/1] Miscellaneous patches for 2019-11-25 Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.