From: Joseph Myers Date: Wed, 21 Aug 2013 19:56:48 +0000 (+0000) Subject: Fix fdim handling of infinities (bug 15797). X-Git-Tag: upstream/2.30~8798 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=acd06bb11f6d6436e15d0c7608fc7ea6008c224f;p=external%2Fglibc.git Fix fdim handling of infinities (bug 15797). --- diff --git a/ChangeLog b/ChangeLog index 86a11e3..7a39fc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2013-08-21 Joseph Myers + + [BZ #15797] + * math/s_fdim.c (__fdim): Check for infinite arguments if result + is infinite, not alongside NaN test. + * math/s_fdimf.c (__fdimf): Likewise. + * math/s_fdiml.c (__fdiml): Likewise. + * math/libm-test.inc (fdim_test_data): Add more tests. Test that + errno is unchanged. + 2013-08-21 Ondřej Bílka * argp/argp-help.c: Fix typos. diff --git a/NEWS b/NEWS index 4b79c3d..705e95f 100644 --- a/NEWS +++ b/NEWS @@ -9,7 +9,7 @@ Version 2.19 * The following bugs are resolved with this release: - 14699, 15531, 15749 + 14699, 15531, 15749, 15797 * CVE-2013-4237 The readdir_r function could write more than NAME_MAX bytes to the d_name member of struct dirent, or omit the terminating NUL diff --git a/math/libm-test.inc b/math/libm-test.inc index 25ea336..43c4a8f 100644 --- a/math/libm-test.inc +++ b/math/libm-test.inc @@ -8144,33 +8144,37 @@ fabs_test (void) static const struct test_ff_f_data fdim_test_data[] = { - TEST_ff_f (fdim, 0, 0, 0, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, 9, 0, 9, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, 0, 9, 0, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, -9, 0, 0, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, 0, -9, 9, NO_INEXACT_EXCEPTION), - - TEST_ff_f (fdim, plus_infty, 9, plus_infty, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, plus_infty, -9, plus_infty, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, minus_infty, 9, 0, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, minus_infty, -9, 0, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, 9, minus_infty, plus_infty, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, -9, minus_infty, plus_infty, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, 9, plus_infty, 0, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, -9, plus_infty, 0, NO_INEXACT_EXCEPTION), - - TEST_ff_f (fdim, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, 9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, -9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, minus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION), - TEST_ff_f (fdim, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION), - - TEST_ff_f (fdim, plus_infty, plus_infty, 0, NO_INEXACT_EXCEPTION), + TEST_ff_f (fdim, 0, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, 9, 0, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, 0, 9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, -9, 0, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, 0, -9, 9, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + + TEST_ff_f (fdim, plus_infty, 9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, plus_infty, -9, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, minus_infty, 9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, minus_infty, -9, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, 9, minus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, -9, minus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, 9, plus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, -9, plus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + + TEST_ff_f (fdim, 0, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, 9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, -9, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, qnan_value, 0, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, qnan_value, 9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, qnan_value, -9, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, plus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, minus_infty, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, qnan_value, plus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, qnan_value, minus_infty, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, qnan_value, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + + TEST_ff_f (fdim, plus_infty, plus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, plus_infty, minus_infty, plus_infty, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, minus_infty, plus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), + TEST_ff_f (fdim, minus_infty, minus_infty, 0, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED), }; static void diff --git a/math/s_fdim.c b/math/s_fdim.c index 2f97948..f8fd804 100644 --- a/math/s_fdim.c +++ b/math/s_fdim.c @@ -26,16 +26,16 @@ __fdim (double x, double y) int clsx = fpclassify (x); int clsy = fpclassify (y); - if (clsx == FP_NAN || clsy == FP_NAN - || (y < 0 && clsx == FP_INFINITE && clsy == FP_INFINITE)) - /* Raise invalid flag. */ + if (clsx == FP_NAN || clsy == FP_NAN) + /* Raise invalid flag for signaling but not quiet NaN. */ return x - y; if (x <= y) return 0.0; double r = x - y; - if (fpclassify (r) == FP_INFINITE) + if (fpclassify (r) == FP_INFINITE + && clsx != FP_INFINITE && clsy != FP_INFINITE) __set_errno (ERANGE); return r; diff --git a/math/s_fdimf.c b/math/s_fdimf.c index 03810b5..86efe6e 100644 --- a/math/s_fdimf.c +++ b/math/s_fdimf.c @@ -26,16 +26,16 @@ __fdimf (float x, float y) int clsx = fpclassify (x); int clsy = fpclassify (y); - if (clsx == FP_NAN || clsy == FP_NAN - || (y < 0 && clsx == FP_INFINITE && clsy == FP_INFINITE)) - /* Raise invalid flag. */ + if (clsx == FP_NAN || clsy == FP_NAN) + /* Raise invalid flag for signaling but not quiet NaN. */ return x - y; if (x <= y) return 0.0f; float r = x - y; - if (fpclassify (r) == FP_INFINITE) + if (fpclassify (r) == FP_INFINITE + && clsx != FP_INFINITE && clsy != FP_INFINITE) __set_errno (ERANGE); return r; diff --git a/math/s_fdiml.c b/math/s_fdiml.c index 5604532..030fcc2 100644 --- a/math/s_fdiml.c +++ b/math/s_fdiml.c @@ -26,16 +26,16 @@ __fdiml (long double x, long double y) int clsx = fpclassify (x); int clsy = fpclassify (y); - if (clsx == FP_NAN || clsy == FP_NAN - || (y < 0 && clsx == FP_INFINITE && clsy == FP_INFINITE)) - /* Raise invalid flag. */ + if (clsx == FP_NAN || clsy == FP_NAN) + /* Raise invalid flag for signaling but not quiet NaN. */ return x - y; if (x <= y) return 0.0f; long double r = x - y; - if (fpclassify (r) == FP_INFINITE) + if (fpclassify (r) == FP_INFINITE + && clsx != FP_INFINITE && clsy != FP_INFINITE) __set_errno (ERANGE); return r;