Rodri - 10 hours ago

Hi, I found a false negative regarding the rule arrayIndexOutOfBounds.

Cppcheck misses an out-of-bounds write when the array is accessed through a pointer alias.

int a[2];

void f() {
  int *p = a;
  p[2] = 0;
}

Actual result

Cppcheck does not report arrayIndexOutOfBounds. Replacing p[2] = 0 with a[2] = 0 produces the warning.

Expected result

Cppcheck should report the out-of-bounds write through the alias.

Verification

The issue was reproduced with:

cppcheck --output-format=xmlv2 --enable=all array_alias.cpp

Version: 2.21.0