summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-03-24 15:32:22 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-03-24 15:32:22 +0000
commit610e574fc2bf49bcf6a7f98f0fe6513fd24652e2 (patch)
tree45e3444b947a9a7c9eee6c36fb73fc92212ef67b
parentb523c7635a6e15f474d67ae9ce044a907dde0b5a (diff)
downloadmpfr-610e574fc2bf49bcf6a7f98f0fe6513fd24652e2.tar.gz
[src/sub1.c] If exp_b = MPFR_EXP_MIN, an integer overflow may occur in
the "MAX (aq, bq) + 2 <= diff_exp" branch. This is possible only with UBF. Fixed this bug with an early underflow detection in the UBF case. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13806 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r--src/sub1.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/sub1.c b/src/sub1.c
index 78458a0db..0256e43cd 100644
--- a/src/sub1.c
+++ b/src/sub1.c
@@ -96,6 +96,15 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
if (MPFR_UNLIKELY (MPFR_IS_UBF (b) || MPFR_IS_UBF (c)))
{
exp_b = MPFR_UBF_GET_EXP (b);
+ /* Early underflow detection. Rare, but a test is needed anyway
+ since in the "MAX (aq, bq) + 2 <= diff_exp" branch, the exponent
+ may decrease and MPFR_EXP_MIN would yield an integer overflow. */
+ if (MPFR_UNLIKELY (exp_b < __gmpfr_emin - 1))
+ {
+ if (rnd_mode == MPFR_RNDN)
+ rnd_mode = MPFR_RNDZ;
+ return mpfr_underflow (a, rnd_mode, MPFR_SIGN(a));
+ }
diff_exp = mpfr_ubf_diff_exp (b, c);
MPFR_LOG_MSG (("UBF: exp_b=%" MPFR_EXP_FSPEC "d%s "
"diff_exp=%" MPFR_EXP_FSPEC "d%s\n",