Extra zero byte converting mpz_t to a string

Niels Möller nisse at lysator.liu.se
Mon Apr 20 09:35:59 UTC 2015


Hans Aberg <haberg-1 at telia.com> writes:

> Right, but you would not would want to compute it if the current
> free_function() does not use it.

If that matters, I'd suggest allocating it before invoking mpz_get_str.
If you pass NULL to mpz_get_str, you also have the cost that it may do a
pretty useless reallocation to shrink the area from strlen(s)+2 to
strlen()+1, in case the initial allocation, based on mpz_sizeinbase,
returned a one-off size.

That said, I'd prefer to remove the size argument fom the free function and
the old size argument for the realloc function. But that's an interface
change (see https://gmplib.org/devel/incompatibility.html).

Regards,
/Niels

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


More information about the gmp-bugs mailing list