Lazy mpz allocation

Niels Möller nisse at
Mon Aug 31 19:16:34 UTC 2015

tg at (Torbjörn Granlund) writes:

> (We should use 'attribute ((visibility ("hidden")))' for the the
> constant zero limbs at any rate.  I'll commit a basic patch for that
> soonish.)

Maybe it should have a more interesting value than zero, to help catch
bugs if it is used when it shouldn't. And when running valgrind, it
could be explicitly marked as readable but undefined, to generate
valgrind warnings if any branch or memory access depends on the value.

It's tempting to try to rely on it being zero, like eliminating the
_mp_size != 0 test in mpz_odd_p, but that's broken unless all code that
may assign zero to _mp_size makes sure that _mp_size == 0 implies
_mp_d[0] == 0, which I doubt is a good idea.


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list