-
Notifications
You must be signed in to change notification settings - Fork 216
Closed
Labels
Description
Currently, mp_fwrite writes a terminating \0 character to the stream it is given. This does not make much sense, as usually one uses this fwrite to print something to the stdout or to a text file where no zero bytes should appear.
This is due to the mp_to_radix function always appending the NULL byte and the subsequent write in fwrite taking it all.
An easy solution would be to trim the NULL byte during the fwrite call:
https://github.com/libtom/libtommath/blob/develop/mp_fwrite.c#L23
if ((err = mp_to_radix(a, buf, size, &written, radix)) == MP_OKAY) {
if (fwrite(buf, written - 1, 1uL, stream) != 1uL) {
err = MP_ERR;
}
}instead of
if ((err = mp_to_radix(a, buf, size, &written, radix)) == MP_OKAY) {
if (fwrite(buf, written, 1uL, stream) != 1uL) {
err = MP_ERR;
}
}