musl: backport various post-1.1.15 fixes
[openwrt/openwrt.git] / toolchain / musl / patches / 048-math-fix-pow-signed-shift-ub.patch
1 From 688d3da0f1730daddbc954bbc2d27cc96ceee04c Mon Sep 17 00:00:00 2001
2 From: Szabolcs Nagy <nsz@port70.net>
3 Date: Tue, 4 Oct 2016 03:58:56 +0200
4 Subject: math: fix pow signed shift ub
5
6 j is int32_t and thus j<<31 is undefined if j==1, so j is changed to
7 uint32_t locally as a quick fix, the generated code is not affected.
8
9 (this is a strict conformance fix, future c standard may allow 1<<31,
10 see DR 463. the bug was inherited from freebsd fdlibm, the proper fix
11 is to use uint32_t for all bit hacks, but that requires more intrusive
12 changes.)
13
14 reported by Daniel Sabogal
15 ---
16 src/math/pow.c | 4 ++--
17 1 file changed, 2 insertions(+), 2 deletions(-)
18
19 diff --git a/src/math/pow.c b/src/math/pow.c
20 index b66f632..3ddc1b6 100644
21 --- a/src/math/pow.c
22 +++ b/src/math/pow.c
23 @@ -125,11 +125,11 @@ double pow(double x, double y)
24 else if (iy >= 0x3ff00000) {
25 k = (iy>>20) - 0x3ff; /* exponent */
26 if (k > 20) {
27 - j = ly>>(52-k);
28 + uint32_t j = ly>>(52-k);
29 if ((j<<(52-k)) == ly)
30 yisint = 2 - (j&1);
31 } else if (ly == 0) {
32 - j = iy>>(20-k);
33 + uint32_t j = iy>>(20-k);
34 if ((j<<(20-k)) == iy)
35 yisint = 2 - (j&1);
36 }
37 --
38 cgit v0.11.2