about summary refs log tree commit diff
path: root/sysdeps/ieee754/dbl-64/wordsize-64
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/dbl-64/wordsize-64
parent07e12bb391ae84eb74817d42feda42cff7f687e5 (diff)
downloadglibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.gz
glibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.xz
glibc-a6d06d7b86f724046b462115556d0df682f9f703.zip
Fix scalbn, scalbln integer overflow.
Diffstat (limited to 'sysdeps/ieee754/dbl-64/wordsize-64')
-rw-r--r--sysdeps/ieee754/dbl-64/wordsize-64/s_scalbln.c8
-rw-r--r--sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbln.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbln.c
index d6b97b5483..1d0da687c1 100644
--- a/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbln.c
+++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbln.c
@@ -39,11 +39,13 @@ __scalbln (double x, long int n)
 	    k = ((ix >> 52) & 0x7ff) - 54;
 	    }
 	if (__builtin_expect(k==0x7ff, 0)) return x+x;	/* NaN or Inf */
-	k = k+n;
-	if (__builtin_expect(n> 50000 || k >  0x7fe, 0))
-	  return huge*__copysign(huge,x); /* overflow  */
 	if (__builtin_expect(n< -50000, 0))
 	  return tiny*__copysign(tiny,x); /*underflow*/
+	if (__builtin_expect(n> 50000 || k+n > 0x7fe, 0))
+	  return huge*__copysign(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 */
 	    {INSERT_WORDS64(x,(ix&UINT64_C(0x800fffffffffffff))|(k<<52));
 	      return x;}
diff --git a/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c b/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c
index 7f0e21f646..e183c3875f 100644
--- a/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c
+++ b/sysdeps/ieee754/dbl-64/wordsize-64/s_scalbn.c
@@ -39,11 +39,13 @@ __scalbn (double x, int n)
 	    k = ((ix >> 52) & 0x7ff) - 54;
 	    }
 	if (__builtin_expect(k==0x7ff, 0)) return x+x;	/* NaN or Inf */
-	k = k+n;
-	if (__builtin_expect(n> 50000 || k >  0x7fe, 0))
-	  return huge*__copysign(huge,x); /* overflow  */
 	if (__builtin_expect(n< -50000, 0))
 	  return tiny*__copysign(tiny,x); /*underflow*/
+	if (__builtin_expect(n> 50000 || k+n > 0x7fe, 0))
+	  return huge*__copysign(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 */
 	    {INSERT_WORDS64(x,(ix&UINT64_C(0x800fffffffffffff))|(k<<52));
 	      return x;}