diff options
author | David Robillard <d@drobilla.net> | 2019-10-18 14:46:59 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-10-18 14:46:59 +0200 |
commit | 55f0835fff8bf8be6a58813b6c9faec97ec5597c (patch) | |
tree | 252149a3fcd15a067d481c9ed3cb9d58104c37a7 /zix | |
parent | 5b1f9a7ba3b1e1c5fcf0c36ce018df56822539b1 (diff) | |
download | zix-55f0835fff8bf8be6a58813b6c9faec97ec5597c.tar.gz zix-55f0835fff8bf8be6a58813b6c9faec97ec5597c.tar.bz2 zix-55f0835fff8bf8be6a58813b6c9faec97ec5597c.zip |
Fix out of bounds accesses in Bitset
Diffstat (limited to 'zix')
-rw-r--r-- | zix/bitset.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/zix/bitset.c b/zix/bitset.c index 6a4d245..e5f8348 100644 --- a/zix/bitset.c +++ b/zix/bitset.c @@ -77,8 +77,10 @@ zix_bitset_count_up_to(const ZixBitset* b, const ZixBitsetTally* t, size_t i) count += t[e]; } - const ZixBitset mask = ~(~(ZixBitset)0 << extra); - count += (size_t)__builtin_popcountl(b[full_elems] & mask); + if (extra) { + const ZixBitset mask = ~(~(ZixBitset)0 << extra); + count += (size_t)__builtin_popcountl(b[full_elems] & mask); + } return count; } @@ -99,8 +101,10 @@ zix_bitset_count_up_to_if(const ZixBitset* b, const ZixBitsetTally* t, size_t i) count += t[e]; } - const ZixBitset mask = ~(~(ZixBitset)0 << extra); - count += __builtin_popcountl(b[full_elems] & mask); + if (extra) { + const ZixBitset mask = ~(~(ZixBitset)0 << extra); + count += __builtin_popcountl(b[full_elems] & mask); + } return count; } |