Not sure if this has been reported by before, but there's another false positive in cppcheck 2.5 when run with --enable=portability. The test case is:
cppcheck 2.5
--enable=portability
#include <stdio.h> int main(int argc, const char* argv[]) { argv++; if (argc>0) printf("%s\n", (argv-1)[0]); return 0; }
Code compiles fine and is perfectly valid C:
# gcc foo3.c -o foo3 && ./foo3 ./foo3
...but cppcheck complains:
cppcheck
# cppcheck --enable=portability foo3.c Checking foo3.c ... foo3.c:4:37: portability: Undefined behaviour, pointer arithmetic 'argv-1' is out of bounds. [pointerOutOfBounds] if (argc>0) printf("%s\n", (argv-1)[0]); ^
Thanks! I have created https://trac.cppcheck.net/ticket/10367
Log in to post a comment.
Not sure if this has been reported by before, but there's another false positive in
cppcheck 2.5
when run with--enable=portability
. The test case is:Code compiles fine and is perfectly valid C:
...but
cppcheck
complains:Thanks! I have created https://trac.cppcheck.net/ticket/10367