rspec/rules/S946/cfamily/rule.adoc

28 lines
788 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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).
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
int* f(void) {
int local_auto;
return &local_auto; // Noncompliant, returning address of an object allocated on the stack.
}
----
2021-04-28 16:49:39 +02:00
== 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
ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::rspecator-view[]