CRITICAL
Rule Definition
When a variable goes out of scope, all pointers or references to this variable become invalid. Any access to this data results in undefined behavior. The best way to make sure this situation does not occur is to have the pointer itself go out of scope at the same time as the pointed-to variable.
Remediation
Try to declare the local variable and the pointer in the same scope to avoid protection failures.
Violation Code Sample
int *p;
void f()
{
int i = 0;
p = &i; // Violation
}
Related Technologies
C++
Technical Criterion
Programming Practices - Unexpected Behavior
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.