Skip to content

[clang-tidy] Check request: detect saving stack addresses beyond their lifetime #122985

@asund

Description

@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 calls 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:static analyzerquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions