summaryrefslogtreecommitdiff
path: root/mpz
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2001-11-28 11:49:04 +0100
committertege <tege@gmplib.org>2001-11-28 11:49:04 +0100
commit01bc261e5b84d74d3ba877dad0b45783d5c8240b (patch)
treed05db61ab615bae911027dd9ff2df10f0f12dc2f /mpz
parent5c1bb7f3601d0f1c9fc0992dd1fe726b09e2bde8 (diff)
downloadgmp-01bc261e5b84d74d3ba877dad0b45783d5c8240b.tar.gz
Fix typo. Make more similar to mpz_realloc.
Diffstat (limited to 'mpz')
-rw-r--r--mpz/realloc2.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/mpz/realloc2.c b/mpz/realloc2.c
index 20f3ff1b8..9059b73e1 100644
--- a/mpz/realloc2.c
+++ b/mpz/realloc2.c
@@ -23,17 +23,22 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
void
-mpz_realloc2 (mpz_ptr x, unsigned long bits)
+mpz_realloc2 (mpz_ptr m, unsigned long bits)
{
- mp_size_t new_limbs, old_limbs;
+ mp_ptr mp;
+ mp_size_t new_alloc;
- new_limbs = (bits + BITS_PER_MP_LIMB-1) / BITS_PER_MP_LIMB;
- new_limbs = MAX (new_limbs, 1);
+ new_alloc = (bits + BITS_PER_MP_LIMB-1) / BITS_PER_MP_LIMB;
- if (ABSIZ(m) > new_limbs)
- SIZ(m) = 0;
+ /* Never allocate zero space. */
+ new_alloc = MAX (new_alloc, 1);
+
+ mp = __GMP_REALLOCATE_FUNC_LIMBS (PTR(m), ALLOC(m), new_alloc);
+ PTR(m) = mp;
+ ALLOC(m) = new_alloc;
- old_limbs = ALLOC(x);
- ALLOC(x) = new_limbs;
- PTR(x) = __GMP_REALLOCATE_FUNC_LIMBS (PTR(x), old_limbs, new_limbs);
+ /* Don't create an invalid number; if the current value doesn't fit after
+ reallocation, clear it to 0. */
+ if (ABSIZ(m) > new_alloc)
+ SIZ(m) = 0;
}