diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-03-23 15:13:34 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2020-03-23 15:13:34 +0000 |
commit | fd5d3140011f0503c614b411a2e90c28c169092d (patch) | |
tree | c0c1ff0cda5bb54ac94adff4679ea79e8e373793 | |
parent | de89f191e6e8a49ffe8c5caf49f6b6ac16d249f7 (diff) | |
download | mpfr-fd5d3140011f0503c614b411a2e90c28c169092d.tar.gz |
[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
-rw-r--r-- | src/sub1.c | 9 |
1 files changed, 9 insertions, 0 deletions
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, |