Memory for a copy of a string is allocated without room for its terminating zero
What it finds
malloc(strlen(s)): the length of a string does not count its terminating zero, so a copy of s into the new memory writes one byte past its end. strlen(s) + 1 is the size of a copy.
Sometimes the memory is meant for the characters alone, without the zero, which is why the rule is not in the default set.
From the rule's source, malloc_strlen.rs.
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/cpp:malloc-strlen" = "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/cpp:malloc-strlen] reason="..."tx0 explain tx0/cpp:malloc-strlen shows the same in the terminal. Found a false positive? Report it.