[previous] 2843 [next] Suspicious: Dereference of an invalid pointer value.
Arrays

Dataflow analysis has identified a code construct which is suspicious. The code may be entirely safe but further investigation is advisable.

An array is being accessed and examination of the immediate context suggests that the element being accessed could sometimes be out of bounds.

For example, in the code shown below, the value of the array subscript 'x' will be '10' (leading to an array bounds violation) unless the parameter 'n' is greater than 0.


/*PRQA S 2017,3120,3132,3203,3227,3408,3605,3689 ++*/
void foo(int n)
{
   int a[10];
   int i;
   int x = 10;

   for (i = 0; i < n; ++i)
   {
      --x;
   }

   a[x] = 1;                      /* 2843 */
}



No MISRA C:2012 Rules applicable to message 2843


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