rspec/rules/S946/cfamily/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

47 lines
1.0 KiB
Plaintext

== Why is this an issue?
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
[source,cpp]
----
int* f(void) {
int local_auto;
return &local_auto; // Noncompliant, returning address of an object allocated on the stack.
}
----
== Resources
* 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::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
The address of 'xxx' is invalid once the function returns.
'''
== Comments And Links
(visible only on this page)
=== is duplicated by: S838
=== is related to: S837
=== is related to: S839
endif::env-github,rspecator-view[]