Extra zero byte converting mpz_t to a string
vincent at vinc17.net
Mon Apr 20 07:48:23 UTC 2015
On 2015-04-20 09:16:20 +0200, tg at gmplib.org wrote:
> Vincent Lefevre <vincent at vinc17.net> writes:
> Here the result is a string, and a string stops at the *first* null
> byte. If GMP writes a second null byte, then that's a bug.
> Not sure what your speculation is here.
> If you think you've found a bug, then please report it.
> Speculating about possible bugs isn't going to help.
Sorry, the OP was actually wrong: GMP does not write a second null
byte, as this can be seen by adding
s[len - 1] = '@';
before the first printf.
Now, this potentially makes the GMP manual incorrect by implying that
STR should point to a block of at least mpz_sizeinbase (OP, BASE) + 2
bytes. So, what is correct? A block of storage large enough for the
result? Or a block of at least mpz_sizeinbase (OP, BASE) + 2 bytes?
The manual doesn't say either whether the generated string can start
with a 0 digit.
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the gmp-bugs