diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2016-12-28 18:30:06 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2016-12-28 18:30:06 +0100 |
commit | 5be2628723ae383653823a56c8d5a4165b25065e (patch) | |
tree | 5833842d39ab3d35de3748cb02ed4a753ca496a5 /mpz/tdiv_r.c | |
parent | 384d404241fb2a9f30263a17eb1692cd8095711d (diff) | |
download | gmp-5be2628723ae383653823a56c8d5a4165b25065e.tar.gz |
mpz/tdiv_r.c: Avoid allocating too much space in some corner-case conditions
Diffstat (limited to 'mpz/tdiv_r.c')
-rw-r--r-- | mpz/tdiv_r.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/mpz/tdiv_r.c b/mpz/tdiv_r.c index fe38f1ca0..c76275e53 100644 --- a/mpz/tdiv_r.c +++ b/mpz/tdiv_r.c @@ -36,32 +36,32 @@ void mpz_tdiv_r (mpz_ptr rem, mpz_srcptr num, mpz_srcptr den) { mp_size_t ql; - mp_size_t ns, ds, nl, dl; + mp_size_t ns, nl, dl; mp_ptr np, dp, qp, rp; TMP_DECL; ns = SIZ (num); - ds = SIZ (den); nl = ABS (ns); - dl = ABS (ds); + dl = ABSIZ (den); ql = nl - dl + 1; if (UNLIKELY (dl == 0)) DIVIDE_BY_ZERO; - rp = MPZ_REALLOC (rem, dl); - if (ql <= 0) { if (num != rem) { + SIZ (rem) = ns; + rp = MPZ_NEWALLOC (rem, nl); np = PTR (num); MPN_COPY (rp, np, nl); - SIZ (rem) = SIZ (num); } return; } + rp = MPZ_REALLOC (rem, dl); + TMP_MARK; qp = TMP_ALLOC_LIMBS (ql); np = PTR (num); |