A local array has a length computed at run time, which can overflow the stack
What it finds
char buf[len]; in a function: the size of a variable-length array is only known at run time, and it lives on the stack, so a large or hostile length overflows the stack without any way to detect it. C11 made them optional. A fixed bound, or memory from malloc that can be checked, is safer.
The length must read a variable or parameter of the function; a length written with a macro or an enumerator is constant.
From the rule's source, variable_length_array.rs.
enum { SIZE = 16 }; void fill(int n){ char buf[n];tx0 reports: this array's length is computed at run time char fixed[SIZE]; char other[64]; buf[0] = fixed[0] = other[0];} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/c:variable-length-array" = "warning"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:variable-length-array] reason="..."tx0 explain tx0/c:variable-length-array shows the same in the terminal. Found a false positive? Report it.