Commit 849a54a7 authored by Igor Kushnir's avatar Igor Kushnir
Browse files

ItemRepository::index: fix off-by-one error

Several member functions of ItemRepository access elements of m_buckets
at indices up to and including m_currentBucket. Presumably
m_currentBucket < m_buckets.size() is an invariant.
needMonsterExtent + 1 is added to m_currentBucket a few lines below the
modified line. So when
m_currentBucket + needMonsterExtent + 1 == m_buckets.size(), the size of
m_buckets must be increased.

The bug fixed in this commit caused frequent assertion failures in
ItemRepository when TestItemRepository::testItemRepository() randomly
picked a large item size - `if (itemDecision < largeItemsFraction)`.
parent f756798a
......@@ -1249,7 +1249,7 @@ public:
//Create a new monster-bucket at the end of the data
int needMonsterExtent = (totalSize - ItemRepositoryBucketSize) / MyBucket::DataSize + 1;
Q_ASSERT(needMonsterExtent);
if (m_currentBucket + needMonsterExtent + 1 > m_buckets.size()) {
if (m_currentBucket + needMonsterExtent + 1 >= m_buckets.size()) {
m_buckets.resize(m_buckets.size() + 10 + needMonsterExtent + 1);
}
useBucket = m_currentBucket;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment