Fixed uninitialized variable m_mode in SymmetricCipher.h#13173
Open
mateea326 wants to merge 2 commits intokeepassxreboot:developfrom
Open
Fixed uninitialized variable m_mode in SymmetricCipher.h#13173mateea326 wants to merge 2 commits intokeepassxreboot:developfrom
mateea326 wants to merge 2 commits intokeepassxreboot:developfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes an uninitialized member in SymmetricCipher (crypto module) by ensuring m_mode is set to a defined value immediately upon construction, avoiding indeterminate results when mode() is called before init().
Changes:
- Replaced the defaulted constructor with an explicit inline constructor.
- Initialized
m_modetoSymmetricCipher::InvalidModeat construction time.
michaelk83
reviewed
Mar 20, 2026
src/crypto/SymmetricCipher.h
Outdated
Comment on lines
+52
to
+55
| explicit SymmetricCipher() = default; | ||
| explicit SymmetricCipher() | ||
| : m_mode(InvalidMode) | ||
| { | ||
| } |
There was a problem hiding this comment.
You should be able to keep the default constructor by specifying an initializer on the field itself: Mode m_mode{InvalidMode};
Author
There was a problem hiding this comment.
Fixed it and added Mode m_mode{InvalidMode}; as you suggested
droidmonkey
approved these changes
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
SymmetricCipherclass used a defaulted constructor (= default), which left them_modemember variable uninitialized. In C++, enum members are not automatically zero-initialized, meaning that ifmode()is called beforeinit(), it returns an indeterminate garbage value from the stack.This issue was identified via static analysis (
cppcheck) as anuninitMemberVarwarning in the crypto module.Fix: Replaced the defaulted constructor with an explicit constructor that initializes
m_modetoSymmetricCipher::InvalidMode:Impact:
init()is called.Screenshots
N/A — header-only change with no visual output.
Testing strategy
Run
cppcheckto confirm the warning is resolved:The
uninitMemberVarwarning form_modeshould no longer appear. Existing unit tests for the crypto module continue to pass unchanged.Type of change