diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-06-26 01:02:26 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2014-06-26 01:02:26 +0000 |
commit | b19a82e0c918e8786702ceaad07760bd9436479b (patch) | |
tree | aeef501826ba7ae134eaf69b6fa80c467b381a10 | |
parent | b64863635c59b9dec38120e1467ee093e3999baa (diff) | |
download | mpfr-b19a82e0c918e8786702ceaad07760bd9436479b.tar.gz |
[src/div.c] Bug fix: avoid integer overflow in the code added in r9086
(now tdiv no longer fails).
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@9107 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/div.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -366,7 +366,13 @@ mpfr_div (mpfr_ptr q, mpfr_srcptr u, mpfr_srcptr v, mpfr_rnd_t rnd_mode) MPFR_CHANGE_SIGN(q); } /* q did not under/overflow */ - MPFR_EXP(q) -= exp_v - GMP_NUMB_BITS; + MPFR_EXP(q) -= exp_v; + /* The following test is needed, otherwise the next addition + on the exponent may overflow, e.g. when dividing the + largest finite MPFR number by the smallest positive one. */ + if (MPFR_UNLIKELY (MPFR_EXP(q) > __gmpfr_emax - GMP_NUMB_BITS)) + return mpfr_overflow (q, rnd_mode, MPFR_SIGN(q)); + MPFR_EXP(q) += GMP_NUMB_BITS; return mpfr_check_range (q, inex, rnd_mode); } |