diff --git a/m-bitset.h b/m-bitset.h index 946d5424..5a988e6e 100644 --- a/m-bitset.h +++ b/m-bitset.h @@ -536,7 +536,9 @@ static inline bool bitset_last_p(const bitset_it_t it) { M_ASSERT (it != NULL && it->set != NULL); - return (it->index) >= (it->set->size)-1; + /* NOTE: Can not compute 'size-1' due to potential overflow + if size is 0 */ + return (it->index+1) >= (it->set->size); } /* Test if both iterators reference the same bit */ diff --git a/tests/test-mbitset.c b/tests/test-mbitset.c index 01504948..e31dd289 100644 --- a/tests/test-mbitset.c +++ b/tests/test-mbitset.c @@ -202,7 +202,12 @@ static void test1(void) assert (bitset_end_p(it)); assert (bitset_hash(set) != 0); - + + bitset_clean(set); + bitset_it(it, set); + assert(bitset_end_p(it)); + assert(bitset_last_p(it)); + bitset_clear(set); bitset_clear(set2); }