]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix scalb spurious "invalid" exceptions (bug 16770).
authorJoseph Myers <joseph@codesourcery.com>
Sat, 29 Mar 2014 17:22:14 +0000 (17:22 +0000)
committerJoseph Myers <joseph@codesourcery.com>
Sat, 29 Mar 2014 17:22:14 +0000 (17:22 +0000)
This patch fixes bug 16770, spurious "invalid" exceptions from scalb
when testing whether the second argument is an integer, by inserting
appropriate range checks to determine whether a cast to int is safe.
(Note that invalid_fn is a function that handles both nonintegers and
large integers, distinguishing them reliably using functions such as
__rint; note also that there are no issues with scalb needing to avoid
spurious "inexact" exceptions - it's an old-POSIX XSI function, not a
standard C function bound to an IEEE 754 operation - although the
return value is still fully determined.)

Tested x86_64 and x86.

[BZ #16770]
* math/e_scalb.c (__ieee754_scalb): Check second argument is not
too large before casting to int.
* math/e_scalbf.c (__ieee754_scalbf): Likewise.
* math/e_scalbl.c (__ieee754_scalbl): Likewise.
* math/libm-test.inc (scalb_test_data): Add more tests.

ChangeLog
NEWS
math/e_scalb.c
math/e_scalbf.c
math/e_scalbl.c
math/libm-test.inc

index 081bf0b6d6c201e4fb956f2dd0e4b57fbf65bc3b..5bb69dc0b264962dee6d1c0ee8b1e9e97a01e0d6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2014-03-29  Joseph Myers  <joseph@codesourcery.com>
+
+       [BZ #16770]
+       * math/e_scalb.c (__ieee754_scalb): Check second argument is not
+       too large before casting to int.
+       * math/e_scalbf.c (__ieee754_scalbf): Likewise.
+       * math/e_scalbl.c (__ieee754_scalbl): Likewise.
+       * math/libm-test.inc (scalb_test_data): Add more tests.
+
 2014-03-29  Siddhesh Poyarekar  <siddhesh@redhat.com>
 
        * benchtests/Makefile (DETAILED_OPT): New make option.
diff --git a/NEWS b/NEWS
index b34c9fc65ec355605ebd219ee0531502388f9a5b..9597cbdb24d7aa306d33b2557720b35425aec402 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,7 @@ Version 2.20
   16532, 16545, 16574, 16599, 16600, 16609, 16610, 16611, 16613, 16623,
   16632, 16634, 16639, 16642, 16649, 16670, 16674, 16677, 16680, 16683,
   16689, 16695, 16701, 16706, 16707, 16712, 16713, 16714, 16731, 16743,
-  16758, 16759, 16760.
+  16758, 16759, 16760, 16770.
 
 * Running the testsuite no longer terminates as soon as a test fails.
   Instead, a file tests.sum (xtests.sum from "make xcheck") is generated,
index bddedfa0320409ab7b467d029aa53f550ac9f469..146d49e1c301dfe793a8c1717e61a3ecebba1072 100644 (file)
@@ -50,7 +50,7 @@ __ieee754_scalb (double x, double fn)
        return x;
       return x / -fn;
     }
-  if (__glibc_unlikely ((double) (int) fn != fn))
+  if (__glibc_unlikely (fabs (fn) >= 0x1p31 || (double) (int) fn != fn))
     return invalid_fn (x, fn);
 
   return __scalbn (x, (int) fn);
index 319752c993f34981983e38eeef04953f16352c52..3f2e853353fa7b3ee6ed475e7fd1b214652f34f0 100644 (file)
@@ -50,7 +50,7 @@ __ieee754_scalbf (float x, float fn)
        return x;
       return x / -fn;
     }
-  if (__glibc_unlikely ((float) (int) fn != fn))
+  if (__glibc_unlikely (fabsf (fn) >= 0x1p31f || (float) (int) fn != fn))
     return invalid_fn (x, fn);
 
   return __scalbnf (x, (int) fn);
index 5815a0d67b92c9cbecd4be67a1b282fa9daa16e7..739db7a188b617e884725da9fd88b98dcbdd2b08 100644 (file)
@@ -50,7 +50,7 @@ __ieee754_scalbl (long double x, long double fn)
        return x;
       return x / -fn;
     }
-  if (__glibc_unlikely ((long double) (int) fn != fn))
+  if (__glibc_unlikely (fabsl (fn) >= 0x1p31L || (long double) (int) fn != fn))
     return invalid_fn (x, fn);
 
   return __scalbnl (x, (int) fn);
index cefcb9682af21107548443cd770716acf02adec6..0eff34a0cab886269d723c91e2419f928800d836 100644 (file)
@@ -9134,6 +9134,23 @@ static const struct test_ff_f_data scalb_test_data[] =
     TEST_ff_f (scalb, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION),
     TEST_ff_f (scalb, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION),
 
+    TEST_ff_f (scalb, max_value, max_value, plus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, max_value, -max_value, plus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, 1, max_value, plus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, 1, -max_value, plus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, min_value, max_value, plus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, min_value, -max_value, plus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, min_subnorm_value, max_value, plus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, min_subnorm_value, -max_value, plus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -max_value, max_value, minus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -max_value, -max_value, minus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -1, max_value, minus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -1, -max_value, minus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -min_value, max_value, minus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -min_value, -max_value, minus_uflow, UNDERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -min_subnorm_value, max_value, minus_oflow, OVERFLOW_EXCEPTION),
+    TEST_ff_f (scalb, -min_subnorm_value, -max_value, minus_uflow, UNDERFLOW_EXCEPTION),
+
     TEST_ff_f (scalb, 0.8L, 4, 12.8L),
     TEST_ff_f (scalb, -0.854375L, 5, -27.34L),
   };