diff --git a/include/sta/ArrayTable.hh b/include/sta/ArrayTable.hh index 13aac268..e5746418 100644 --- a/include/sta/ArrayTable.hh +++ b/include/sta/ArrayTable.hh @@ -13,6 +13,7 @@ #include "Vector.hh" #include "ObjectId.hh" +#include "Error.hh" namespace sta { @@ -42,8 +43,9 @@ public: size_t size() const { return size_; } void clear(); - static constexpr ObjectId idx_bits = 10; - static constexpr ObjectId block_size = (1 << idx_bits); + static constexpr int idx_bits = 7; + static constexpr int block_size = (1 << idx_bits); + static constexpr int block_id_max = 1 << (object_id_bits - idx_bits); private: ArrayBlock *makeBlock(uint32_t size); @@ -129,6 +131,8 @@ void ArrayTable::pushBlock(ArrayBlock *block) { blocks_[blocks_size_++] = block; + if (blocks_size_ >= block_id_max) + internalError("max array table block count exceeded."); if (blocks_size_ == blocks_capacity_) { size_t new_capacity = blocks_capacity_ * 1.5; ArrayBlock** new_blocks = new ArrayBlock*[new_capacity]; diff --git a/include/sta/ObjectId.hh b/include/sta/ObjectId.hh index 175d1e21..f3acd5f0 100644 --- a/include/sta/ObjectId.hh +++ b/include/sta/ObjectId.hh @@ -19,6 +19,7 @@ typedef uint32_t BlockIdx; // Object index within a block. typedef uint32_t ObjectIdx; +static constexpr int object_id_bits = sizeof(ObjectId) * 8; static constexpr BlockIdx block_idx_null = 0; static constexpr ObjectId object_id_null = 0; static constexpr ObjectIdx object_idx_null = 0; diff --git a/include/sta/ObjectTable.hh b/include/sta/ObjectTable.hh index 7b2ba4f3..764c6d38 100644 --- a/include/sta/ObjectTable.hh +++ b/include/sta/ObjectTable.hh @@ -43,8 +43,9 @@ public: void clear(); // Objects are allocated in blocks of 128. - static constexpr ObjectId idx_bits = 7; - static constexpr ObjectId block_object_count = (1 << idx_bits); + static constexpr int idx_bits = 7; + static constexpr int block_object_count = (1 << idx_bits); + static constexpr int block_id_max = 1 << (object_id_bits - idx_bits); private: void makeBlock(); @@ -104,6 +105,8 @@ ObjectTable::makeBlock() BlockIdx block_index = blocks_.size(); TableBlock *block = new TableBlock(block_index, this); blocks_.push_back(block); + if (blocks_.size() >= block_id_max) + internalError("max object table block count exceeded."); // ObjectId zero is reserved for object_id_null. int last = (block_index > 0) ? 0 : 1; for (int i = block_object_count - 1; i >= last; i--) {