diff options
author | rubidium <rubidium@openttd.org> | 2009-01-09 15:00:22 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-01-09 15:00:22 +0000 |
commit | 07c5fb2a028dbb97e3c28d267c49131aaba4facb (patch) | |
tree | 92afae688b13a3c67a6c391be2fb3b64e87334ef /src | |
parent | f0b0691bfe603e362cd5760240582cec410876ff (diff) | |
download | openttd-07c5fb2a028dbb97e3c28d267c49131aaba4facb.tar.xz |
(svn r14934) -Fix: in (extreme) cases CanAllocateItem could return true when there's not enough space.
Diffstat (limited to 'src')
-rw-r--r-- | src/oldpool_func.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/oldpool_func.h b/src/oldpool_func.h index fc08bf9ee..3fbed16a7 100644 --- a/src/oldpool_func.h +++ b/src/oldpool_func.h @@ -44,6 +44,7 @@ template<typename T, typename Tid, OldMemoryPool<T> *Tpool> T *PoolItem<T, Tid, 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, OldMemoryPool<T> *Tpool> bool PoolItem<T, Tid 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; } |