A character array is initialized with a string exactly as long as the array, leaving out the terminating zero
What it finds
char code[3] = "abc";: C allows a string literal to fill an array exactly, dropping its terminating zero, so the array is not a string, and strlen or printf("%s") on it read past its end. An array one longer, or char code[] = "abc", keeps the zero.
The length must be written with literals and the initializer with string literals only. Arrays declared const, which are tables of characters filled exactly on purpose, and arrays marked nonstring are left alone.
From the rule's source, array_drops_terminator.rs.
char code[3] = "abc";tx0 reports: the string fills all 3 bytes of the arraychar tab[2] = "\t\n";tx0 reports: the string fills all 2 bytes of the arraychar ok[4] = "abc";char open[] = "abc"; 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:array-drops-terminator" = "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:array-drops-terminator] reason="..."tx0 explain tx0/c:array-drops-terminator shows the same in the terminal. Found a false positive? Report it.