MISRA C:2012 Rule 18.6
The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist
Description
The address of an object with automatic or thread-local storage shall not be copied to another object that persists after the first object has ceased to exist1 .
Rationale
The address of an object becomes indeterminate when the lifetime of that object expires. Any use of an indeterminate address results in undefined behavior.
Polyspace Implementation
Polyspace® reports a violation of this rule when a pointer to a local variable leaves the scope of the variable. For instance:
A function returns a pointer to a local variable.
A function performs the assignment
globPtr = &locVar.globPtris a global pointer variable andlocVaris a local variable.A function performs the assignment
*paramPtr = &locVar.paramPtris a function parameter that is, for instance, anint**pointer andlocVaris a localintvariable.
Polyspace applies this rule on memory allocated using the
alloca function and ignores static local variables.
Polyspace assumes that the local objects within a function definition are in the
same scope.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Pointers and Arrays |
| Category: Required |
| AGC Category: Required |
PQL Name: std.misra_c_2012.R18_6 |
Version History
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.