summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2004-09-24 14:53:05 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2004-09-24 14:53:05 +0000
commit4b137a392d8a23fb2fa1c5d8d3cb2c0bf53b0e54 (patch)
tree5a9f48b3030c9e82957a3e670adc92ca00162085
parent60c3767464b629370f8baf53a198ca13adffc0c1 (diff)
downloadmpfr-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.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/get_si.c b/get_si.c
index 845b08ea5..fd55f29eb 100644
--- a/get_si.c
+++ b/get_si.c
@@ -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);