From 7f4c334c1bb760743e93a68bce8e650b0b715c6a Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Tue, 27 Dec 2022 14:04:59 +0100 Subject: [PATCH] COMP: Fix MSVC warning C26495: `m_PositionIndex` uninitialized Fixed VS2019 Code Analysis warnings, saying: > warning C26495: Variable 'm_PositionIndex' is uninitialized. > Always initialize a member variable (type.6) Also added in-class default member initializers to three other data members that were not yet initialized by the default-constructors of ImageConstIteratorWithIndex and ImageConstIteratorWithOnlyIndex. Note that `ImageConstIteratorWithIndex` and `ImageConstIteratorWithIndex` are rather "expensive" classes (having a virtual table) and their default-constructors are already non-trivial, so the extra cost of the added initialization appears relatively low. --- .../Common/include/itkImageConstIteratorWithIndex.h | 12 ++++++------ .../include/itkImageConstIteratorWithOnlyIndex.h | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Modules/Core/Common/include/itkImageConstIteratorWithIndex.h b/Modules/Core/Common/include/itkImageConstIteratorWithIndex.h index b6aa1be39a5..fef76af9cff 100644 --- a/Modules/Core/Common/include/itkImageConstIteratorWithIndex.h +++ b/Modules/Core/Common/include/itkImageConstIteratorWithIndex.h @@ -287,15 +287,15 @@ class ITK_TEMPLATE_EXPORT ImageConstIteratorWithIndex protected: // made protected so other iterators can access typename TImage::ConstWeakPointer m_Image; - IndexType m_PositionIndex; // Index where we currently are - IndexType m_BeginIndex; // Index to start iterating over - IndexType m_EndIndex; // Index to finish iterating: - // one pixel past the end of each - // row, col, slice, etc.... + IndexType m_PositionIndex{ { 0 } }; // Index where we currently are + IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over + IndexType m_EndIndex{ { 0 } }; // Index to finish iterating: + // one pixel past the end of each + // row, col, slice, etc.... RegionType m_Region; // region to iterate over - OffsetValueType m_OffsetTable[ImageDimension + 1]; + OffsetValueType m_OffsetTable[ImageDimension + 1]{}; const InternalPixelType * m_Position; const InternalPixelType * m_Begin; diff --git a/Modules/Core/Common/include/itkImageConstIteratorWithOnlyIndex.h b/Modules/Core/Common/include/itkImageConstIteratorWithOnlyIndex.h index 89e667b13ed..3c3db6c28e1 100644 --- a/Modules/Core/Common/include/itkImageConstIteratorWithOnlyIndex.h +++ b/Modules/Core/Common/include/itkImageConstIteratorWithOnlyIndex.h @@ -256,15 +256,15 @@ class ITK_TEMPLATE_EXPORT ImageConstIteratorWithOnlyIndex protected: // made protected so other iterators can access typename TImage::ConstPointer m_Image; - IndexType m_PositionIndex; // Index where we currently are - IndexType m_BeginIndex; // Index to start iterating over - IndexType m_EndIndex; // Index to finish iterating: - // one pixel past the end of each - // row, col, slice, etc.... + IndexType m_PositionIndex{ { 0 } }; // Index where we currently are + IndexType m_BeginIndex{ { 0 } }; // Index to start iterating over + IndexType m_EndIndex{ { 0 } }; // Index to finish iterating: + // one pixel past the end of each + // row, col, slice, etc.... RegionType m_Region; // region to iterate over - OffsetValueType m_OffsetTable[ImageDimension + 1]; + OffsetValueType m_OffsetTable[ImageDimension + 1]{}; bool m_Remaining; };