[space map disk] Add a bounds check when accessing block data.
This means we get a more helpful message in the exception.
This commit is contained in:
parent
8781685a10
commit
df016f07a7
@ -443,13 +443,26 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void check_block(block_address b) const {
|
||||||
|
if (b >= nr_blocks_) {
|
||||||
|
std::ostringstream out;
|
||||||
|
out << "space map disk: block out of bounds ("
|
||||||
|
<< b << " >= " << nr_blocks_ << ")";
|
||||||
|
throw std::runtime_error(out.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ref_t lookup_bitmap(block_address b) const {
|
ref_t lookup_bitmap(block_address b) const {
|
||||||
|
check_block(b);
|
||||||
|
|
||||||
index_entry ie = indexes_->find_ie(b / ENTRIES_PER_BLOCK);
|
index_entry ie = indexes_->find_ie(b / ENTRIES_PER_BLOCK);
|
||||||
bitmap bm(tm_, ie, bitmap_validator_);
|
bitmap bm(tm_, ie, bitmap_validator_);
|
||||||
return bm.lookup(b % ENTRIES_PER_BLOCK);
|
return bm.lookup(b % ENTRIES_PER_BLOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert_bitmap(block_address b, unsigned n) {
|
void insert_bitmap(block_address b, unsigned n) {
|
||||||
|
check_block(b);
|
||||||
|
|
||||||
if (n > 3)
|
if (n > 3)
|
||||||
throw runtime_error("bitmap can only hold 2 bit values");
|
throw runtime_error("bitmap can only hold 2 bit values");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user