TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

SR:  6.5#2Checked automatically with code checker

Synopsis:Array indices must be within bounds.
Language:C
Severity Level:1
Category:CONVERSIONS


Description:

Array subscripting requires a pointer to object type and one or more integral subscript expressions. The indices must be within the bounds values of the (allocated) array. This is a language constraint. To avoid memory access outside the array the index should be within the bounds of the array. For example:

int i;
int a[6];

for (i = 0; i <= 6; i++)
{
   a[i] = 0; /* WRONG: Index gets a value greater than the number of elements.*/
}

This should have been

int i;
int a[6];

for (i = 0; i < 6; i++)
{
   a[i] = 0; /* RIGHT */
}