Skip to content

BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels#3845

Merged
dzenanz merged 1 commit intoInsightSoftwareConsortium:masterfrom
jhlegarreta:InitializeImageRegistrationMethodIvar
Jan 10, 2023
Merged

BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels#3845
dzenanz merged 1 commit intoInsightSoftwareConsortium:masterfrom
jhlegarreta:InitializeImageRegistrationMethodIvar

Conversation

@jhlegarreta
Copy link
Copy Markdown
Member

@jhlegarreta jhlegarreta commented Jan 3, 2023

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.

PR Checklist

@github-actions github-actions bot added area:Registration Issues affecting the Registration module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances labels Jan 3, 2023

// By default we set up a 3-level image registration.
this->SetNumberOfLevels(3);
this->SetNumberOfLevels(m_NumberOfLevels);
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker please have a closer look at the SetNumberOfLevels method implementation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uops you're right. Thanks for the heads-up @dzenanz ! Amended the commit to initialize it to 0 in 54367db.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@N-Dekker
Copy link
Copy Markdown
Contributor

N-Dekker commented Jan 3, 2023

Thanks Jon! One more little suggestion, could you please make the commit text a little bit more specific?

For example:

BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to move all of these ivar initializations here?

Copy link
Copy Markdown
Member Author

@jhlegarreta jhlegarreta Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jhlegarreta jhlegarreta force-pushed the InitializeImageRegistrationMethodIvar branch 2 times, most recently from 54367db to e847af4 Compare January 3, 2023 23:20
@jhlegarreta jhlegarreta changed the title BUG: Fix uninitialized value warning BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels Jan 3, 2023
@jhlegarreta jhlegarreta changed the title BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels BUG: Fix uninitialized value ImageRegistrationMethodv4::m_NumberOfLevels Jan 3, 2023
@jhlegarreta
Copy link
Copy Markdown
Member Author

#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.
@jhlegarreta jhlegarreta force-pushed the InitializeImageRegistrationMethodIvar branch from e847af4 to e939dab Compare January 3, 2023 23:51
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jon 👍

@jhlegarreta
Copy link
Copy Markdown
Member Author

This is ready to be merged. IMO should be merged asap to prevent the addressed valgrind defects from being present across commits.

@dzenanz dzenanz merged commit a31e8bf into InsightSoftwareConsortium:master Jan 10, 2023
@jhlegarreta jhlegarreta deleted the InitializeImageRegistrationMethodIvar branch January 10, 2023 14:00
N-Dekker added a commit to N-Dekker/ITKSoftwareGuide that referenced this pull request Jan 15, 2023
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
@jhlegarreta
Copy link
Copy Markdown
Member Author

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.

PR #3886.

dzenanz pushed a commit to InsightSoftwareConsortium/ITKSoftwareGuide that referenced this pull request Jan 19, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Registration Issues affecting the Registration module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants