Fix overflow issue in bitset_last_p (see #81)

This commit is contained in:
Patrick Pelissier committed 2020-12-21 15:08:19 +01:00
1 parent 4dbcfd25b3
commit ad16b310e1
2 files changed
+9 -2

No files matched your search

+3 -1
View File
@@ -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 */
+6 -1
View File
@@ -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);
}