BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels#3845
Conversation
|
|
||
| // By default we set up a 3-level image registration. | ||
| this->SetNumberOfLevels(3); | ||
| this->SetNumberOfLevels(m_NumberOfLevels); |
There was a problem hiding this comment.
Please consider removing the this->SetNumberOfLevels call. The function call seems completely redundant now that this->m_NumberOfLevels is already initialized by the in-class { 3 } default member initialization.
There was a problem hiding this comment.
@N-Dekker please have a closer look at the SetNumberOfLevels method implementation.
There was a problem hiding this comment.
It is guarded by if (this->m_NumberOfLevels != numberOfLevels), which makes this call redundant? If we want this to be called, it would make sense to make in-class initialization to 0.
There was a problem hiding this comment.
Thanks for your effort so far, Jon. Do I understand correctly that this PR now changes the NumberOfLevels of a default constructed ImageRegistrationMethodv4 from 3 to 0? If so, is that intended?
There was a problem hiding this comment.
😅 again my mistake ✋. Thanks for the head-up @N-Dekker. Fixed in e939dab. I think the initialization needs to be reworked to make it more consistent, as the m_SmoothingSigmasPerLevel and the m_MetricSamplingPercentagePerLevel ivars are initialized both in the constructor and the method at issue here to different values. But I'd leave it for a separate PR.
There was a problem hiding this comment.
I think the initialization needs to be reworked to make it more consistent, as the m_SmoothingSigmasPerLevel and the m_MetricSamplingPercentagePerLevel ivars are initialized both in the constructor and the method at issue here to different values. But I'd leave it for a separate PR.
PR #3876.
|
Thanks Jon! One more little suggestion, could you please make the commit text a little bit more specific? For example: Update: Thanks for adjusting the commit subject line this way, Jon 👍 |
|
|
||
| // By default we set up a 3-level image registration. | ||
| this->SetNumberOfLevels(3); | ||
| this->SetNumberOfLevels(m_NumberOfLevels); |
There was a problem hiding this comment.
It is guarded by if (this->m_NumberOfLevels != numberOfLevels), which makes this call redundant? If we want this to be called, it would make sense to make in-class initialization to 0.
| @@ -532,7 +532,7 @@ class ITK_TEMPLATE_EXPORT ImageRegistrationMethodv4 : public ProcessObject | |||
| SetMetricSamplePoints(); | |||
|
|
|||
| SizeValueType m_CurrentLevel; | |||
There was a problem hiding this comment.
Wouldn't it make sense to move all of these ivar initializations here?
There was a problem hiding this comment.
That is a style change. I used the initialization list to fix the bug because the initialization trend that is being pushed in the code base is that one. IMHO best would be to propose the style change you propose in a separate PR. I could do a separate commit within this PR, but I prefer the bug to be fixed and merged as soon as possible.
I also realize that the implementation file contains method documentation blocks. Following the previous comment, best would be to do a separate PR to address that.
Anybody is welcome to contribute with them.
54367db to
e847af4
Compare
ImageRegistrationMethodv4::m_NumberOfLevels
|
#3845 (comment) @N-Dekker Done in e847af4. |
Fix uninitialized value warning for `itk::ImageRegistrationMethodv4::m_NumberOfLevels`. Fixes: ``` UMC ==16463== Conditional jump or move depends on uninitialised value(s) ==16463== at 0x9BD983: itk::ImageRegistrationMethodv4, itk::Image, itk::DisplacementFieldTransform, itk::Image, itk::PointSet > >::SetNumberOfLevels(unsigned long) (itkImageRegistrationMethodv4.hxx:881) ==16463== by 0x9C44B6: itk::ImageRegistrationMethodv4, itk::Image, itk::DisplacementFieldTransform, itk::Image, itk::PointSet > >::ImageRegistrationMethodv4() (itkImageRegistrationMethodv4.hxx:103) ==16463== by 0x9BBFA0: itk::SyNImageRegistrationMethod, itk::Image, itk::DisplacementFieldTransform, itk::Image, itk::PointSet > >::SyNImageRegistrationMethod() (itkSyNImageRegistrationMethod.hxx:41) ==16463== by 0x9B5974: itk::SyNImageRegistrationMethod, itk::Image, itk::DisplacementFieldTransform, itk::Image, itk::PointSet > >::New() (itkSyNImageRegistrationMethod.h:84) ==16463== by 0xA15CD4: itkSyNPointSetRegistrationTest(int, char**) (itkSyNPointSetRegistrationTest.cxx:132) ==16463== by 0x317927: main (ITKRegistrationMethodsv4TestDriver.cxx:222) ``` and similar warnings triggered by registration testing code. Visible in: https://open.cdash.org/viewDynamicAnalysis.php?buildid=8374098 Introduced in d1c46d6. Recover the comment highlighting the initialization to a 3-level registration, and reword to make the need for the call (with a value different from the current value) even more explicit.
e847af4 to
e939dab
Compare
|
This is ready to be merged. IMO should be merged asap to prevent the addressed valgrind defects from being present across commits. |
When a data member is set by a "setter" member function (`Set##name`, `On`, or `Off`), it is still recommended to initialize the member according to this guideline. Doing so prevents problems like the one addressed by pull request InsightSoftwareConsortium/ITK#3845 commit InsightSoftwareConsortium/ITK@a31e8bf "BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels" by Jon Haitz Legarreta Gorroño, 10 January 2023
PR #3886. |
When a data member is set by a "setter" member function (`Set##name`, `On`, or `Off`), it is still recommended to initialize the member according to this guideline. Doing so prevents problems like the one addressed by pull request InsightSoftwareConsortium/ITK#3845 commit InsightSoftwareConsortium/ITK@a31e8bf "BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels" by Jon Haitz Legarreta Gorroño, 10 January 2023
Fix uninitialized value warning for
itk::ImageRegistrationMethodv4::m_NumberOfLevels.Fixes:
and similar warnings triggered by registration testing code.
Visible in:
https://open.cdash.org/viewDynamicAnalysis.php?buildid=8374098
Introduced in d1c46d6.
Recover the comment highlighting the initialization to a 3-level
registration, and reword to make the need for the call (with a value
different from the current value) even more explicit.
PR Checklist