![]() |
![]() |
2842 | ![]() |
||||
![]() | |||||||
| Arrays | |||||||
An apparent anomaly has been detected. Preceding operations imply that this expression will sometimes result in an access outside the bounds of an array. For example, in the code shown below, out of bounds array access will occur if the index n is greater than or equal to 10 - the presence of the "if" statement suggests that this is likely. Of course, if the value of n passed to function foo is always less than 10, the upper bound of the array will not be exceeded; but this would imply that the "if" statement is redundant and any code contained in the "if" block is also redundant.
/*PRQA S 2017,3120,3132,3203,3227,3408,3605,3689 ++*/
void foo(int n)
{
int a[10];
if (n > 10)
{
}
a[n] = 1; /* 2842 */
}
MISRA C:2012 Rules applicable to message 2842:
| Dir-4.1 (Required) | Run-time failures shall be minimized |
See also:
![]() | ||
| QA·C Source Code Analyser 8.1
MISRA C:2012 Compliance Module 1.0 © 2012 Programming Research. www.programmingresearch.com | Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index | Contents |