I have the code below. After running the cppcheck tool, it reports an error as Buffer is accessed out of bounds? An error is reported on line with the snprintf.
#include <stdio.h>
int main(int argc, char * argv[])
{
if (argc > 1) {
char testref[8] = "";
snprintf(testref, sizeof(testref), "Ref:%s", argv[1]);
printf("===>testref=%s\n", testref);
}
}
below the command line interaction :
amin@ubuntu:$ gcc test.c -o test
amin@ubuntu:$
amin@ubuntu:$ ./test hello_world
===>testref=Ref:hel
amin@ubuntu:$ cppcheck test.c
Checking test.c...
[test.c:7]: (error) Buffer is accessed out of bounds.
amin@ubuntu:$
Is cppcheck correct to report this error?