An array is indexed with its own size or element count, one past its last element

tx0/c:index-at-array-sizedefaultwarningreliability/memory-safetydepth fastbug, cwe-193

What it finds

buf[sizeof buf] = '\0';: the valid indexes run up to the size minus one, so this writes one past the end, usually where sizeof buf - 1 was meant.

The array must be declared with a length in the file, and the index must be sizeof of it, for an array of a character type, or sizeof a / sizeof a[0] or sizeof a / sizeof *a.

From the rule's source, index_at_array_size.rs.

Example from the rule's tests
void terminate(void){  char buf[32];  int counts[8];  buf[sizeof(buf)] = '\0';tx0 reports: this index is the length of buf, one past its last element  counts[sizeof counts / sizeof counts[0]] = 0;tx0 reports: this index is the length of counts  buf[sizeof(buf) - 1] = '\0';}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/c:index-at-array-size" = "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:index-at-array-size] reason="..."

tx0 explain tx0/c:index-at-array-size shows the same in the terminal. Found a false positive? Report it.