Skip to content

Commit e0157cb

Browse files
DMurataj01andrea-iob
authored andcommitted
containers: fix undefined behaviour when flatVector2D is empty but has items
1 parent f860fef commit e0157cb

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/containers/flatVector2D.tpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,10 @@ const T* FlatVector2D<T>::operator[](std::size_t i) const
10911091
{
10921092
assert(isIndexValid(i));
10931093

1094+
if (m_v.empty()) {
1095+
return nullptr;
1096+
}
1097+
10941098
std::size_t index = m_index[i];
10951099
return &m_v[index];
10961100
}
@@ -1106,6 +1110,10 @@ T* FlatVector2D<T>::operator[](std::size_t i)
11061110
{
11071111
assert(isIndexValid(i));
11081112

1113+
if (m_v.empty()) {
1114+
return nullptr;
1115+
}
1116+
11091117
std::size_t index = m_index[i];
11101118
return &m_v[index];
11111119
}

0 commit comments

Comments
 (0)