An array or list is indexed with its own length, one past its last element
What it finds
items[items.Length] and list[list.Count] are always out of range: the last element is at Length - 1. A for loop whose condition is i <= items.Length and that indexes items[i] hits the same index in its last round.
From the rule's source, index_at_length.rs.
using System.Collections.Generic; class Bounds{ int Run(int[] items, List<int> list) { var last = items[items.Length];tx0 reports: items[items.Length] is one past the last element var first = list[list.Count - 1]; for (int i = 0; i <= items.Length; i++)tx0 reports: with i <= items.Length the last round indexes one past the end { last += items[i]; } for (int i = 0; i < items.Length; i++) { last += items[i]; } return last + first + list[list.Count];tx0 reports: list[list.Count] is one past the last element }} 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/csharp: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/csharp:index-at-length] reason="..."tx0 explain tx0/csharp:index-at-length shows the same in the terminal. Found a false positive? Report it.