Invalid read in mpz_sub

Torbjörn Granlund tg at
Thu Apr 7 08:58:13 UTC 2016

Vincent Lefevre <vincent at> writes:

  However, the GMP manual says:
  [...] Here are some examples of how to declare such integers:
       mpz_t sum;
       struct foo { mpz_t x, y; };
       mpz_t vec[20];
  and doesn't forbid to copy the structure, for instance. I think it
  would be worth to mention that using several copies of a mpz_t is
  forbidden (or a write operation invalidates the other copies),
  here or in one of the next sections (BTW, the MPFR manual should
  be clarified too).

I agree this should be made explicit; users should not need to worry
about the inner workings of our types (such as the fact that they
contain a pointer).

Would you want to contribute a patch for our manual?

(I suppose it is fine to copy our types as long as you use all copies
read-only.  Now, copying them rather than passing around a reference to
a single copy is a poor idea wrt memory use.)

Please encrypt, key id 0xC8601622

More information about the gmp-bugs mailing list