From b183b6ddd7ffb07ebaa1ee11dc99a91b16e97315 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Thu, 14 Jan 2021 14:46:17 -0800 Subject: 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 Part-of: --- src/util/bitset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/util/bitset.h') diff --git a/src/util/bitset.h b/src/util/bitset.h index dd9a8bebae3..5313f85fcee 100644 --- a/src/util/bitset.h +++ b/src/util/bitset.h @@ -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;) -- cgit v1.2.3