Menu

False negative: dynamic array out-of-bounds write is missed

Rodri
2 days ago
2 days ago
  • Rodri

    Rodri - 2 days ago

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

    In the following C++ program, cppcheck should report an arrayIndexOutOfBounds warning because a dynamic array of size 2 is accessed at index 2. However, cppcheck reports no such warning.

    int *a = new int[2];
    
    int main() {
      a[0] = 0;
      a[1] = 0;
      a[2] = 0;
      return a[0];
    }
    

    Actual result

    Cppcheck reports no arrayIndexOutOfBounds warning.

    Expected result

    Cppcheck should report arrayIndexOutOfBounds for the write to a[2].

    Verification

    The issue was reproduced with:

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

    Version: 2.21.0

     
  • CHR

    CHR - 2 days ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14934

     

Log in to post a comment.

Monday.com Logo