summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorLoïc Guilloux <glx22@users.noreply.github.com>2021-08-10 19:03:15 +0200
committerGitHub <noreply@github.com>2021-08-10 19:03:15 +0200
commit8a083cd7f81d8223f08c30d5bcb2d9c38e7556a4 (patch)
tree8ed861bde5ac2ff8c2401ed5d07a2731dc287418 /src/core
parent4eb368c786893e3607341bae35aec6dde5def6b0 (diff)
downloadopenttd-8a083cd7f81d8223f08c30d5bcb2d9c38e7556a4.tar.xz
Fix 68f2213: Don't use GetPoolSize() for end of pool iterator (#9461)
Diffstat (limited to 'src/core')
-rw-r--r--src/core/pool_type.hpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp
index 2201d5cb0..20e8f8b29 100644
--- a/src/core/pool_type.hpp
+++ b/src/core/pool_type.hpp
@@ -160,7 +160,11 @@ struct Pool : PoolBase {
private:
size_t index;
- void ValidateIndex() { while (this->index < T::GetPoolSize() && !(T::IsValidID(this->index))) this->index++; }
+ void ValidateIndex()
+ {
+ while (this->index < T::GetPoolSize() && !(T::IsValidID(this->index))) this->index++;
+ if (this->index >= T::GetPoolSize()) this->index = T::Pool::MAX_SIZE;
+ }
};
/*
@@ -172,7 +176,7 @@ struct Pool : PoolBase {
size_t from;
IterateWrapper(size_t from = 0) : from(from) {}
PoolIterator<T> begin() { return PoolIterator<T>(this->from); }
- PoolIterator<T> end() { return PoolIterator<T>(T::GetPoolSize()); }
+ PoolIterator<T> end() { return PoolIterator<T>(T::Pool::MAX_SIZE); }
bool empty() { return this->begin() == this->end(); }
};
@@ -201,7 +205,11 @@ struct Pool : PoolBase {
private:
size_t index;
F filter;
- void ValidateIndex() { while (this->index < T::GetPoolSize() && !(T::IsValidID(this->index) && this->filter(this->index))) this->index++; }
+ void ValidateIndex()
+ {
+ while (this->index < T::GetPoolSize() && !(T::IsValidID(this->index) && this->filter(this->index))) this->index++;
+ if (this->index >= T::GetPoolSize()) this->index = T::Pool::MAX_SIZE;
+ }
};
/*
@@ -214,7 +222,7 @@ struct Pool : PoolBase {
F filter;
IterateWrapperFiltered(size_t from, F filter) : from(from), filter(filter) {}
PoolIteratorFiltered<T, F> begin() { return PoolIteratorFiltered<T, F>(this->from, this->filter); }
- PoolIteratorFiltered<T, F> end() { return PoolIteratorFiltered<T, F>(T::GetPoolSize(), this->filter); }
+ PoolIteratorFiltered<T, F> end() { return PoolIteratorFiltered<T, F>(T::Pool::MAX_SIZE, this->filter); }
bool empty() { return this->begin() == this->end(); }
};