diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-04-08 15:30:45 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2015-04-08 15:30:45 +0000 |
commit | 03d2e54477d1e9d8548964db0026590889d70075 (patch) | |
tree | 7f082cb39e2d6e452953e77bfb9aa6ace5c495a4 | |
parent | f964bbd48c0373a6a41e110575669a5df79eb72d (diff) | |
download | mpfr-03d2e54477d1e9d8548964db0026590889d70075.tar.gz |
[src/sum.c] Bug fix: use MPFR_EXP instead of MPFR_SET_EXP to set the
exponent since it can be outside the current exponent range before
it is checked with mpfr_check_range. Also added a static assertion
(always satisfied in practice) to make sure that exponent related
computations cannot yield an integer overflow.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/new-sum@9362 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/sum.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -435,6 +435,10 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, MPFR_ASSERTD (rn >= 3 && rn <= n); + /* In practice, no integer overflow on the exponent. */ + MPFR_STAT_STATIC_ASSERT (MPFR_EXP_MAX - MPFR_EMAX_MAX >= + sizeof (unsigned long) * CHAR_BIT); + /* Set up some variables and the accumulator. */ sump = MPFR_MANT (sum); @@ -1023,7 +1027,9 @@ sum_aux (mpfr_ptr sum, mpfr_ptr *const x, unsigned long n, mpfr_rnd_t rnd, MPFR_ASSERTD (MPFR_LIMB_MSB (sump[sn-1]) != 0); MPFR_LOG_MSG (("Set exponent e=%" MPFR_EXP_FSPEC "d\n", (mpfr_eexp_t) e)); - MPFR_SET_EXP (sum, e); + /* e may be outside the current exponent range, but this will be checked + with mpfr_check_range below. */ + MPFR_EXP (sum) = e; } /* main block */ MPFR_TMP_FREE (marker); |