"Cannot reallocate memory" error after calling mpz_inp_raw()

Torbjörn Granlund tg at gmplib.org
Mon Jul 18 12:06:57 UTC 2016

Paul Lou <paul96lou at gmail.com> writes:

  I'm running into "GMP MP: Cannot reallocate memory (old_size=8
  in gmp-6.1.0/memory.c with an errno of 12 meaning "out of memory" when I
  call mpz_inp_raw() on large integers which I wrote out with mpz_out_raw().
  I've tampered with mpz_inp_raw() and out_raw() and the mpz struct itself so
  mpz's can successfully hold 64-bit values (breaking portability), and
  writing out the integer with mpz_out_raw() seems fine, but when I try to
  read it back in, it fails due to the reallocate error. The reallocation
  error does not occur on smaller integers.
OK, so you've modified the mpz struct and the functions which now
misbehave.  And now you're asking us what might be the error in your
private code.  You assume that we have wizard powers, but we are
actually just plain programmers.  :-)

Why don't you run your modified code in a debugger, or alternatively
instrument it with telling print statements?

Please encrypt, key id 0xC8601622

More information about the gmp-discuss mailing list