1 /* _mpz_realloc -- make the mpz_t have NEW_ALLOC digits allocated.
3 Copyright 1991, 1993, 1994, 1995, 2000, 2001, 2008 Free Software Foundation,
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
27 _mpz_realloc (mpz_ptr m, mp_size_t new_alloc)
31 /* Never allocate zero space. */
32 new_alloc = MAX (new_alloc, 1);
34 if (sizeof (mp_size_t) == sizeof (int))
36 if (UNLIKELY (new_alloc > ULONG_MAX / GMP_NUMB_BITS))
38 fprintf (stderr, "gmp: overflow in mpz type\n");
44 if (UNLIKELY (new_alloc > INT_MAX))
46 fprintf (stderr, "gmp: overflow in mpz type\n");
51 mp = __GMP_REALLOCATE_FUNC_LIMBS (PTR(m), ALLOC(m), new_alloc);
55 /* Don't create an invalid number; if the current value doesn't fit after
56 reallocation, clear it to 0. */
57 if (ABSIZ(m) > new_alloc)