Checkers:UNINIT.STACK.ARRAY.MIGHT

From current

Reference > C/C++ checkers > UNINIT.STACK.ARRAY.MIGHT

This error indicates that the memory of a local array is read and there might be a path in the program where the memory hasn't been initialized.

Contents

Vulnerability and risk

Uninitialized variables located in a stack may have garbage data in them. Usage of such variables will lead to unpredictable behavior.

Example 1

1  extern void pfoo(int *);
2  extern int some_condition();
3  
4  void uninit_array_might() {
5      int *a[10];
6      if (some_condition()) {
7          int i;
8          for(i = 0; i < 10; i++) {
9              a[i] = 0;
10         }
11     }
12     pfoo(a[4]);
13 }

Klocwork produces an uninitialized local array reading report, indicating that the memory of array 'a' can be used at line 12, when the array might be uninitialized.

Related checkers

External guidance