UNINIT.STACK.ARRAY.MUST
Uninitialized array
The UNINIT.STACK.ARRAY.MUST checker finds instances in which the memory of a local array is read when the memory hasn't been initialized.
Vulnerability and risk
In C++, stack variables aren't initialized by default. They generally contain random junk data from the current content of stack memory. The uninitialized data may contain values that cause program flow to change in unintended ways, possibly with security implications.
Mitigation and prevention
To avoid initialization problems, make sure all variables and resources are initialized explicitly before their first usage. Take note of complex conditional situations and make sure that all paths include the initialization.
Vulnerable code example
Copy
extern void ifoo(int);
void uninit_array_must() {
int a[10];
ifoo(a[1]);
}
Klocwork flags line 5, indicating that the memory of uninitialized array 'a' is used.