hbitmap: add 'pos < size' asserts
For now, fail in hbitmap_set on start + count > size will come from hbitmap_set hb_count_between hbitmap_iter_init assert(pos < hb->size) This patch adds such checks to set/get/reset functions of hbitmap. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-id: 1465924093-76875-2-git-send-email-vsementsov@virtuozzo.com Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
3dd48fdc55
commit
0e32119122
@ -269,6 +269,7 @@ void hbitmap_set(HBitmap *hb, uint64_t start, uint64_t count)
|
|||||||
start >>= hb->granularity;
|
start >>= hb->granularity;
|
||||||
last >>= hb->granularity;
|
last >>= hb->granularity;
|
||||||
count = last - start + 1;
|
count = last - start + 1;
|
||||||
|
assert(last < hb->size);
|
||||||
|
|
||||||
hb->count += count - hb_count_between(hb, start, last);
|
hb->count += count - hb_count_between(hb, start, last);
|
||||||
hb_set_between(hb, HBITMAP_LEVELS - 1, start, last);
|
hb_set_between(hb, HBITMAP_LEVELS - 1, start, last);
|
||||||
@ -348,6 +349,7 @@ void hbitmap_reset(HBitmap *hb, uint64_t start, uint64_t count)
|
|||||||
|
|
||||||
start >>= hb->granularity;
|
start >>= hb->granularity;
|
||||||
last >>= hb->granularity;
|
last >>= hb->granularity;
|
||||||
|
assert(last < hb->size);
|
||||||
|
|
||||||
hb->count -= hb_count_between(hb, start, last);
|
hb->count -= hb_count_between(hb, start, last);
|
||||||
hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last);
|
hb_reset_between(hb, HBITMAP_LEVELS - 1, start, last);
|
||||||
@ -371,6 +373,7 @@ bool hbitmap_get(const HBitmap *hb, uint64_t item)
|
|||||||
/* Compute position and bit in the last layer. */
|
/* Compute position and bit in the last layer. */
|
||||||
uint64_t pos = item >> hb->granularity;
|
uint64_t pos = item >> hb->granularity;
|
||||||
unsigned long bit = 1UL << (pos & (BITS_PER_LONG - 1));
|
unsigned long bit = 1UL << (pos & (BITS_PER_LONG - 1));
|
||||||
|
assert(pos < hb->size);
|
||||||
|
|
||||||
return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0;
|
return (hb->levels[HBITMAP_LEVELS - 1][pos >> BITS_PER_LEVEL] & bit) != 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user