summaryrefslogtreecommitdiff
path: root/tests/sys_param_test.cpp
AgeCommit message (Collapse)Author
2019-03-25Make powerof2 macro ubsan safeNick Kralevich
Subtracting one from the smallest value expressable by the provided variable could cause an underflow operation. In particular, this is problematic when code similar to: uint64_t foo = 0; if (powerof2(foo)) { ...; } is run with integer sanitization enabled. The macro would subtract one from zero, underflowing and triggering the sanitizer. Make the powerof2() macro ubsan safe, by explicitly handling underflows. Note: This change DOES NOT make powerof2() accurate. We continue to falsely return "true" for 0 and negative numbers (see attached tests). Found while investigating Bug: 122975762 Test: see added testcase Test: atest ziparchive-tests Change-Id: I5408ce5c18868d797bcae8f115ddb7c4c1ced81e