Changeset - r10635:87b713d8a41d
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-01-09 15:00:22
rubidium@openttd.org
(svn r14934) -Fix: in (extreme) cases CanAllocateItem could return true when there's not enough space.
1 file changed with 2 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/oldpool_func.h
Show inline comments
 
@@ -44,6 +44,7 @@ template<typename T, typename Tid, OldMe
 
template<typename T, typename Tid, OldMemoryPool<T> *Tpool> bool PoolItem<T, Tid, Tpool>::CanAllocateItem(uint count)
 
{
 
	uint last_minus_one = Tpool->GetSize() - 1;
 
	uint orig_count = count;
 

	
 
	for (T *t = Tpool->Get(Tpool->first_free_index); count > 0 && t != NULL; t = ((uint)t->index < last_minus_one) ? Tpool->Get(t->index + 1U) : NULL) {
 
		if (!t->IsValid()) count--;
 
@@ -52,7 +53,7 @@ template<typename T, typename Tid, OldMe
 
	if (count == 0) return true;
 

	
 
	/* Check if we can add a block to the pool */
 
	if (Tpool->AddBlockToPool()) return CanAllocateItem(count);
 
	if (Tpool->AddBlockToPool()) return CanAllocateItem(orig_count);
 

	
 
	return false;
 
}
0 comments (0 inline, 0 general)