Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libspl sys/sysmacros.h: Fix P2ROUNDUP_TYPED to not trigger integer ov…
…erflow The original P2ROUNDUP_TYPED macro contains a -x which triggers PaX's integer overflow detection for unsigned integers. Replace the macro with an equivalent version that does not trigger the overflow. Axioms: A. (-(x)) === (~((x) - 1)) === (~(x) + 1) under two's complement B. ~(x & y) === ((~(x)) | (~(y))) under De Morgan's law C. ~(~x) = x under the law of the excluded middle Proof: 0. (-(-(x) & -(align))) original 1. (~(-(x) & -(align)) + 1) by A 2. (((~(-(x))) | (~(-(align)))) + 1) by B 3. (((~(~((x) - 1))) | (~(~((align) - 1)))) + 1) by A 4. (((((x) - 1)) | (((align) - 1))) + 1) by C Signed-off-by: Jason Zaman <[email protected]> Reviewed-by: Chris Dunlop <[email protected]> Reviewed-by: Richard Yao <[email protected]>
- Loading branch information