Skip to content

Commit 72ea1f2

Browse files
committed
BUG: Fix uninitialized variable use in ANTS neighborhood correlation metric
Fix uninitialized variable use in `ANTS` neighborhood correlation metric: ensure that `fixedImageGradient` and `movingImageGradient` have valid values before assigning them to the `scanMem` struct that scans over images. Fixes: ``` Run-Time Check Failure #3 - The variable 'fixedImageGradient' is being used without being initialized. ``` The bug was affecting a number of tests in the `ITKRegistrationMethodsv4Test` module. Signaled at https://open.cdash.org/viewTest.php?onlyfailed&buildid=7067466 and https://open.cdash.org/viewTest.php?onlyfailed&buildid=7069241
1 parent d8f088f commit 72ea1f2

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Modules/Registration/Metricsv4/include/itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.hxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,14 @@ ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader<
483483
scanMem.sFixedFixed = sFixedFixed;
484484
scanMem.sMovingMoving = sMovingMoving;
485485

486-
scanMem.fixedImageGradient = fixedImageGradient;
487-
scanMem.movingImageGradient = movingImageGradient;
486+
if (this->m_ANTSAssociate->GetComputeDerivative() && this->m_ANTSAssociate->GetGradientSourceIncludesFixed())
487+
{
488+
scanMem.fixedImageGradient = fixedImageGradient;
489+
}
490+
if (this->m_ANTSAssociate->GetComputeDerivative() && this->m_ANTSAssociate->GetGradientSourceIncludesMoving())
491+
{
492+
scanMem.movingImageGradient = movingImageGradient;
493+
}
488494

489495
scanMem.mappedFixedPoint = mappedFixedPoint;
490496
scanMem.mappedMovingPoint = mappedMovingPoint;

0 commit comments

Comments
 (0)