top(1): Raise WARNS to 6 and fix warnings.
[dragonfly.git] / contrib / gmp / mpz / realloc.c
blob0a6d1638a50cc15769dc153df3a781d0429be18f
1 /* _mpz_realloc -- make the mpz_t have NEW_ALLOC digits allocated.
3 Copyright 1991, 1993, 1994, 1995, 2000, 2001, 2008 Free Software Foundation,
4 Inc.
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/. */
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "gmp.h"
24 #include "gmp-impl.h"
26 void *
27 _mpz_realloc (mpz_ptr m, mp_size_t new_alloc)
29 mp_ptr mp;
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");
39 abort ();
42 else
44 if (UNLIKELY (new_alloc > INT_MAX))
46 fprintf (stderr, "gmp: overflow in mpz type\n");
47 abort ();
51 mp = __GMP_REALLOCATE_FUNC_LIMBS (PTR(m), ALLOC(m), new_alloc);
52 PTR(m) = mp;
53 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)
58 SIZ(m) = 0;
60 return (void *) mp;