Problems with mpz_set_str and huge strings

Torbjorn Granlund tg at gmplib.org
Sun Jul 5 21:37:06 CEST 2009


Stefan Krah <stefan-usenet at bytereef.org> writes:

  I'm having memory corruption problems when using mpz_set_str for some huge
  strings. Valgrind tracks down the problem to an invalid write in __gmpn_sub_n.
  
GMP only supports numbers of 2^31-1 bits or less on a 32-bit computer.
Your number is greater than that.
  
Of course, GMP should catch oversize operands, print an error message
and abort.  It does that for most overflows (starting with GMP 4.3) but
unfortunately not all.  The difficulty is detecting overflow without
adding overhead.

I assume you have tried larger and larger conversions until you ran into
this limitation?  Your operands are just slightly above what GMP can
handle, which make sens if you gradually increased your operands.

-- 
Torbjörn


More information about the gmp-bugs mailing list