File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313
1414#include " Vector.hh"
1515#include " ObjectId.hh"
16+ #include " Error.hh"
1617
1718namespace sta {
1819
@@ -42,8 +43,9 @@ public:
4243 size_t size () const { return size_; }
4344 void clear ();
4445
45- static constexpr ObjectId idx_bits = 10 ;
46- static constexpr ObjectId block_size = (1 << idx_bits);
46+ static constexpr int idx_bits = 7 ;
47+ static constexpr int block_size = (1 << idx_bits);
48+ static constexpr int block_id_max = 1 << (object_id_bits - idx_bits);
4749
4850private:
4951 ArrayBlock<TYPE> *makeBlock (uint32_t size);
129131ArrayTable<TYPE>::pushBlock(ArrayBlock<TYPE> *block)
130132{
131133 blocks_[blocks_size_++] = block;
134+ if (blocks_size_ >= block_id_max)
135+ internalError (" max array table block count exceeded." );
132136 if (blocks_size_ == blocks_capacity_) {
133137 size_t new_capacity = blocks_capacity_ * 1.5 ;
134138 ArrayBlock<TYPE>** new_blocks = new ArrayBlock<TYPE>*[new_capacity];
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ typedef uint32_t BlockIdx;
1919// Object index within a block.
2020typedef uint32_t ObjectIdx;
2121
22+ static constexpr int object_id_bits = sizeof (ObjectId) * 8 ;
2223static constexpr BlockIdx block_idx_null = 0 ;
2324static constexpr ObjectId object_id_null = 0 ;
2425static constexpr ObjectIdx object_idx_null = 0 ;
Original file line number Diff line number Diff line change @@ -43,8 +43,9 @@ public:
4343 void clear ();
4444
4545 // Objects are allocated in blocks of 128.
46- static constexpr ObjectId idx_bits = 7 ;
47- static constexpr ObjectId block_object_count = (1 << idx_bits);
46+ static constexpr int idx_bits = 7 ;
47+ static constexpr int block_object_count = (1 << idx_bits);
48+ static constexpr int block_id_max = 1 << (object_id_bits - idx_bits);
4849
4950private:
5051 void makeBlock ();
@@ -104,6 +105,8 @@ ObjectTable<TYPE>::makeBlock()
104105 BlockIdx block_index = blocks_.size ();
105106 TableBlock<TYPE> *block = new TableBlock<TYPE>(block_index, this );
106107 blocks_.push_back (block);
108+ if (blocks_.size () >= block_id_max)
109+ internalError (" max object table block count exceeded." );
107110 // ObjectId zero is reserved for object_id_null.
108111 int last = (block_index > 0 ) ? 0 : 1 ;
109112 for (int i = block_object_count - 1 ; i >= last; i--) {
You can’t perform that action at this time.
0 commit comments