A slice, array or string is indexed at its length, which is always out of range

tx0/go:index-at-lengthdefaultwarningbug

What it finds

s[len(s)]: the indices of a slice, array or string run from 0 to len(s)-1, so indexing at the length is always out of range and panics. The last element is s[len(s)-1].

The indexed expression must be a variable of this file whose declaration shows that it is a slice, an array or a string: by its written type, or by a value that is a slice or array literal, a string literal or a make of a slice. Maps, where m[len(m)] is a fine key, and values of unknown type are left alone.

From the rule's source, index_at_length.rs.

Example from the rule's tests
package p func f(s []int, m map[int]string, t string) (int, string, byte) {	a := s[len(s)]tx0 reports: s[len(s)] is always out of range and panics	b := m[len(m)]	c := t[len(t)]tx0 reports: t[len(t)] is always out of range and panics	u := make([]int, 3)	u[len(u)] = 1tx0 reports: u[len(u)] is always out of range and panics	return a + s[len(s)-1], b, c}
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/go:index-at-length" = "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/go:index-at-length] reason="..."

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