summaryrefslogtreecommitdiff
path: root/sysdeps/ieee754/ldbl-96
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2012-03-02 15:32:56 +0000
committerJoseph Myers <joseph@codesourcery.com>2012-03-02 15:32:56 +0000
commita6d06d7b86f724046b462115556d0df682f9f703 (patch)
tree640870a7d978c8a224fe317e862b65fddba6f40e /sysdeps/ieee754/ldbl-96
parent07e12bb391ae84eb74817d42feda42cff7f687e5 (diff)
downloadglibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.gz
Fix scalbn, scalbln integer overflow.
Diffstat (limited to 'sysdeps/ieee754/ldbl-96')
-rw-r--r--sysdeps/ieee754/ldbl-96/s_scalblnl.c8
-rw-r--r--sysdeps/ieee754/ldbl-96/s_scalbnl.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/sysdeps/ieee754/ldbl-96/s_scalblnl.c b/sysdeps/ieee754/ldbl-96/s_scalblnl.c
index ada587b9d5..755a212555 100644
--- a/sysdeps/ieee754/ldbl-96/s_scalblnl.c
+++ b/sysdeps/ieee754/ldbl-96/s_scalblnl.c
@@ -43,11 +43,13 @@ __scalblnl (long double x, long int n)
k = (hx&0x7fff) - 63;
}
if (__builtin_expect(k==0x7fff, 0)) return x+x; /* NaN or Inf */
- k = k+n;
- if (__builtin_expect(n> 50000 || k > 0x7ffe, 0))
- return huge*__copysignl(huge,x); /* overflow */
if (__builtin_expect(n< -50000, 0))
return tiny*__copysignl(tiny,x);
+ if (__builtin_expect(n> 50000 || k+n > 0x7ffe, 0))
+ return huge*__copysignl(huge,x); /* overflow */
+ /* Now k and n are bounded we know that k = k+n does not
+ overflow. */
+ k = k+n;
if (__builtin_expect(k > 0, 1)) /* normal result */
{SET_LDOUBLE_EXP(x,(es&0x8000)|k); return x;}
if (k <= -63)
diff --git a/sysdeps/ieee754/ldbl-96/s_scalbnl.c b/sysdeps/ieee754/ldbl-96/s_scalbnl.c
index 6a41920aca..6946cf232f 100644
--- a/sysdeps/ieee754/ldbl-96/s_scalbnl.c
+++ b/sysdeps/ieee754/ldbl-96/s_scalbnl.c
@@ -43,11 +43,13 @@ __scalbnl (long double x, int n)
k = (hx&0x7fff) - 64;
}
if (__builtin_expect(k==0x7fff, 0)) return x+x; /* NaN or Inf */
- k = k+n;
- if (__builtin_expect(n> 50000 || k > 0x7ffe, 0))
- return huge*__copysignl(huge,x); /* overflow */
if (__builtin_expect(n< -50000, 0))
return tiny*__copysignl(tiny,x);
+ if (__builtin_expect(n> 50000 || k+n > 0x7ffe, 0))
+ return huge*__copysignl(huge,x); /* overflow */
+ /* Now k and n are bounded we know that k = k+n does not
+ overflow. */
+ k = k+n;
if (__builtin_expect(k > 0, 1)) /* normal result */
{SET_LDOUBLE_EXP(x,(es&0x8000)|k); return x;}
if (k <= -64)