Checkers:UNINIT.CTOR.MUST
From current
Reference > C/C++ checkers > UNINIT.CTOR.MUST
This error indicates that a class field was not initialized in the constructor.
Vulnerability and risk
C++ does not provide default values for fields of non-user-defined types. Possible use of uninitialized class member in class methods may lead to unpredictable behavior.
Mitigation and prevention
To avoid use of uninitialized variables, constructors should initialize all class fields.
Example 1
1 class C { 2 int i; 3 int j; 4 public: 5 C(bool flag) { 6 if (flag) i = 0; 7 } 8 };
Klocwork reports an uninitialized member in constructor, indicating that the value of 'this->j' variable is not initialized, when constructor exits at line 7.
Related checkers
- UNINIT.CTOR.MIGHT
- UNINIT.CTOR.MUST


