Stack overflow in gmp_get_str when passed a big number

Torbjorn Granlund tg at
Fri Oct 3 09:14:45 CEST 2008

  > My Scheme compiler (Ikarus Scheme) uses gmp for its bignums.  It uses
  > gmp_get_str to convert bignums to base-10 strings.  It also crashes
  > when converting very large numbers.  I have seen the problem under a
  > Linux (2.6.18) machine with 2GB of ram, but it runs fine under OS X
  > (10.4) with the same amount of ram.  Attached is a small program that
  > exhibits the problem.  Let me know if I can provide more information
  > and please let me know if there is a workaround (other that writing
  > my own conversion routine).  Thanks.
  this is usually due to a stack overflow. Some GMP routines allocate memory
  on the stack for a better efficiency, but for large problems this may lead
  to problems. I believe this problem is fixed in the latest versions of GMP,
  or a workaround is to configure GMP with --disable-alloca. See for example
With any recent GMP release, --disable-alloca should never be needed.

Aziz doesn't mention the used GMP version, leaving us to guess it.
I guess it is GMP 4.1.x, which I no longer maintain.  :-)


More information about the gmp-bugs mailing list