strncmp compares fewer characters than the string literal it is given has
What it finds
strncmp(arg, "--verbose", 6): only the first six characters of the literal are compared, so --verb and --verbatim match as well. The length was probably counted wrong or left from an earlier literal; sizeof("--verbose") - 1 keeps them together.
The length must be a constant written with literals, positive and smaller than the length of the literal.
From the rule's source, strncmp_short_length.rs.
#include <string.h> int option(const char *arg){ if (strncmp(arg, "--verbose", 6) == 0)tx0 reports: strncmp compares only 6 of the 9 characters of the literal return 1; return strncmp(arg, "--verbose", 9) == 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:strncmp-short-length" = "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:strncmp-short-length] reason="..."tx0 explain tx0/c:strncmp-short-length shows the same in the terminal. Found a false positive? Report it.