strlen measures a whole string only to compare the length with zero

tx0/c:strlen-emptiness-testrecommendedwarningperformance/algorithmicdepth fastperformance

What it finds

if (strlen(name) == 0): strlen walks the whole string to count it, where whether it is empty depends on the first character only. name[0] == '\0' answers in one step. The fix writes that when the string is a plain name.

From the rule's source, strlen_emptiness_test.rs.

Example from the rule's tests
#include <string.h> int empty(const char *name, const char **list){  if (strlen(name) == 0)tx0 reports: only the first character decides    return 1;  return strlen(list[0]) > 0 || strlen(name) == 4;tx0 reports: only the first character decides}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/c:strlen-emptiness-test" = "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:strlen-emptiness-test] reason="..."

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