Skip to content

Commit fd77022

Browse files
hjmjohnsonclaude
andcommitted
ENH: Use std::vector instead of raw new[] in QuadEdgeMesh test
Replace raw `new PointIdentifier[]` with `std::vector<PointIdentifier>` and `std::iota` in TestCellInterface and TestQECellInterface. This resolves core.CallAndMessage scan-build findings where the analyzer could not verify value-initialization of raw new[] arrays. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b1c947c commit fd77022

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshCellInterfaceTest.cxx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
*=========================================================================*/
1818

1919
#include <iostream>
20+
#include <numeric>
2021
#include <string_view>
22+
#include <vector>
2123

2224
#include "itkQuadEdgeMesh.h"
2325

@@ -114,14 +116,11 @@ TestCellInterface(const std::string_view name, TCell * aCell)
114116

115117
using PointIdentifier = MeshType::PointIdentifier;
116118

117-
const unsigned int numberOfPoints = cell->GetNumberOfPoints();
118-
auto * pointIds = new PointIdentifier[numberOfPoints * 2]{};
119-
for (unsigned int i = 0; i < numberOfPoints * 2; ++i)
120-
{
121-
pointIds[i] = i;
122-
}
119+
const unsigned int numberOfPoints = cell->GetNumberOfPoints();
120+
std::vector<PointIdentifier> pointIds(numberOfPoints * 2);
121+
std::iota(pointIds.begin(), pointIds.end(), PointIdentifier{});
123122

124-
cell->SetPointIds(pointIds);
123+
cell->SetPointIds(pointIds.data());
125124
// exercising the const GetPointIds() method
126125
// null for QE Cells
127126
if (cell2->GetPointIds())
@@ -166,9 +165,6 @@ TestCellInterface(const std::string_view name, TCell * aCell)
166165
xpointId++;
167166
}
168167
std::cout << std::endl;
169-
170-
171-
delete[] pointIds;
172168
return EXIT_SUCCESS;
173169
}
174170

@@ -212,14 +208,11 @@ TestQECellInterface(const std::string_view name, TCell * aCell)
212208
const unsigned int numberOfPoints = cell->GetNumberOfPoints();
213209
if (numberOfPoints > 0)
214210
{
215-
auto * pointIds = new PointIdentifier[numberOfPoints * 2]{};
216-
for (unsigned int i = 0; i < numberOfPoints * 2; ++i)
217-
{
218-
pointIds[i] = i;
219-
}
211+
std::vector<PointIdentifier> pointIds(numberOfPoints * 2);
212+
std::iota(pointIds.begin(), pointIds.end(), PointIdentifier{});
220213

221214
// actually populate
222-
cell->SetPointIds(pointIds);
215+
cell->SetPointIds(pointIds.data());
223216
// exercising the non const internal equivalent.
224217
cell->InternalSetPointIds(cell->InternalGetPointIds());
225218
// exercising the const internal equivalent
@@ -245,8 +238,6 @@ TestQECellInterface(const std::string_view name, TCell * aCell)
245238
pxpointId++;
246239
}
247240
std::cout << std::endl;
248-
249-
delete[] pointIds;
250241
}
251242
return EXIT_SUCCESS;
252243
}

0 commit comments

Comments
 (0)