UNINIT.CTOR.MIGHTUninitialized variable in constructor possibleThe UNINIT.CTOR.MIGHT checker finds class variables that may not have been initialized in the constructor. Vulnerability and riskIn C++, primitive data type variables need to be initialized explicitly. Use of uninitialized members in class methods typically leads to unpredictable behavior, and may have security implications. Mitigation and preventionTo avoid use of uninitialized variables, make sure that constructors initialize all class fields. Vulnerable code example1 class C { 2 int i; 3 public: 4 C(bool flag) { 5 if (flag) i = 0; 6 } 7 }; Klocwork flags line 6, indicating that the value of 'this->i' variable might remain uninitialized when constructor exits. Related checkers |