[previous] MISRA-C:2004  Rule  9.1:  (Required) [next] All automatic variables shall have been assigned a value before being used.
The intent of this rule is that all variables shall have been written to before they are read. This does not necessarily require initialisation at declaration.

Note that according to the ISO C standard, variables with static storage duration are automatically initialised to zero by default, unless explicitly initialised. In practice, many embedded environments do not implement this behaviour. Static storage duration is a property of all variables declared with the static storage class specifier, or with external linkage. Variables with automatic storage duration are not usually automatically initialised.

Example Code:


/* PRQA S 2983,3447 ++ */
#include "misra.h"
#include "m2cmex.h"


extern S16 test_0901a( const S16 *p );


extern S16 test_0901( void )
{
   S16 a;
   S16 b;
   S16 c;
   S16 d;
   S16 e;
   S16 r;

   r = a;                          /* MISRA Violation */

   if ( s16a > 0 )
   {
       b = s16a;
       e = s16a;
   }

   r = r + b;                      /* MISRA Violation */

   c = test_0901a( &d );           /* MISRA Violation */

   d = 1;

   c += test_0901a( &e );          /* MISRA Violation */

   return r + c + d;
}


QAC messages that encompass this guideline:

2883 This 'goto' statement will always bypass the initialization of local variables.
2961 Definite: Using value of uninitialized automatic object '%s'.
2962 Apparent: Using value of uninitialized automatic object '%s'.
2971 Definite: Passing address of uninitialized object '%s' to a function parameter declared as a pointer to const.
2972 Apparent: Passing address of uninitialized object '%s' to a function parameter declared as a pointer to const.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents