A local variable is read where some path to the read never assigned it
What it finds
int len; if (ok) len = n; return len;: on some path to the read the variable was never assigned, while on others it was. The value read on that path is indeterminate.
``cpp int fd; if (path != NULL) fd = open(path, O_RDONLY); return fd; // indeterminate when path is NULL ``
The rule follows each function on its paths as uninitialized-read does. Paths are kept apart while they are few, so a variable assigned under a condition and read only under the same condition is not reported; past four paths, or where the conditions are not the same values, the rule stays silent rather than guess. Conditions that are tied through other variables, as a switch on a kind that a goto path never sets, are not followed, so some reports are paths that cannot happen; the rule is in the strict tier.
From the rule's source, maybe_uninitialized_read.rs.
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/cpp:maybe-uninitialized-read" = "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/cpp:maybe-uninitialized-read] reason="..."tx0 explain tx0/cpp:maybe-uninitialized-read shows the same in the terminal. Found a false positive? Report it.