Code can be compiled and result is fine. But cppcheck will report an error of it.
#define BUF_SIZE 1024
#define MAX_LENG 80
static unsigned char path[MAX_LENG];
unsigned char file_buf[BUF_SIZE*2];
memset(file_buf, 0, sizeof(file_buf));
strcpy(file_buf, "KID ");
strncat(file_buf, &path[strlen(path)-12], 10); //error this line
I tried a few time, and still cannot find the reason. Anyone can give me some hints ?
Thanks all the answers.
but I have more questions: If this is a fatal error , why compiler passed and result is what I want ? Under what condition it will have trouble ?
There is any alternative way to realize it ?
And if I changed it into
strncat(file_buf, &path[strlen(path)-12], 5);
cppcheack error will disappear. Why?