strlen measures c_str() of a string, whose length the string already knows

tx0/cpp:strlen-of-c-strstrictnoteperformance/allocationdepth fastperformance

What it finds

strlen(s.c_str()) walks the characters to find the terminating zero, while s.size() is stored; the two also differ when s holds a zero byte. The fix uses size().

From the rule's source, strlen_of_c_str.rs.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/cpp:strlen-of-c-str" = "note"

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:strlen-of-c-str] reason="..."

tx0 explain tx0/cpp:strlen-of-c-str shows the same in the terminal. Found a false positive? Report it.