Skip to content

Commit 77abeac

Browse files
jhlegarretadzenanz
authored andcommitted
BUG: Initialize miscellaneous local variables
Initialize miscellaneous local variables to avoid undefined behavior. Remove the now unnecessary `update.Fill(0.0)` calls and associated conditions in `itk::ESMDemonsRegistrationFunction::ComputeUpdate(...)`. Fixes: ``` Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx:308:18: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations] 308 | point[j] += displacement[j]; | ^ ``` and ``` Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx:338:18: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations] 338 | point[j] += displacement[j]; | ``` and ``` Modules/Registration/PDEDeformable/include/itkESMDemonsRegistrationFunction.hxx:331:22: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations] 331 | mappedPoint[j] += it.GetCenterPixel()[j]; | ``` and ``` Modules/Registration/PDEDeformable/include/itkESMDemonsRegistrationFunction.hxx:383:19: warning: iteration 2 invokes undefined behavior [-Waggressive-loop-optimizations] 383 | update[j] = factor * usedGradientTimes2[j]; | ``` raised for example in: https://open.cdash.org/viewBuildError.php?type=1&buildid=10154210
1 parent 1090d31 commit 77abeac

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

Modules/Filtering/ImageGrid/include/itkWarpImageFilter.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ WarpImageFilter<TInputImage, TOutputImage, TDisplacementField>::DynamicThreadedG
283283

284284
// iterator for the output image
285285
ImageRegionIteratorWithIndex<OutputImageType> outputIt(outputPtr, outputRegionForThread);
286-
IndexType index;
287-
PointType point;
288-
DisplacementType displacement;
286+
IndexType index{};
287+
PointType point{};
288+
DisplacementType displacement{};
289289
NumericTraits<DisplacementType>::SetLength(displacement, ImageDimension);
290290
static_assert(PointType::Dimension == ImageDimension, "ERROR: Point type and ImageDimension must be the same!");
291291
if (this->m_DefFieldSameInformation)

Modules/Registration/PDEDeformable/include/itkESMDemonsRegistrationFunction.hxx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ESMDemonsRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>::Co
171171
const FloatOffsetType & itkNotUsed(offset)) -> PixelType
172172
{
173173
auto * globalData = (GlobalDataStruct *)gd;
174-
PixelType update;
174+
PixelType update{};
175175
IndexType FirstIndex = this->GetFixedImage()->GetLargestPossibleRegion().GetIndex();
176176
IndexType LastIndex = this->GetFixedImage()->GetLargestPossibleRegion().GetIndex() +
177177
this->GetFixedImage()->GetLargestPossibleRegion().GetSize();
@@ -190,7 +190,6 @@ ESMDemonsRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>::Co
190190

191191
if (movingPixValue == NumericTraits<MovingPixelType>::max())
192192
{
193-
update.Fill(0.0);
194193
return update;
195194
}
196195

@@ -324,7 +323,7 @@ ESMDemonsRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>::Co
324323
}
325324
else if (this->m_UseGradientType == GradientEnum::MappedMoving)
326325
{
327-
PointType mappedPoint;
326+
PointType mappedPoint{};
328327
this->GetFixedImage()->TransformIndexToPhysicalPoint(index, mappedPoint);
329328
for (unsigned int j = 0; j < ImageDimension; ++j)
330329
{
@@ -352,11 +351,7 @@ ESMDemonsRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>::Co
352351
const double usedGradientTimes2SquaredMagnitude = usedGradientTimes2.GetSquaredNorm();
353352

354353
const double speedValue = fixedValue - movingValue;
355-
if (itk::Math::abs(speedValue) < m_IntensityDifferenceThreshold)
356-
{
357-
update.Fill(0.0);
358-
}
359-
else
354+
if (itk::Math::abs(speedValue) >= m_IntensityDifferenceThreshold)
360355
{
361356
double denom;
362357
if (m_Normalizer > 0.0)
@@ -370,11 +365,7 @@ ESMDemonsRegistrationFunction<TFixedImage, TMovingImage, TDisplacementField>::Co
370365
denom = usedGradientTimes2SquaredMagnitude;
371366
}
372367

373-
if (denom < m_DenominatorThreshold)
374-
{
375-
update.Fill(0.0);
376-
}
377-
else
368+
if (denom >= m_DenominatorThreshold)
378369
{
379370
const double factor = 2.0 * speedValue / denom;
380371

0 commit comments

Comments
 (0)