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

Full description
Might return an address on the stack.
Coding standards
- CERT DCL30-C
Declare objects with appropriate storage durations
- CWE 562
Return of Stack Variable Address
Code examples
The following code example fails the check and will give a warning:
int *example(void) {
int a[20];
return a; //a is a local array
}
The following code example passes the check and will not give a warning about this issue:
int* example(void) {
int *p,i;
p = (int *)malloc(sizeof(int));
return p; //OK - p is dynamically allocated
}