A goto jumps into a block past declarations that initialize variables
What it finds
goto retry; to a label inside a block that the goto is not in: the jump enters the block past the declarations before the label, whose initializers do not run, so the variables hold indeterminate values.
Only a block entered from outside that declares a variable with an initializer before the label counts.
From the rule's source, goto_into_block.rs.
int run(int n){ if (n) goto inside;tx0 reports: goto inside jumps into a block past the initialization of its variables { int k = n * 2;inside: n += k; } if (n > 1) goto out; n++;out: return n;} 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:goto-into-block" = "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:goto-into-block] reason="..."tx0 explain tx0/c:goto-into-block shows the same in the terminal. Found a false positive? Report it.