From 979d8a6587690fa71db48baaff69618f0421f25c Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Fri, 28 Apr 2006 15:52:15 +0000 Subject: [PATCH] BugFix: do return -1 if no bit is found [r7669] --- ir/adt/bitset.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ir/adt/bitset.h b/ir/adt/bitset.h index d49eb6573..9ae16372b 100644 --- a/ir/adt/bitset.h +++ b/ir/adt/bitset.h @@ -272,6 +272,7 @@ static INLINE bitset_pos_t _bitset_next(const bitset_t *bs, bitset_pos_t pos, int set) { bitset_pos_t unit_number = pos / BS_UNIT_SIZE_BITS; + bitset_pos_t res; if(pos >= bs->size) return -1; @@ -295,8 +296,10 @@ static INLINE bitset_pos_t _bitset_next(const bitset_t *bs, _bitset_inside_ntz_value((set ? curr_unit : ~curr_unit) & ~in_unit_mask); /* If there is a bit set in the current unit, exit. */ - if(next_in_this_unit < BS_UNIT_SIZE_BITS) - return next_in_this_unit + unit_number * BS_UNIT_SIZE_BITS; + if (next_in_this_unit < BS_UNIT_SIZE_BITS) { + res = next_in_this_unit + unit_number * BS_UNIT_SIZE_BITS; + return res < bs->size ? res : -1; + } /* Else search for set bits in the next units. */ else { @@ -306,8 +309,10 @@ static INLINE bitset_pos_t _bitset_next(const bitset_t *bs, bitset_pos_t first_set = _bitset_inside_ntz_value(set ? data : ~data); - if(first_set < BS_UNIT_SIZE_BITS) - return first_set + i * BS_UNIT_SIZE_BITS; + if (first_set < BS_UNIT_SIZE_BITS) { + res = first_set + i * BS_UNIT_SIZE_BITS; + return res < bs->size ? res : -1; + } } } } -- 2.20.1