diff options
author | Torbjorn Granlund <tege@gmplib.org> | 2014-01-19 13:04:21 +0100 |
---|---|---|
committer | Torbjorn Granlund <tege@gmplib.org> | 2014-01-19 13:04:21 +0100 |
commit | 6138b90d3b87d4c98d8d4694b27a0538b7e70855 (patch) | |
tree | 6977fd09c0e4965e42ae2260946dd09681054823 /mpz/array_init.c | |
parent | 059d0c5f2e51478289d199299a85a2379522e07d (diff) | |
download | gmp-6138b90d3b87d4c98d8d4694b27a0538b7e70855.tar.gz |
Avoid two overflow scenarios in allocation computation.
Diffstat (limited to 'mpz/array_init.c')
-rw-r--r-- | mpz/array_init.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/mpz/array_init.c b/mpz/array_init.c index 285cf9573..b7f00599f 100644 --- a/mpz/array_init.c +++ b/mpz/array_init.c @@ -23,12 +23,12 @@ along with the GNU MP Library. If not, see https://www.gnu.org/licenses/. */ void mpz_array_init (mpz_ptr arr, mp_size_t arr_size, mp_size_t nbits) { - register mp_ptr p; - register mp_size_t i; + mp_ptr p; + mp_size_t i; mp_size_t nlimbs; - nlimbs = (nbits + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS; - p = (mp_ptr) (*__gmp_allocate_func) (arr_size * nlimbs * BYTES_PER_MP_LIMB); + nlimbs = nbits / GMP_NUMB_BITS + 1; + p = (mp_ptr) (*__gmp_allocate_func) ((size_t) arr_size * nlimbs * BYTES_PER_MP_LIMB); for (i = 0; i < arr_size; i++) { |