Core/DataStores: Fixed out of bounds array access in DBStorageIterator

This commit is contained in:
Shauren
2015-02-25 16:13:58 +01:00
parent aa3b05c312
commit 4282ec57f3

View File

@@ -26,7 +26,15 @@ class DBStorageIterator : public std::iterator<std::forward_iterator_tag, T>
{
public:
DBStorageIterator() : _index(nullptr), _pos(0), _end(0) { }
DBStorageIterator(T** index, uint32 size, uint32 pos = 0) : _index(index), _pos(pos), _end(size) { while (_pos < _end && !_index[++_pos]); }
DBStorageIterator(T** index, uint32 size, uint32 pos = 0) : _index(index), _pos(pos), _end(size)
{
if (_pos < _end)
{
do
++_pos;
while (_pos < _end && !_index[_pos]);
}
}
T* operator->() { return _index[_pos]; }
T* operator*() { return _index[_pos]; }
@@ -34,8 +42,24 @@ public:
bool operator==(DBStorageIterator const& right) const { /*ASSERT(_index == right._index, "Iterator belongs to a different container")*/ return _pos == right._pos; }
bool operator!=(DBStorageIterator const& right) const { return !(*this == right); }
DBStorageIterator& operator++() { while (_pos < _end && !_index[++_pos]); return *this; }
DBStorageIterator operator++(int) { DBStorageIterator tmp = *this; ++*this; return tmp; }
DBStorageIterator& operator++()
{
if (_pos < _end)
{
do
++_pos;
while (_pos < _end && !_index[_pos]);
}
return *this;
}
DBStorageIterator operator++(int)
{
DBStorageIterator tmp = *this;
++*this;
return tmp;
}
private:
T** _index;