diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2012-03-08 14:11:02 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2012-03-08 14:11:02 +0000 |
commit | 5ed9d0b72b6abb1f49ae5faec20042cb371a8f30 (patch) | |
tree | d5ea8b8368259678003d4ebea1890680e9975a6c /src/round_prec.c | |
parent | 04037a85b152525d13026c3ff450f01aab1bbd82 (diff) | |
download | mpfr-5ed9d0b72b6abb1f49ae5faec20042cb371a8f30.tar.gz |
Avoid potential integer overflows and improve consistency. This should
fix bug #13918 "Segfault with precision = MPFR_PREC_MAX on 32-bit".
Note: this problem appeared in MPFR 3.0.0 when the precision type (now
mpfr_prec_t) was changed to a signed integer.
Added a large precision test in tests/tinits.c (enabled by setting
MPFR_CHECK_LARGEMEM=1) to trigger the bug mentioned above on 32-bit
machines (or when MPFR is built with -m32).
(merged changesets r8025,8026,8029,8031,8077 from the trunk)
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/3.1@8080 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/round_prec.c')
-rw-r--r-- | src/round_prec.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/round_prec.c b/src/round_prec.c index baebeb0ee..cf27d76e3 100644 --- a/src/round_prec.c +++ b/src/round_prec.c @@ -55,12 +55,12 @@ mpfr_prec_round (mpfr_ptr x, mpfr_prec_t prec, mpfr_rnd_t rnd_mode) MPFR_ASSERTN(prec >= MPFR_PREC_MIN && prec <= MPFR_PREC_MAX); - nw = 1 + (prec - 1) / GMP_NUMB_BITS; /* needed allocated limbs */ + nw = MPFR_PREC2LIMBS (prec); /* needed allocated limbs */ /* check if x has enough allocated space for the significand */ /* Get the number of limbs from the precision. (Compatible with all allocation methods) */ - ow = (MPFR_PREC (x) + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS; + ow = MPFR_LIMB_SIZE (x); if (nw > ow) { /* FIXME: Variable can't be created using custom allocation, |