With below code, the error that array index out of bounds can't be checked.
voidfoo(intx){intbuf[10];if(x==1000)buf[x]=0;}
With passing 1000 to the function foo, there should be an error of index is out of bounds. But seems this can not be checked by cppcheck.
Do you know why? Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HI, my version is Cppcheck 2.16.0. Is there any option that need to be turned on to display the warnings? My command is just like below without using any option.
./cppcheck arrayIndexOutOfBounds.c
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
HI CHR, thanks so much for your reply. And I have another separated question. Could you help take a look. This problem is actually a famous example which is explained on below link. https://www.theregister.com/2014/01/09/x11_has_privilege_escalation_bug/. I copied the code piece from the checked file where the error should be.
if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) { bdfError("bad character name in BDF file\n"); goto BAILOUT; /* bottom of function, free and return error */
}
The charName should be copied with a limited length.
But I can't get the expected error which should be checked by the cppcheck.
./cppcheck --enable=warning bdfread.c
I attached the file bdfread.c and copied my result below.
Hello,
With below code, the error that array index out of bounds can't be checked.
With passing 1000 to the function foo, there should be an error of index is out of bounds. But seems this can not be checked by cppcheck.
Do you know why? Thanks!
Output from the (outdated) online demo:
Which version do you use?
HI, my version is Cppcheck 2.16.0. Is there any option that need to be turned on to display the warnings? My command is just like below without using any option.
./cppcheck arrayIndexOutOfBounds.c
You need to pass (at least)
--enable=warning
. By default, only errors are reported.HI CHR, thanks so much for your reply. And I have another separated question. Could you help take a look. This problem is actually a famous example which is explained on below link.
https://www.theregister.com/2014/01/09/x11_has_privilege_escalation_bug/. I copied the code piece from the checked file where the error should be.
The charName should be copied with a limited length.
But I can't get the expected error which should be checked by the cppcheck.
I attached the file bdfread.c and copied my result below.
With Cppcheck 2.16.0 I get this output:
I scanned the bdfread.c you attached and I used the same flags you did:
The full output I get is:
So it seems you get the errors but not the warnings. That is pretty strange.
Hi, I got where the problem is. It's my problem. Sorry for the trouble.