A local variable is read before any value is assigned to it
What it finds
int n; total += n;: a local variable without an initializer holds an indeterminate value until something is assigned to it, and reading it before is undefined.
The variable must be a scalar declared without initializer in a block, never have its address taken, and the function must have no labels. The statements after the declaration in the same block are followed while they do not mention the variable and call no macro that could assign it; the first statement that mentions it is reported if it is a plain expression statement, return or declaration that reads it before assigning it.
From the rule's source, uninitialized_read.rs.
int f(int); int sum(int k){ int n; int m; int total = 0; total += n;tx0 reports: n is read before a value is assigned to it m = k; total += m; return total;} int later(int k){ int x; if (k) x = 1; else x = 2; return x;} int returned(void){ int r; return f(r);tx0 reports: r is read before a value is assigned to it} void address(int *p); int through_pointer(void){ int v; address(&v); return v;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/c:uninitialized-read" = "off"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:uninitialized-read] reason="..."tx0 explain tx0/c:uninitialized-read shows the same in the terminal. Found a false positive? Report it.