Skip to content

Fix MSVC warning C26495: ZwQuerySystemInformation, m_MetaDataObjectValue uninitialized#3843

Merged
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Fix-Variable-uninitialized-ZwQuerySystemInformation
Jan 4, 2023
Merged

Fix MSVC warning C26495: ZwQuerySystemInformation, m_MetaDataObjectValue uninitialized#3843
dzenanz merged 2 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Fix-Variable-uninitialized-ZwQuerySystemInformation

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Jan 2, 2023

Fixed Visual Studio 2019 Code Analysis warnings from both MetaDataObject and WindowsMemoryUsageObserver, saying:

warning C26495: Variable is uninitialized. Always initialize a member variable (type.6)

Fixed VS2019 Code Analysis warnings, saying:
> warning C26495: Variable 'itk::MetaDataObject::m_MetaDataObjectValue' is uninitialized.
> Always initialize a member variable (type.6)

Note that `MetaDataObject<MetaDataObjectType>` is a rather "expensive" class
(typically heap-allocated, and having a virtual table), so the extra cost of
the added initialization appears relatively low.
Fixed VS2019 Code Analysis warnings, saying:
> warning C26495: Variable 'itk::WindowsMemoryUsageObserver::ZwQuerySystemInformation' is uninitialized.
> Always initialize a member variable (type.6).

Also added an in-class default member initializer to m_hNTLib, which was not yet
initialized by the default-constructor of WindowsMemoryUsageObserver either.

Note that `WindowsMemoryUsageObserver` is a rather "expensive" class
(having a virtual table) and its default-constructor is already non-trivial,
so the extra cost of the added initialization appears relatively low.
@github-actions github-actions Bot added the area:Core Issues affecting the Core module label Jan 2, 2023
@N-Dekker
Copy link
Copy Markdown
Contributor Author

N-Dekker commented Jan 2, 2023

Note that MSVC/Code Analysis does not always produce this warning about uninitialized member variables, when it should. As I reported at developercommunity.visualstudio.com: False negative (missing) /analyze warning C26495: Variable is uninitialized. Always initialize a member variable (type.6). For a code example, see https://godbolt.org/z/c4GhdPMc8

So even when all of those "C26495" warnings would be fixed, there might still be some more uninitialized member variables... So please upvote my MSVC bug report: https://developercommunity.visualstudio.com/t/False-negative-missing-analyze-warnin/10239447

@N-Dekker N-Dekker marked this pull request as ready for review January 2, 2023 17:21
Copy link
Copy Markdown
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

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

💯

@dzenanz dzenanz merged commit a1f40a7 into InsightSoftwareConsortium:master Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants