Problem with large values in GMP...

Vincent Lefevre vincent at
Thu Mar 17 13:02:13 UTC 2016

On 2016-03-17 10:16:25 +0100, Torbjörn Granlund wrote:
> Furthermore, when using 64-bit ABIs which are LLP64 (like Windoze-64)
> the size calculation looks like it is prone to overflow.  On LP64 (as
> opposed to LLP64) machines, overflow can happen but only when asking for
> a calculation which will never fit in any computer's memory.

You mean that 32-bit limitation has been fixed on LP64 machines?
GMP 6.1.0 under Debian/amd64 still has such a limitation, as shown

#include <stdio.h>
#include <gmp.h>

int main (void)
  mpz_t u;
  int i;

  mpz_init (u);
  for (i = 30; i <= 40; i++)
      printf ("i = %d\n", i);
      mpz_realloc2 (u, 1UL << i);
  mpz_clear (u);

  return 0;

I've just reported a bug in the Debian BTS:

BTW, this is quite obvious from the mpz/realloc2.c code, due to the
use of the int type:

  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 ();

Vincent Lefèvre <vincent at> - Web: <>
100% accessible validated (X)HTML - Blog: <>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

More information about the gmp-discuss mailing list