A constant size given with an array is larger than the array

tx0/cpp:constant-size-exceeds-arraydefaultwarningreliability/memory-safetydepth fastbug, cwe-787

What it finds

char buf[16]; memset(buf, 0, 32); or fgets(buf, 64, f): the size passed with the buffer is a constant larger than the array, so the function reads or writes past its end.

The array must be a variable, not a parameter, declared in the file with a literal length and with elements of a character type, so that the length counts bytes; the size must be written with literals.

From the rule's source, constant_size_exceeds_array.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-size-exceeds-array" = "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-size-exceeds-array] reason="..."

tx0 explain tx0/cpp:constant-size-exceeds-array shows the same in the terminal. Found a false positive? Report it.