Issue |
122985
|
Summary |
[clang-tidy] Check request: detect saving stack addresses beyond their lifetime
|
Labels |
clang-tidy
|
Assignees |
|
Reporter |
asund
|
This seems to be missed by existing stack address check as the address doesn't escape scope of the stack but is preserved between scopes using a static variable.
```
auto f() {
process stack_array[] = { method1, method2, method3 };
static *process process_to_use = nullptr;
if (!process) {
// some expensive init later...
process = &stack_array[n];
}
if (!process) {
process->do_processing(); // segfault
}
}
```
process_to_use has a stale value when the function is called again. stack_array needs to have static lifetime in this case.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs