Mesa (master): util/bitset: Avoid dereferencing the bitset for size == 0.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 25 19:20:56 UTC 2021


Module: Mesa
Branch: master
Commit: b183b6ddd7ffb07ebaa1ee11dc99a91b16e97315
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b183b6ddd7ffb07ebaa1ee11dc99a91b16e97315

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Jan 14 14:46:17 2021 -0800

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 at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8530>

---

 src/util/bitset.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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;)
 



More information about the mesa-commit mailing list