diff options
author | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2021-12-12 14:24:10 +0100 |
---|---|---|
committer | Marco Bodrato <bodrato@mail.dm.unipi.it> | 2021-12-12 14:24:10 +0100 |
commit | 650368f11361f45af429cac9690c9d85885d765c (patch) | |
tree | 06411f3152ec58173e1bd8fb0d6327f68ad3f78f | |
parent | 5ea34d9f6fd6ebe37653ea64dac820e05cb160d5 (diff) | |
download | gmp-650368f11361f45af429cac9690c9d85885d765c.tar.gz |
Handle overflow in mpz_type through errno.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | errno.c | 7 | ||||
-rw-r--r-- | gmp-h.in | 6 | ||||
-rw-r--r-- | gmp-impl.h | 4 | ||||
-rw-r--r-- | mpz/init2.c | 7 | ||||
-rw-r--r-- | mpz/realloc.c | 12 | ||||
-rw-r--r-- | mpz/realloc2.c | 7 |
7 files changed, 34 insertions, 23 deletions
@@ -1,3 +1,17 @@ +2021-12-11 Marco Bodrato <bodrato@mail.dm.unipi.it> + + * mpn/generic/toom3_sqr.c: Use a shorter mul when it's simple. + * mpn/generic/toom4_sqr.c: Likewise. + * mpn/generic/toom33_mul.c: Likewise. + * mpn/generic/toom44_mul.c: Likewise. + + * gmp-h.in (GMP_ERROR_MPZ_OVERFLOW): New enum value. + * errno.c (__gmp_overflow_in_mpz): New function. + * gmp-impl.h (MPZ_OVERFLOW): New macro calling it. + * mpz/init2.c: Use the new macro to rise the overflow error. + * mpz/realloc.c: Likewise. + * mpz/realloc2.c: Likewise. + 2021-11-02 Torbjörn Granlund <tg@gmplib.org> * mpn/s390_64/sec_tabselect.asm: Rewrite. @@ -4,7 +4,7 @@ ONLY. THEY'RE ALMOST CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN FUTURE GNU MP RELEASES. -Copyright 2000, 2001, 2003 Free Software Foundation, Inc. +Copyright 2000, 2001, 2003, 2021 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -70,3 +70,8 @@ __gmp_divide_by_zero (void) { __gmp_exception (GMP_ERROR_DIVISION_BY_ZERO); } +void +__gmp_overflow_in_mpz (void) +{ + __gmp_exception (GMP_ERROR_MPZ_OVERFLOW); +} @@ -1,6 +1,7 @@ /* Definitions for GNU multiple precision functions. -*- mode: c -*- -Copyright 1991, 1993-1997, 1999-2016, 2020 Free Software Foundation, Inc. +Copyright 1991, 1993-1997, 1999-2016, 2020, 2021 Free Software +Foundation, Inc. This file is part of the GNU MP Library. @@ -2325,7 +2326,8 @@ enum GMP_ERROR_UNSUPPORTED_ARGUMENT = 1, GMP_ERROR_DIVISION_BY_ZERO = 2, GMP_ERROR_SQRT_OF_NEGATIVE = 4, - GMP_ERROR_INVALID_ARGUMENT = 8 + GMP_ERROR_INVALID_ARGUMENT = 8, + GMP_ERROR_MPZ_OVERFLOW = 16 }; /* Define CC and CFLAGS which were used to build this version of GMP */ diff --git a/gmp-impl.h b/gmp-impl.h index 2b6d7e9e9..60d7ee345 100644 --- a/gmp-impl.h +++ b/gmp-impl.h @@ -3,7 +3,7 @@ THE CONTENTS OF THIS FILE ARE FOR INTERNAL USE AND ARE ALMOST CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES IN FUTURE GNU MP RELEASES. -Copyright 1991-2018 Free Software Foundation, Inc. +Copyright 1991-2018, 2021 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -3925,10 +3925,12 @@ __GMP_DECLSPEC extern const int __gmp_0; __GMP_DECLSPEC void __gmp_exception (int) ATTRIBUTE_NORETURN; __GMP_DECLSPEC void __gmp_divide_by_zero (void) ATTRIBUTE_NORETURN; __GMP_DECLSPEC void __gmp_sqrt_of_negative (void) ATTRIBUTE_NORETURN; +__GMP_DECLSPEC void __gmp_overflow_in_mpz (void) ATTRIBUTE_NORETURN; __GMP_DECLSPEC void __gmp_invalid_operation (void) ATTRIBUTE_NORETURN; #define GMP_ERROR(code) __gmp_exception (code) #define DIVIDE_BY_ZERO __gmp_divide_by_zero () #define SQRT_OF_NEGATIVE __gmp_sqrt_of_negative () +#define MPZ_OVERFLOW __gmp_overflow_in_mpz () #if defined _LONG_LONG_LIMB #define CNST_LIMB(C) ((mp_limb_t) C##LL) diff --git a/mpz/init2.c b/mpz/init2.c index fcbaa66db..3133f60ab 100644 --- a/mpz/init2.c +++ b/mpz/init2.c @@ -1,6 +1,6 @@ /* mpz_init2 -- initialize mpz, with requested size in bits. -Copyright 2001, 2002, 2008 Free Software Foundation, Inc. +Copyright 2001, 2002, 2008, 2021 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -43,10 +43,7 @@ mpz_init2 (mpz_ptr x, mp_bitcnt_t bits) if (sizeof (unsigned long) > sizeof (int)) /* param vs _mp_size field */ { if (UNLIKELY (new_alloc > INT_MAX)) - { - fprintf (stderr, "gmp: overflow in mpz type\n"); - abort (); - } + MPZ_OVERFLOW; } PTR(x) = __GMP_ALLOCATE_FUNC_LIMBS (new_alloc); diff --git a/mpz/realloc.c b/mpz/realloc.c index bb55bf683..184fdf8c9 100644 --- a/mpz/realloc.c +++ b/mpz/realloc.c @@ -1,6 +1,6 @@ /* _mpz_realloc -- make the mpz_t have NEW_ALLOC digits allocated. -Copyright 1991, 1993-1995, 2000, 2001, 2008, 2015 Free Software +Copyright 1991, 1993-1995, 2000, 2001, 2008, 2015, 2021 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -44,18 +44,12 @@ _mpz_realloc (mpz_ptr m, mp_size_t new_alloc) if (sizeof (mp_size_t) == sizeof (int)) { if (UNLIKELY (new_alloc > ULONG_MAX / GMP_NUMB_BITS)) - { - fprintf (stderr, "gmp: overflow in mpz type\n"); - abort (); - } + MPZ_OVERFLOW; } else { if (UNLIKELY (new_alloc > INT_MAX)) - { - fprintf (stderr, "gmp: overflow in mpz type\n"); - abort (); - } + MPZ_OVERFLOW; } if (ALLOC (m) == 0) diff --git a/mpz/realloc2.c b/mpz/realloc2.c index 535033942..9fa3a7578 100644 --- a/mpz/realloc2.c +++ b/mpz/realloc2.c @@ -1,6 +1,6 @@ /* mpz_realloc2 -- change allocated data size. -Copyright 2001, 2002, 2008, 2015 Free Software Foundation, Inc. +Copyright 2001, 2002, 2008, 2015, 2021 Free Software Foundation, Inc. This file is part of the GNU MP Library. @@ -43,10 +43,7 @@ mpz_realloc2 (mpz_ptr m, mp_bitcnt_t bits) if (sizeof (unsigned long) > sizeof (int)) /* param vs _mp_size field */ { if (UNLIKELY (new_alloc > INT_MAX)) - { - fprintf (stderr, "gmp: overflow in mpz type\n"); - abort (); - } + MPZ_OVERFLOW; } if (ALLOC (m) == 0) |