diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-24 14:53:05 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2004-09-24 14:53:05 +0000 |
commit | 4b137a392d8a23fb2fa1c5d8d3cb2c0bf53b0e54 (patch) | |
tree | 5a9f48b3030c9e82957a3e670adc92ca00162085 | |
parent | 60c3767464b629370f8baf53a198ca13adffc0c1 (diff) | |
download | mpfr-4b137a392d8a23fb2fa1c5d8d3cb2c0bf53b0e54.tar.gz |
Fixed integer overflow.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2992 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | get_si.c | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -28,8 +28,6 @@ mpfr_get_si (mpfr_srcptr f, mp_rnd_t rnd) mp_prec_t prec; long s; mpfr_t x; - mp_size_t n; - mp_exp_t exp; if (!mpfr_fits_slong_p (f, rnd) || MPFR_IS_ZERO(f)) return (long) 0; @@ -46,11 +44,15 @@ mpfr_get_si (mpfr_srcptr f, mp_rnd_t rnd) s = 0; else { + mp_limb_t a; + mp_size_t n; + mp_exp_t exp; + /* now the result is in the most significant limb of x */ exp = MPFR_GET_EXP (x); /* since |x| >= 1, exp >= 1 */ n = MPFR_LIMB_SIZE(x); - s = MPFR_MANT(x)[n - 1] >> (BITS_PER_MP_LIMB - exp); - s *= MPFR_SIGN(f); + a = MPFR_MANT(x)[n - 1] >> (BITS_PER_MP_LIMB - exp); + s = MPFR_SIGN(f) > 0 ? a : a <= LONG_MAX ? - (long) a : LONG_MIN; } mpfr_clear (x); |