From fd5d3140011f0503c614b411a2e90c28c169092d Mon Sep 17 00:00:00 2001 From: vlefevre Date: Mon, 23 Mar 2020 15:13:34 +0000 Subject: [src/sub1.c] Detect an underflow case (before the main detection) to avoid a possible integer overflow with UBF. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13798 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/sub1.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sub1.c b/src/sub1.c index 272709acc..41deef381 100644 --- a/src/sub1.c +++ b/src/sub1.c @@ -674,6 +674,15 @@ mpfr_sub1 (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode) if (MPFR_LIKELY(cancel)) { cancel -= add_exp; /* OK: add_exp is an int equal to 0 or 1 */ + MPFR_ASSERTD (cancel >= 0); + /* Detect an underflow case to avoid a possible integer overflow + with UBF in the computation of exp_a. */ + 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)); + } exp_a = exp_b - cancel; /* The following assertion corresponds to a limitation of the MPFR implementation. It may fail with a 32-bit ABI and huge precisions, -- cgit v1.2.1