Menu ▾ ▴

False negative: out-of-bounds write through pointer arithmetic

Rodri
2026-09-29
2026-09-30
  • Rodri

    Rodri - 2026-09-29

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

    Cppcheck misses an out-of-bounds write when array indexing is written as pointer arithmetic.

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

    Actual result

    Cppcheck does not report arrayIndexOutOfBounds. Replacing *(a + 2) = 0 with a[2] = 0 produces the warning.

    Expected result

    Cppcheck should report the out-of-bounds write in both forms.

    Verification

    The issue was reproduced with:

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

    Version: 2.21.0

     
  • CHR

    CHR - 2026-09-30
     

Log in to post a comment.