The variables a loop's condition tests never change in the loop, which has no other way out

tx0/c:loop-condition-never-changesrecommendedwarningreliability/control-flowdepth fastbug, cwe-835

What it finds

while (left > 0) { total += step; } with nothing in the body that changes left: once the condition holds, it holds forever, and the loop never ends. Usually the update was forgotten or changes another variable.

The condition must test local variables or parameters only, without calls, whose address is never taken in the function; the body must not change them, call a function with their address, or leave the loop with break, return, goto or a call.

From the rule's source, loop_condition_never_changes.rs.

Example from the rule's tests
int drain(int left, int step){  int total = 0;  while (left > 0)tx0 reports: nothing in the loop changes what this condition tests    total += step;  while (step > 0)    step--;  return total;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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/c:loop-condition-never-changes" = "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:loop-condition-never-changes] reason="..."

tx0 explain tx0/c:loop-condition-never-changes shows the same in the terminal. Found a false positive? Report it.