The address of a local variable is stored in a global variable, where it outlives the variable
What it finds
current = &frame; with a global current and a local frame: when the function returns, the global points to stack memory that the next calls reuse.
The target must be a variable declared outside any function, the value the address of, or a local array of, the function the assignment is in, without static.
From the rule's source, local_address_in_global.rs.
int *current;int saved; void run(void){ int frame = 0; static int kept; current = &frame;tx0 reports: the global current keeps the address of the local frame current = &kept; current = &saved;} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:local-address-in-global" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/c:local-address-in-global] reason="..."tx0 explain tx0/c:local-address-in-global shows the same in the terminal. Found a false positive? Report it.