A loop tests feof before reading, so it runs once more after the last read fails

tx0/cpp:feof-looprecommendedwarningreliability/control-flowdepth fastbug

What it finds

while (!feof(f)) { fgets(line, n, f); ... }: the end-of-file flag is set only after a read has failed, so the body runs once more with the last line again or with nothing read. Testing the result of the read itself ends the loop at the right time.

From the rule's source, feof_loop.rs.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:feof-loop" = "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:feof-loop] reason="..."

tx0 explain tx0/cpp:feof-loop shows the same in the terminal. Found a false positive? Report it.