Menu

FP Bughunting : Array index out of bounds, cannot determine that i is less than 2

dp11
2022-01-17
2022-01-22
  • dp11

    dp11 - 2022-01-17

    With head and this

    int main()
    {   
        int D[] = {1,2,3};  
        int j = (sizeof(D) / sizeof(E))-1;
        int a;
        int i;
        for(i=0;i< j ; i++)
                a = D[i];
    }
    

    and this command line

    ./cppcheck --bug-hunting ../FP2.c
    

    I get :

    ../FP2.c:9:10: error: Array index out of bounds, cannot determine that i is less than 3 [bughuntingArrayIndexOutOfBounds]
       a = D[i];
             ^
    ../FP2.c:9:10: error: Array index out of bounds, cannot determine that i is not negative [bughuntingArrayIndexNegative]
       a = D[i];
             ^
    
     

    Last edit: dp11 2022-01-17
  • dp11

    dp11 - 2022-01-22

    could someone check I'm not going made i.e cppcheck should know i is positive and the bounds of the loop.

     
  • Daniel Marjamäki

    thanks! I have created ticket https://trac.cppcheck.net/ticket/10757

     
  • dp11

    dp11 - 2022-01-22

    Thanks, just for my interest does this mean that with out bug hunting enabled there is a possibility of false negatives in normal operation ?

     
    • Daniel Marjamäki

      No. Bug hunting uses a totally separated and very different value flow analysis. It was written from scratch to be "soundy".

       

      Last edit: Daniel Marjamäki 2022-01-22
  • dp11

    dp11 - 2022-01-22

    Thanks for the extra info.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.