Upstream patch to remove abort() that occur during memory overflow

Marco Bodrato bodrato at
Sun Sep 13 07:47:06 UTC 2020


Il 2020-09-03 19:22 nisse at ha scritto:
> Mustafa Mohamad <mus-m at> writes:
>> Currently GMP aborts which sends SIGBART and forcibly aborts Julia or 
>> any linked program. With the above patch,  GMP will instead throw a  
>> Instead of forcibly aborting
> Hi, I understand aborting may be undesirable, but can you provide a bit
> more context. How do you handle the callback on overflow? If you 
> longjmp
> out, how do you arrange so that your mpz variables are in a consistent
> state?

I believe that a "safe" mpz type, is anyway difficult to obtain. We may 
say that if the result is outside of the range supported by mpz, the 
behavior is undefined.

Try the following code on a Linux or BSD system.

main (int argc, char *argv[])
   unsigned long b, e;
   mpz_t p;
   mpz_init (p);

   b = 1;
   b <<= 24;
   e = ~0UL / 24 + 1;

   mpz_ui_pow_ui (p, b, e);

   gmp_printf ("%lu ^ %lu = %Zd", b, e, p);
   mpz_clear (p);

   return 0;

With ABI=64 I get:
16777216 ^ 768614336404564651 = 256

With ABI=32 I get:
16777216 ^ 178956971 = 256

Not a signal, nor an abort, simply an incorrect result :-)

Anyway this patch might be a way to give a little bit more control to 
the programs using the library...


More information about the gmp-bugs mailing list