A for loop's update moves its counter away from the bound of its condition
What it finds
for ($i = 0; $i < $n; $i--): the update moves the counter away from the bound, so the loop runs until the counter overflows or never ends. The update was meant to go the other way.
From the rule's source, wrong_loop_direction.rs.
<?phpfunction walk($n){ for ($i = 0; $i < $n; $i--) {tx0 reports: $i counts down, away from the bound of the condition step($i); } for ($j = $n; $j > 0; $j += 1) {tx0 reports: $j counts up, away from the bound of the condition step($j); } for ($k = 0; $k < $n; $k++) { step($k); } for ($m = $n; $m >= 0; $m--) { step($m); }} 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/php: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/php:wrong-loop-direction] reason="..."tx0 explain tx0/php:wrong-loop-direction shows the same in the terminal. Found a false positive? Report it.