Skip to content

Commit 643cafb

Browse files
authored
Merge pull request InsightSoftwareConsortium#5967 from hjmjohnson/fix-QuadEdgeMeshCellInterfaceTest-UB
BUG: Fix undefined behavior in itkQuadEdgeMeshCellInterfaceTest
2 parents 18d89fd + 7c0071f commit 643cafb

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshCellInterfaceTest.cxx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,17 @@ TestCellInterface(const std::string_view name, TCell * aCell)
120120
std::vector<PointIdentifier> pointIds(numberOfPoints * 2);
121121
std::iota(pointIds.begin(), pointIds.end(), PointIdentifier{});
122122

123-
cell->SetPointIds(pointIds.data());
123+
if (!pointIds.empty())
124+
{
125+
cell->SetPointIds(pointIds.data());
126+
}
124127
// exercising the const GetPointIds() method
125128
// null for QE Cells
126129
if (cell2->GetPointIds())
127130
{
128131
cell->SetPointIds(cell2->GetPointIds());
129132
}
130-
if (numberOfPoints > 0)
133+
if (!pointIds.empty())
131134
{
132135
cell->SetPointId(0, 100);
133136
}
@@ -142,7 +145,10 @@ TestCellInterface(const std::string_view name, TCell * aCell)
142145
}
143146
std::cout << std::endl;
144147

145-
cell->SetPointIds(&pointIds[numberOfPoints], &pointIds[numberOfPoints * 2]);
148+
if (!pointIds.empty())
149+
{
150+
cell->SetPointIds(pointIds.data() + numberOfPoints, pointIds.data() + numberOfPoints * 2);
151+
}
146152
std::cout << " Iterator test: PointIds for populated cell: ";
147153
typename TCell::PointIdIterator pxpointId = cell->PointIdsBegin();
148154
typename TCell::PointIdIterator pxendId = cell->PointIdsEnd();

0 commit comments

Comments
 (0)