MPN_FILL vs MPN_ZERO
vincent at vinc17.net
Tue Apr 24 13:17:41 UTC 2018
On 2018-04-24 12:46:27 +0200, paul zimmermann wrote:
> I understand MPN_ZERO(p,n) is implemented as "if (n) MPN_FILL(p, n, 0)".
> Then in case MPN_FILL is implemented using memset, since memset also checks
> for the case n=0, MPN_ZERO(p,n) will perform two tests for n > 0. Why not
> directly call MPN_FILL?
Note that there is a difference: with memset, p must have a valid
value (e.g. must not be a null pointer), even when n is 0, while
in MPN_ZERO(p,n), p may have an invalid value when n is 0. To do
the change, you would need to check the GMP code to see whether
MPN_ZERO can be called with an invalid pointer value.
Moreover, I think that if this is OK, it would be better to call
memset directly from MPN_ZERO in this case, bypassing MPN_FILL,
which normally expects n > 0.
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-devel