A semicolon right after the head of a loop is its whole body, and the block after it runs once
What it finds
while (n--); { total += n; } or for (i = 0; i < n; i++); followed by an indented statement: the semicolon on the line of the loop's head is the body, the loop runs without doing anything, and the statement meant as its body runs once afterwards.
The semicolon must be on the same line as the closing parenthesis, and the next statement either a block or one that starts on a later line indented deeper than the loop. Loops that wait on purpose, while (busy());, are followed by a statement at the same indentation and left alone.
From the rule's source, empty_loop_body.rs.
int busy(void); int count(int n){ int total = 0; while (n--);tx0 reports: this semicolon is the whole body of the loop { total += n; } for (n = 0; n < 4; n++);tx0 reports: this semicolon is the whole body of the loop total++; while (busy()); return total;} 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:empty-loop-body" = "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:empty-loop-body] reason="..."tx0 explain tx0/c:empty-loop-body shows the same in the terminal. Found a false positive? Report it.