mpz_limbs_modify doesn't clear new limbs
Ivo maffei
ivomaffei at gmail.com
Thu Jan 2 10:31:55 CET 2025
Hi everyone,
I found some unexpected(?) behaviour with mpz_limbs_modify, but after
looking at the code, I'm no longer sure what the expected behaviour is.
According to the GMP manual, the function should return an array holding
the absolute value of the input. However, the code doesn't seem to work
that way.
If reallocation is needed, the stdlib realloc function is used (if I
understand correctly). As per specifications, the new allocated blocks are
undefined (https://en.cppreference.com/w/c/memory/realloc).
If reallocation is not needed, the pointer to the underlying limbs array is
returned even if the mpz_t was not using all limbs (abs(_mp_size) <
_mp_alloc).
In both cases, the most significant limb might not be zero.
So, is this a bug or mpz_limbs_modify was never meant to zero the new limbs?
Thanks,
Ivo
More information about the gmp-discuss
mailing list