Copy the 's' parameter of _gej_rescale to avoid aliasing issues#1785
Copy the 's' parameter of _gej_rescale to avoid aliasing issues#1785peterdettman wants to merge 1 commit intobitcoin-core:masterfrom
Conversation
|
utACK 57652a3 (edit: The change is correct, but I believe we should do something else, see below.) Urghs, great catch. Now that I see this, I believe this is a larger (latent) problem. In most functions, entire |
|
Why not add a couple of |
|
I think we should decide whether to allow aliasing, or not, of this argument:
I have not checked the compilation output, but my guess is that both options will actually generate (very slightly) more performant code than current master, as in both cases the compiler can rely on the assumption that the scale value (or copy thereof) doesn't change throughout the execution. |
Agreed, and I'd prefer the second one, just because it's less work. Exceptions can be made in the future if we actually need them. |
There doesn't appear to be any reason why a caller of
_gej_rescalecouldn't pass ansthat aliases one of the fields ofr. In case it aliasedr->yorr->z, at least aVERIFY_CHECKin_fe_mulcould catch the problem. However ifr->xwere aliased, in general an invalid result would be silently produced, due tosbeing read afterr->xis written.This PR proposes simply copying
sto a local at the start of the method. (Also updates the group.h method decl so that the parameter names match).