MISRAC2012-Rule-1.3_r
In this section:
Synopsis
(Required) There shall be no occurrence of undefined or critical unspecified behavior.
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
A stack address is stored in a global pointer.
Coding standards
- CERT DCL30-C
Declare objects with appropriate storage durations
- CWE 466
Return of Pointer Value Outside of Expected Range
Code examples
The following code example fails the check and will give a warning:
int *px;
void example() {
int i = 0;
px = &i; // assigning the address of stack
// variable a to the global px
}
The following code example passes the check and will not give a warning about this issue:
void example(int *pz) {
int x; int *px = &x;
int *py = px; /* local variable */
pz = px; /* parameter */
}