Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSVC warning C26495: ZwQuerySystemInformation, m_MetaDataObjectValue uninitialized #3843

Conversation

N-Dekker
Copy link
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
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
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.

None yet

3 participants