[previous] MISRA-C:2004  Rule  17.6:  (Required) [next] The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist.
If the address of an automatic object is assigned to another automatic object of larger scope, or to a static object, or returned from a function then the object containing the address may exist beyond the time when the original object ceases to exist (and its address becomes invalid).

For example

int8_t * foobar( void )
{
   int8_t local_auto;
   return &local_auto;      /* not compliant */
}


QAC messages that encompass this guideline:

3217 Address of automatic object exported to a pointer with linkage or wider scope.
3225 Address of automatic object exported using a function parameter.
3230 Address of automatic object assigned to local pointer with static storage duration.
4140 Address of automatic object exported in function return value.



(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