Skip to content

Commit

Permalink
fix bitvector iterators (#358)
Browse files Browse the repository at this point in the history
* fix bitvector iterators

use mContainer.begin() instead of &mContainer[0],
since it causes out of bounds exception in non release build

* test for empty bit vector comparison and iterator
  • Loading branch information
AntonYudintsev authored Apr 23, 2020
1 parent 73e1685 commit d996510
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/EASTL/bitvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -766,23 +766,23 @@ namespace eastl
typename bitvector<Allocator, Element, Container>::iterator
bitvector<Allocator, Element, Container>::begin() EA_NOEXCEPT
{
return iterator(&mContainer[0], 0);
return iterator(mContainer.begin(), 0);
}


template <typename Allocator, typename Element, typename Container>
typename bitvector<Allocator, Element, Container>::const_iterator
bitvector<Allocator, Element, Container>::begin() const EA_NOEXCEPT
{
return const_iterator(&mContainer[0], 0);
return const_iterator(mContainer.begin(), 0);
}


template <typename Allocator, typename Element, typename Container>
typename bitvector<Allocator, Element, Container>::const_iterator
bitvector<Allocator, Element, Container>::cbegin() const EA_NOEXCEPT
{
return const_iterator(&mContainer[0], 0);
return const_iterator(mContainer.begin(), 0);
}


Expand Down
5 changes: 5 additions & 0 deletions test/source/TestBitVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ int TestBitVector()

bv0.assign(boolArray, boolArray + EAArrayCount(boolArray));
EATEST_VERIFY(bv0 == bitvector<>(boolArray, boolArray + EAArrayCount(boolArray)));

bv0.resize(0);
EATEST_VERIFY(bv0.begin()==bv0.end());//should not crash
bv3.resize(0);
EATEST_VERIFY(bv0 == bv3);
}
}

Expand Down

0 comments on commit d996510

Please sign in to comment.