Skip to content

Commit

Permalink
containers: fix undefined behaviour when flatVector2D is empty but ha…
Browse files Browse the repository at this point in the history
…s items
  • Loading branch information
DMurataj01 authored and andrea-iob committed May 24, 2022
1 parent f860fef commit e0157cb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/containers/flatVector2D.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ const T* FlatVector2D<T>::operator[](std::size_t i) const
{
assert(isIndexValid(i));

if (m_v.empty()) {
return nullptr;
}

std::size_t index = m_index[i];
return &m_v[index];
}
Expand All @@ -1106,6 +1110,10 @@ T* FlatVector2D<T>::operator[](std::size_t i)
{
assert(isIndexValid(i));

if (m_v.empty()) {
return nullptr;
}

std::size_t index = m_index[i];
return &m_v[index];
}
Expand Down

0 comments on commit e0157cb

Please sign in to comment.