summaryrefslogtreecommitdiff
path: root/libc/stdio/stdio.cpp
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2019-03-21 14:04:33 -0700
committerNick Kralevich <nnk@google.com>2019-03-25 13:51:33 -0700
commitc50b6a2b89136b26a7f511a1a17e05b39f49dabd (patch)
tree6a4a41a1dd913590f47b4035175557d1aa6f026c /libc/stdio/stdio.cpp
parente187d92062b3a384f8c4730f93aa6c36e1c74b52 (diff)
Make powerof2 macro ubsan safe
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
Diffstat (limited to 'libc/stdio/stdio.cpp')
0 files changed, 0 insertions, 0 deletions