summary refs log tree commit diff
path: root/sysdeps/ieee754/flt-32
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/flt-32
parent07e12bb391ae84eb74817d42feda42cff7f687e5 (diff)
downloadglibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.gz
glibc-a6d06d7b86f724046b462115556d0df682f9f703.tar.xz
glibc-a6d06d7b86f724046b462115556d0df682f9f703.zip
Fix scalbn, scalbln integer overflow.
Diffstat (limited to 'sysdeps/ieee754/flt-32')
-rw-r--r--sysdeps/ieee754/flt-32/s_scalblnf.c8
-rw-r--r--sysdeps/ieee754/flt-32/s_scalbnf.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/sysdeps/ieee754/flt-32/s_scalblnf.c b/sysdeps/ieee754/flt-32/s_scalblnf.c
index 5256c32592..2a2d7ab651 100644
--- a/sysdeps/ieee754/flt-32/s_scalblnf.c
+++ b/sysdeps/ieee754/flt-32/s_scalblnf.c
@@ -35,11 +35,13 @@ __scalblnf (float x, long int n)
 	    k = ((ix&0x7f800000)>>23) - 25;
 	    }
 	if (__builtin_expect(k==0xff, 0)) return x+x;	/* NaN or Inf */
-	k = k+n;
-	if (__builtin_expect(n> 50000 || k >  0xfe, 0))
-	  return huge*copysignf(huge,x); /* overflow  */
 	if (__builtin_expect(n< -50000, 0))
 	  return tiny*copysignf(tiny,x);	/*underflow*/
+	if (__builtin_expect(n> 50000 || k+n > 0xfe, 0))
+	  return huge*copysignf(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_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
 	if (k <= -25)
diff --git a/sysdeps/ieee754/flt-32/s_scalbnf.c b/sysdeps/ieee754/flt-32/s_scalbnf.c
index 3be2925a03..a7cb1a1a49 100644
--- a/sysdeps/ieee754/flt-32/s_scalbnf.c
+++ b/sysdeps/ieee754/flt-32/s_scalbnf.c
@@ -35,11 +35,13 @@ __scalbnf (float x, int n)
 	    k = ((ix&0x7f800000)>>23) - 25;
 	    }
 	if (__builtin_expect(k==0xff, 0)) return x+x;	/* NaN or Inf */
-	k = k+n;
-	if (__builtin_expect(n> 50000 || k >  0xfe, 0))
-	  return huge*__copysignf(huge,x); /* overflow  */
 	if (__builtin_expect(n< -50000, 0))
 	  return tiny*__copysignf(tiny,x);	/*underflow*/
+	if (__builtin_expect(n> 50000 || k+n > 0xfe, 0))
+	  return huge*__copysignf(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_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
 	if (k <= -25)