util/bitset: Avoid dereferencing the bitset for size == 0.

If we don't have any bits in our set, don't go reading the pointer.  Fixes
invalid accesses caught by ASan in liveness and nir_to_tgsi when
impl->ssa_alloc == 0.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8530>
This commit is contained in:
Eric Anholt
2021-01-14 14:46:17 -08:00
committed by Marge Bot
parent efff70e73f
commit b183b6ddd7

View File

@@ -151,7 +151,7 @@ __bitset_next_set(unsigned i, BITSET_WORD *tmp,
* @param __size number of bits in the set to consider
*/
#define BITSET_FOREACH_SET(__i, __set, __size) \
for (BITSET_WORD __tmp = *(__set), *__foo = &__tmp; __foo != NULL; __foo = NULL) \
for (BITSET_WORD __tmp = (__size) == 0 ? 0 : *(__set), *__foo = &__tmp; __foo != NULL; __foo = NULL) \
for (__i = 0; \
(__i = __bitset_next_set(__i, &__tmp, __set, __size)) < __size;)