Stack overflow in gmp_get_str when passed a big number

Paul Zimmermann Paul.Zimmermann at loria.fr
Fri Oct 3 09:00:46 CEST 2008


       Dear Aziz,

> 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
http://gmplib.org/manual/Debugging.html.

Paul Zimmermann


More information about the gmp-bugs mailing list