A loop counter of type char or short is compared with a bound of a wider type, which it may never reach
What it finds
for (unsigned char i = 0; i < n; i++) with an int n: once n is above 255, the counter wraps around to 0 before it reaches the bound, and the loop never ends.
The counter and the bound must be variables whose types the file shows.
From the rule's source, narrow_loop_counter.rs.
void clear(char *buf, int n){ for (unsigned char i = 0; i < n; i++)tx0 reports: i has 8 bits and may wrap before it reaches n buf[i] = 0;} 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:
[rules]
"tx0/c:narrow-loop-counter" = "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:narrow-loop-counter] reason="..."tx0 explain tx0/c:narrow-loop-counter shows the same in the terminal. Found a false positive? Report it.