UNINIT.CTOR.MUSTUninitialized variable in constructorThe UNINIT.CTOR.MUST checker finds class variables that haven't 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 int j; 4 public: 5 C() { 6 this->j = 0; 7 } 8 }; Klocwork flags line 7, indicating that the value of 'this->i' variable will remain uninitialized when the constructor exits. Related checkers |