How to reproduce:
#include "stdio.h" void foo(const char* message, short length) { const char *end = message + length; printf("%s, %d\n", message, *end); } int main() { foo("a", 1); // Remove this line the error is gone foo("bbb", 3); }
Output
cppcheck.exe --enable=portability test.c Checking test.c ... test.c:6:31: portability: Undefined behaviour, pointer arithmetic 'message+length' is out of bounds. [pointerOutOfBounds] const char *end = message + length; ^ test.c:13:16: note: Calling function 'foo', 2nd argument '3' value is 3 foo("bbb", 3); ^ test.c:6:31: note: Pointer arithmetic overflow const char *end = message + length; ^
It seems it uses the size of "a" to check "bbb"
Thanks for reporting. I think this issue is covered by https://trac.cppcheck.net/ticket/11026
Log in to post a comment.
How to reproduce:
Output
It seems it uses the size of "a" to check "bbb"
Thanks for reporting. I think this issue is covered by https://trac.cppcheck.net/ticket/11026