If a function argument is an array and it is declared using pointer notation (int *arr) then the out of bounds check works, but if declared using array notation (int arr[]) then there is no out of bounds warning, see the example below:
voidfunc1a(char*str);voidfunc2a(charstr[]);voidfunc1b(char*str);voidfunc2b(charstr[]);intmain(void)
{
charstr_sized[2] ="A";func1a(str_sized);func2a(str_sized);charstr_unsized[] ="AB";func1b(str_unsized);func2b(str_unsized);return0;
}
voidfunc1a(char*str)
{
str[2] ='B'; // warning: Array index out of bounds; 'str' buffer size is 2 and it is accessed at offset 2. [ctuArrayIndex]
}
voidfunc2a(charstr[])
{
str[2] ='B'; // missing warning
}
voidfunc1b(char*str)
{
str[3] ='B'; // warning: Array index out of bounds; 'str' buffer size is 3 and it is accessed at offset 3. [ctuArrayIndex]
}
voidfunc2b(charstr[])
{
str[3] ='B'; // missing warning
}
/col
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
for information.. the ctu analysis in the "traditional" analysis will always be pretty limited. The analysis will go much deeper in the "bug hunting" analysis but that does not have an array index out of bounds check yet.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi!
If a function argument is an array and it is declared using pointer notation (
int *arr
) then the out of bounds check works, but if declared using array notation (int arr[]
) then there is no out of bounds warning, see the example below:/col
thanks! I created ticket https://trac.cppcheck.net/ticket/9788
for information.. the ctu analysis in the "traditional" analysis will always be pretty limited. The analysis will go much deeper in the "bug hunting" analysis but that does not have an array index out of bounds check yet.