I get an array out of bounds false positive with these nested for loops:
#defineNULL((void*)0)#defineLIST_SIZE1staticvoid*list[LIST_SIZE];voidunregister_ptr(void*ptr){inti;//indexof"ptr"in"list"intj;//indexofthelastnon-nullelementin"list"//Remove"ptr"from"list"for(i=0;i<LIST_SIZE;i++){if(list[i]==ptr){for(j=i;j<LIST_SIZE-1;j++){if(list[j+1]==NULL){break;}}/* Replace the "ptr" entry with the last non-null "list" entry, and set * this last non-null entry (which might by the "ptr" entry) to NULL */list[i]=list[j];list[j]=NULL;return;}}}
Tested on cppcheck v2.7, v2.8 and the current git master branch.
Attached file is the output of cppcheck from git master branch, with the --debug flag.
Did you try using unsigned integers for i and j? It might fix this (asking because I'm aware of various static checkers that will produce warnings when you use a signed integer for an array index)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I get an array out of bounds false positive with these nested for loops:
cppcheck --verbose sample.c
Tested on cppcheck v2.7, v2.8 and the current git master branch.
Attached file is the output of cppcheck from git master branch, with the --debug flag.
Thank you very much for you work on cppcheck !
Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/11113
Thanks !
Did you try using unsigned integers for i and j? It might fix this (asking because I'm aware of various static checkers that will produce warnings when you use a signed integer for an array index)