A for loop moves its counter away from the bound of its condition
What it finds
for (int i = 0; i < n; i--) counts away from n: the loop runs until the counter overflows, or forever. The update was meant to go the other way.
From the rule's source, wrong_loop_direction.rs.
class Loops{ void Run(int[] items, int n) { for (int i = 0; i < n; i--)tx0 reports: i-- moves the counter away from the bound in the condition { } for (int j = n; j >= 0; j += 1)tx0 reports: j += 1 moves the counter away from the bound in the condition { } for (int k = n - 1; k >= 0; k--) { } }} 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/csharp:wrong-loop-direction" = "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/csharp:wrong-loop-direction] reason="..."tx0 explain tx0/csharp:wrong-loop-direction shows the same in the terminal. Found a false positive? Report it.