A counting loop ends on != instead of < or >
What it finds
for (int i = 0; i != n; i++) stops only when i hits n exactly. If the counter can step over the bound, because it starts past it or moves by more than one, the loop never ends; i < n ends it either way.
Reported when the condition compares with != a counter that the update moves with ++ or --.
From the rule's source, loop_inequality.rs.
class Loops { void run(int n, int[] values) { for (int i = 0; i != n; i++) {tx0 reports: this loop ends only when its counter equals the bound exactly values[i] = 0; } for (int i = 0; i < n; i++) { values[i] = 1; } }} 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/java:loop-inequality" = "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/java:loop-inequality] reason="..."tx0 explain tx0/java:loop-inequality shows the same in the terminal. Found a false positive? Report it.