Skip to content

Commit 2b14793

Browse files
probably overflow of unsigned for large capacity
1 parent 155dfb1 commit 2b14793

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/util/chashtable.h

+6
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ class chashtable : private HashProc, private EqProc {
161161
unsigned curr_cellar = (m_capacity - m_slots);
162162
unsigned new_slots = m_slots * 2;
163163
unsigned new_cellar = curr_cellar * 2;
164+
if (new_slots < m_slots || new_cellar < curr_cellar)
165+
throw default_exception("table overflow");
164166
while (true) {
165167
unsigned new_capacity = new_slots + new_cellar;
168+
if (new_capacity < new_slots)
169+
throw default_exception("table overflow");
166170
cell * new_table = alloc_table(new_capacity);
167171
cell * next_cell = copy_table(m_table, m_slots, m_capacity,
168172
new_table, new_slots, new_capacity,
@@ -179,6 +183,8 @@ class chashtable : private HashProc, private EqProc {
179183
return;
180184
}
181185
dealloc_vect(new_table, new_capacity);
186+
if (2*new_cellar < new_cellar)
187+
throw default_exception("table overflow");
182188
new_cellar *= 2;
183189
}
184190
}

0 commit comments

Comments
 (0)