# HG changeset patch # User Loïc Guilloux # Date 2021-08-10 17:03:15 # Node ID d10108931407955be1e77f032ddb9c3cb2e1e813 # Parent f3cf79dd5c7210930e390e4c134709ba989c3828 Fix 68f2213: Don't use GetPoolSize() for end of pool iterator (#9461) diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp --- 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 begin() { return PoolIterator(this->from); } - PoolIterator end() { return PoolIterator(T::GetPoolSize()); } + PoolIterator end() { return PoolIterator(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 begin() { return PoolIteratorFiltered(this->from, this->filter); } - PoolIteratorFiltered end() { return PoolIteratorFiltered(T::GetPoolSize(), this->filter); } + PoolIteratorFiltered end() { return PoolIteratorFiltered(T::Pool::MAX_SIZE, this->filter); } bool empty() { return this->begin() == this->end(); } };