An array is indexed with a constant outside its bounds

tx0/cpp:constant-index-out-of-boundsdefaultwarningreliability/memory-safetydepth fastbug, cwe-787

What it finds

int a[4]; a[4] = 0;: the index is a constant at or past the length of the array, or negative, so the access is outside the array. Taking the address one past the end, as &a[4], is allowed and left alone, as is anything under sizeof.

The array must be a variable, not a parameter, declared in the file with a literal length; the index must be written with literals.

From the rule's source, constant_index_out_of_bounds.rs.

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/cpp:constant-index-out-of-bounds" = "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/cpp:constant-index-out-of-bounds] reason="..."

tx0 explain tx0/cpp:constant-index-out-of-bounds shows the same in the terminal. Found a false positive? Report it.