Invalid read in mpz_sub

Miha Marolt miham at
Thu Apr 7 07:50:08 UTC 2016

On 06. 04. 2016 17:39, Torbjörn Granlund wrote:
> When passing x by value, you make copies of the two contained mpz_t
> variables, including pointers.  Then you cause reallocation of the
> original variables, making pointer your copies point to stale data.

That I know, I intentionally made it that way specifically to produce
the invalid read. If this is the intended behavior then the documentation
should clearly state that input and output function arguments should not
be copies of one another. Also the definition of mpz_t as one element
array of struct should be emphasized (not just mentioned by the way
"for interest" as in [1]) because it affects when the underlying struct
behaves as a reference type (e.g. when mpz_t is a function argument)
and when as a value type (e.g. when mpz_t is inside another struct).

Best regards,
Miha Marolt


More information about the gmp-bugs mailing list