rbitset: Handle the edge case that the start position equals the end position in...
authorChristoph Mallon <christoph.mallon@gmx.de>
Sun, 25 Nov 2012 22:05:24 +0000 (23:05 +0100)
committerChristoph Mallon <christoph.mallon@gmx.de>
Sun, 25 Nov 2012 22:05:24 +0000 (23:05 +0100)
This fixes rbitset_foreach().

ir/adt/bitset.h
ir/adt/raw_bitset.h

index 59a6dbd..5d9aada 100644 (file)
@@ -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);
 }
 
index 8af6662..9cf5894 100644 (file)
@@ -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);