Checkers:UNINIT.STACK.ARRAY.PARTIAL.MUST

From current

Reference > C/C++ checkers > UNINIT.STACK.ARRAY.PARTIAL.MUST

This error indicates that an element of a local array is read when it may be uninitialized, because the array hasn't been initialized completely.

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  int incomplete_init() {
2      int a[10];
3      int i;
4      for (i = 9; i > 0; i--) {
5          a[i] = i;
6      }
7      return a[0];
8  }

Klocwork produces an uninitialized local array element reading report, indicating that an element of uninitialized array 'a' with the index equal to 0 is used at line 7.

Related checkers

External guidance