Skip to content

Commit 13abcb9

Browse files
authored
Merge pull request InsightSoftwareConsortium#5940 from hjmjohnson/1261-scan-build-warnings
COMP: Address scan-build warnings
2 parents 9814e0d + 14c265b commit 13abcb9

24 files changed

Lines changed: 166 additions & 238 deletions

Modules/Core/Common/include/itkSingleton.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Singleton(const char * globalName, std::function<void()> deleteFunc)
140140
T * instance = SingletonIndex::GetInstance()->GetGlobalInstance<T>(globalName);
141141
if (instance == nullptr)
142142
{
143-
instance = new T;
143+
instance = new T{};
144144
SingletonIndex::GetInstance()->SetGlobalInstance<T>(globalName, instance, std::move(deleteFunc));
145145
}
146146
return instance;

Modules/Core/Common/src/itkPoolMultiThreader.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ PoolMultiThreader::ParallelizeImageRegion(unsigned int dimension,
278278
}
279279
}
280280
iRegion = region;
281-
total = splitter->GetSplit(0, splitCount, iRegion);
281+
splitter->GetSplit(0, splitCount, iRegion);
282282

283283
// execute this thread's share
284284
ExceptionHandler exceptionHandler;

Modules/Core/Common/test/itkArray2DGTest.cxx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ TEST(Array2D, MoveConstruct)
7070
const auto * const * const originalDataArray{ original.data_array() };
7171
const unsigned int originalSize{ original.size() };
7272

73-
const auto moveConstructed = std::move(original);
73+
const auto moveConstructed = std::forward<decltype(original)>(original);
7474

7575
// After the "move", the move-constructed object has retrieved the original data.
7676
EXPECT_EQ(moveConstructed.data_array(), originalDataArray);
7777
EXPECT_EQ(moveConstructed.size(), originalSize);
7878

79-
// After the "move", the original is left empty.
79+
// Intentionally verify the moved-from object is in a valid empty state.
80+
// NOLINTNEXTLINE(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
8081
EXPECT_EQ(original.data_array(), nullptr);
8182
EXPECT_EQ(original.size(), 0U);
8283
};
@@ -102,7 +103,8 @@ TEST(Array2D, MoveAssign)
102103
EXPECT_EQ(moveAssigmentTarget.data_array(), originalDataArray);
103104
EXPECT_EQ(moveAssigmentTarget.size(), originalSize);
104105

105-
// After the "move", the original is left empty.
106+
// Intentionally verify the moved-from object is in a valid empty state.
107+
// NOLINTNEXTLINE(bugprone-use-after-move,clang-analyzer-cplusplus.Move)
106108
EXPECT_EQ(original.data_array(), nullptr);
107109
EXPECT_EQ(original.size(), 0U);
108110
};

Modules/Core/Common/test/itkImageVectorOptimizerParametersHelperTest.cxx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ testMemoryAccess(OptimizerParametersType & params, ImageVectorPointer imageOfVec
7878
int
7979
itkImageVectorOptimizerParametersHelperTest(int, char *[])
8080
{
81-
int result = EXIT_SUCCESS;
82-
8381
SizeType size;
8482
constexpr int dimLength{ 3 };
8583
size.Fill(dimLength);
@@ -128,7 +126,7 @@ itkImageVectorOptimizerParametersHelperTest(int, char *[])
128126
// to the image data.
129127
params.SetParametersObject(imageOfVectors);
130128

131-
result = testMemoryAccess(params, imageOfVectors, dimLength);
129+
const int result = testMemoryAccess(params, imageOfVectors, dimLength);
132130

133131
// Test MoveDataPointer
134132
itk::Array<ValueType> array(imageOfVectors->GetPixelContainer()->Size(), 1.23);

Modules/Core/Common/test/itkRangeGTestUtilities.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class RangeGTestUtilities
9494
ExpectMoveConstructedRangeHasSameIteratorsAsOriginalBeforeMove(TRange && originalRange)
9595
{
9696
const TRange originalRangeBeforeMove = originalRange;
97-
TRange moveConstructedRange(std::move(originalRange));
97+
TRange moveConstructedRange(std::forward<TRange>(originalRange));
9898

9999
ExpectRangesHaveEqualBeginAndEnd(moveConstructedRange, originalRangeBeforeMove);
100100
}
@@ -107,7 +107,7 @@ class RangeGTestUtilities
107107
const TRange originalRangeBeforeMove = originalRange;
108108

109109
TRange moveAssignedRange;
110-
moveAssignedRange = std::move(originalRange);
110+
moveAssignedRange = std::forward<TRange>(originalRange);
111111

112112
ExpectRangesHaveEqualBeginAndEnd(moveAssignedRange, originalRangeBeforeMove);
113113
}

Modules/Core/Common/test/itkVariableLengthVectorTest.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ itkVariableLengthVectorTest(int, char *[])
186186
ASSERT(&x[0] != start, "DontShrintToFit(bigger) => reallocate");
187187
// ASSERT(x[0] is uninitialized);
188188
x[0] = ref[0];
189-
start = &x[0];
190189
}
191190

192191
// Test on assignments

Modules/Core/QuadEdgeMesh/test/itkQuadEdgeMeshCellInterfaceTest.cxx

Lines changed: 37 additions & 42 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,20 +116,18 @@ TestCellInterface(const std::string_view name, TCell * aCell)
114116

115117
using PointIdentifier = MeshType::PointIdentifier;
116118

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

123-
cell->SetPointIds(pointIds);
123+
cell->SetPointIds(pointIds.data());
124124
// exercising the const GetPointIds() method
125125
// null for QE Cells
126126
if (cell2->GetPointIds())
127127
{
128128
cell->SetPointIds(cell2->GetPointIds());
129129
}
130-
if (cell->GetNumberOfPoints() > 0)
130+
if (numberOfPoints > 0)
131131
{
132132
cell->SetPointId(0, 100);
133133
}
@@ -142,7 +142,7 @@ TestCellInterface(const std::string_view name, TCell * aCell)
142142
}
143143
std::cout << std::endl;
144144

145-
cell->SetPointIds(&pointIds[cell->GetNumberOfPoints()], &pointIds[cell->GetNumberOfPoints() * 2]);
145+
cell->SetPointIds(&pointIds[numberOfPoints], &pointIds[numberOfPoints * 2]);
146146
std::cout << " Iterator test: PointIds for populated cell: ";
147147
typename TCell::PointIdIterator pxpointId = cell->PointIdsBegin();
148148
typename TCell::PointIdIterator pxendId = cell->PointIdsEnd();
@@ -165,9 +165,6 @@ TestCellInterface(const std::string_view name, TCell * aCell)
165165
xpointId++;
166166
}
167167
std::cout << std::endl;
168-
169-
170-
delete[] pointIds;
171168
return EXIT_SUCCESS;
172169
}
173170

@@ -208,42 +205,40 @@ TestQECellInterface(const std::string_view name, TCell * aCell)
208205

209206
using PointIdentifier = typename TCell::PointIdentifier;
210207

211-
auto * pointIds = new PointIdentifier[cell->GetNumberOfPoints() * 2];
212-
for (unsigned int i = 0; i < cell->GetNumberOfPoints() * 2; ++i)
208+
const unsigned int numberOfPoints = cell->GetNumberOfPoints();
209+
if (numberOfPoints > 0)
213210
{
214-
pointIds[i] = i;
215-
}
216-
217-
// actually populate
218-
cell->SetPointIds(pointIds);
219-
// exercising the non const internal equivalent.
220-
cell->InternalSetPointIds(cell->InternalGetPointIds());
221-
// exercising the const internal equivalent
222-
cell->InternalSetPointIds(cell2->InternalGetPointIds());
211+
std::vector<PointIdentifier> pointIds(numberOfPoints * 2);
212+
std::iota(pointIds.begin(), pointIds.end(), PointIdentifier{});
223213

214+
// actually populate
215+
cell->SetPointIds(pointIds.data());
216+
// exercising the non const internal equivalent.
217+
cell->InternalSetPointIds(cell->InternalGetPointIds());
218+
// exercising the const internal equivalent
219+
cell->InternalSetPointIds(cell2->InternalGetPointIds());
224220

225-
std::cout << " ConstIterator test: PointIds for populated cell: ";
226-
typename TCell::PointIdInternalConstIterator ppointId = cell2->InternalPointIdsBegin();
227-
const typename TCell::PointIdInternalConstIterator pendId = cell2->InternalPointIdsEnd();
228-
while (ppointId != pendId)
229-
{
230-
std::cout << *ppointId << ", ";
231-
ppointId++;
232-
}
233-
std::cout << std::endl;
221+
std::cout << " ConstIterator test: PointIds for populated cell: ";
222+
typename TCell::PointIdInternalConstIterator ppointId = cell2->InternalPointIdsBegin();
223+
const typename TCell::PointIdInternalConstIterator pendId = cell2->InternalPointIdsEnd();
224+
while (ppointId != pendId)
225+
{
226+
std::cout << *ppointId << ", ";
227+
ppointId++;
228+
}
229+
std::cout << std::endl;
234230

235-
cell->InternalSetPointIds(cell2->InternalPointIdsBegin(), cell2->InternalPointIdsEnd());
236-
std::cout << " Iterator test: PointIds for populated cell: ";
237-
typename TCell::PointIdInternalIterator pxpointId = cell->InternalPointIdsBegin();
238-
const typename TCell::PointIdInternalIterator pxendId = cell->InternalPointIdsEnd();
239-
while (pxpointId != pxendId)
240-
{
241-
std::cout << *pxpointId << ", ";
242-
pxpointId++;
231+
cell->InternalSetPointIds(cell2->InternalPointIdsBegin(), cell2->InternalPointIdsEnd());
232+
std::cout << " Iterator test: PointIds for populated cell: ";
233+
typename TCell::PointIdInternalIterator pxpointId = cell->InternalPointIdsBegin();
234+
const typename TCell::PointIdInternalIterator pxendId = cell->InternalPointIdsEnd();
235+
while (pxpointId != pxendId)
236+
{
237+
std::cout << *pxpointId << ", ";
238+
pxpointId++;
239+
}
240+
std::cout << std::endl;
243241
}
244-
std::cout << std::endl;
245-
246-
delete[] pointIds;
247242
return EXIT_SUCCESS;
248243
}
249244

Modules/Core/TestKernel/test/itkRandomImageSourceAttributesTest.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ itkRandomImageSourceAttributesTest(int, char *[])
8282
constexpr ImageType2D::ValueType max{ 1000.0 };
8383

8484
testStatus = itkRandomImageSourceAttributesTestHelper<ImageType2D>(size, spacing, origin, direction, min, max);
85+
if (testStatus != EXIT_SUCCESS)
86+
{
87+
return EXIT_FAILURE;
88+
}
8589
}
8690

8791
{

Modules/Filtering/BiasCorrection/test/itkMRIBiasFieldCorrectionFilterTest.cxx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,10 @@ itkMRIBiasFieldCorrectionFilterTest(int, char *[])
329329
optimizerInitialRadius = 0.02;
330330
volumeCorrectionMaximumIteration = 200;
331331
interSliceCorrectionMaximumIteration = 100;
332-
optimizerInitialRadius = 0.02;
333332

334333
filter->SetOptimizerInitialRadius(optimizerInitialRadius);
335334
filter->SetVolumeCorrectionMaximumIteration(volumeCorrectionMaximumIteration);
336335
filter->SetInterSliceCorrectionMaximumIteration(interSliceCorrectionMaximumIteration);
337-
filter->SetOptimizerInitialRadius(optimizerInitialRadius);
338336

339337
ITK_TEST_SET_GET_BOOLEAN(filter, UsingInterSliceIntensityCorrection, usingInterSliceIntensityCorrection);
340338
ITK_TEST_SET_GET_BOOLEAN(filter, UsingSlabIdentification, usingSlabIdentification);

Modules/Filtering/Path/test/itkHilbertPathTest.cxx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ HilbertPathTestHelper(unsigned int maxHilbertPathOder)
6060

6161
// path->EvaluateToIndex( 6 )
6262

63-
for (unsigned int d = 0; d < 10; ++d)
63+
for (unsigned int d = 0; d < path->NumberOfSteps(); ++d)
6464
{
6565
const IndexType index = path->TransformPathIndexToMultiDimensionalIndex(d);
6666

@@ -98,6 +98,10 @@ itkHilbertPathTest(int, char *[])
9898
ITK_EXERCISE_BASIC_OBJECT_METHODS(path2D, HilbertPath, Path);
9999

100100
testStatus = HilbertPathTestHelper<HilbertPathType2D>(maxHilbertPathOder);
101+
if (testStatus != EXIT_SUCCESS)
102+
{
103+
return EXIT_FAILURE;
104+
}
101105

102106
// Test dimension = 3
103107
using HilbertPathType3D = itk::HilbertPath<IndexValueType, 3>;
@@ -109,6 +113,10 @@ itkHilbertPathTest(int, char *[])
109113
ITK_EXERCISE_BASIC_OBJECT_METHODS(path3D, HilbertPath, Path);
110114

111115
testStatus = HilbertPathTestHelper<HilbertPathType3D>(maxHilbertPathOder);
116+
if (testStatus != EXIT_SUCCESS)
117+
{
118+
return EXIT_FAILURE;
119+
}
112120

113121
// Test dimension = 4
114122
using HilbertPathType4D = itk::HilbertPath<IndexValueType, 4>;

0 commit comments

Comments
 (0)