A loop over an array runs one step past its end because its condition uses <=
What it finds
for (i = 0; i <= 10; i++) buf[i] = 0; with buf declared with 10 elements: the last step reads or writes buf[10], one past the end. < was meant.
The bound must be the literal length of an array the file declares, not a parameter, the body must index that array with the loop variable alone, and must not change the loop variable itself.
From the rule's source, loop_past_array_end.rs.
void clear(void){ int buf[10]; int other[11]; int i; for (i = 0; i <= 10; i++)tx0 reports: i reaches 10, one past the end of buf buf[i] = 0; for (int j = 0; j <= 10; j++)tx0 reports: j reaches 10, one past the end of buf buf[j] = 1; for (i = 0; i <= 10; i++) other[i] = 0; for (i = 0; i < 10; i++) buf[i] = 0;} 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:loop-past-array-end" = "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:loop-past-array-end] reason="..."tx0 explain tx0/c:loop-past-array-end shows the same in the terminal. Found a false positive? Report it.