From: Christoph Mallon Date: Sun, 25 Nov 2012 22:05:24 +0000 (+0100) Subject: rbitset: Handle the edge case that the start position equals the end position in... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=7f446a85bb45e7b1fa16354ea167d19eb4406afb;p=libfirm rbitset: Handle the edge case that the start position equals the end position in rbitset_next_max(). This fixes rbitset_foreach(). --- diff --git a/ir/adt/bitset.h b/ir/adt/bitset.h index 59a6dbdff..5d9aada3f 100644 --- a/ir/adt/bitset.h +++ b/ir/adt/bitset.h @@ -200,8 +200,6 @@ static inline void bitset_copy_into(bitset_t *tgt, const bitset_t *src) */ static inline size_t bitset_next_clear(const bitset_t *bs, size_t pos) { - if (pos >= bs->size) - return (size_t)-1; return rbitset_next_max(bs->data, pos, bs->size, false); } @@ -215,8 +213,6 @@ static inline size_t bitset_next_clear(const bitset_t *bs, size_t pos) */ static inline size_t bitset_next_set(const bitset_t *bs, size_t pos) { - if (pos >= bs->size) - return (size_t)-1; return rbitset_next_max(bs->data, pos, bs->size, true); } diff --git a/ir/adt/raw_bitset.h b/ir/adt/raw_bitset.h index 8af66627f..9cf58943c 100644 --- a/ir/adt/raw_bitset.h +++ b/ir/adt/raw_bitset.h @@ -304,6 +304,10 @@ static inline size_t rbitset_next(const unsigned *bitset, size_t pos, static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos, size_t last, bool set) { + assert(pos <= last); + if (pos == last) + return (size_t)-1; + size_t p; size_t elem_pos = pos / BITS_PER_ELEM; size_t bit_pos = pos % BITS_PER_ELEM; @@ -318,8 +322,6 @@ static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos, */ unsigned in_elem_mask = (1u << bit_pos) - 1; - assert(pos < last); - elem ^= mask; p = ntz(elem & ~in_elem_mask);