/
2nd Array Index Out Of Bounds

2nd Array Index Out Of Bounds

This checks array index out of bounds.(for two-dimensional array)

 

refer to below example:

Caution: It is possible there will be more test cases.

case 1

function_1(int (*array_parameter)[4])
{
int basic_array[9][4]={0,};

for(int i=0 ; i<11 ; i++) 
{
for(int j=0 ; j<12 ; j++)
{
basic_array[i][j]=0;
}
}


printf("(*(basic_array+10))[10] : %d ",(*(basic_array+10))[10]);
printf("*(basic_array[10]+10) : %d ",*(basic_array[10]+10));
printf("*(*(basic_array+10)+10)) : %d ",*(*(basic_array+10)+10));

}

case 2

function_1(int (*array_parameter)[4])
{
int basic_array[9][4]={0,};

int (*array_ptr)[4] = basic_array; 
for(int i=0 ; i<11 ; i++) 
{
for(int j=0 ; j<12 ; j++)
{
array_ptr[i][j] = 0;
}
}

 

This checker should not detect for below case

case 1

function_1(int (*array_parameter)[4])
{
int basic_array[9][4]={0,};

int (*array_ptr)[4] = basic_array; 
for(int i=0 ; i<9 ; i++) 
{
for(int j=0 ; j<4 ; j++)
{
array_ptr[i][j] = 0;
}
}

 

 

the checker config can be like below:

 

{
  "code""CHECK_ARRAY_INDEX_OUT_OF_BOUNDS_TWO_DIMESIONAL",
  "name""Checking array index out of bounds",
  "type""BOTH",
  "categoryName""Tizen",
  "severityCode""CRI",
  "version""2.5.33",
  "description""Array index out of bounds",
  "isActive"true,
  "properties": {       
  },
  "cwe"129
}

 

 

Related content