21 lines
653 B
Plaintext
21 lines
653 B
Plaintext
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).
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
int* f(void) {
|
|
int local_auto;
|
|
return &local_auto; // Noncompliant, returning address of an object allocated on the stack.
|
|
}
|
|
----
|
|
|
|
|
|
== See
|
|
|
|
* MISRA C:2004, 17.6
|
|
* MISRA {cpp}:2008, 7-5-2
|
|
* MISRA C:2012, 18.6
|
|
* https://wiki.sei.cmu.edu/confluence/x/UtcxBQ[CERT, DCL30-C.] - Declare objects with appropriate storage durations
|
|
|