The result of a string's find is stored in an int or unsigned, which cannot hold npos and truncates large positions

tx0/cpp:string-position-in-intrecommendedwarningreliability/strings-and-regexdepth fastbug

What it finds

find returns a size_t, and std::string::npos is its largest value; stored in an int it becomes -1 by an implementation-defined conversion, and comparisons with npos no longer match. size_t or auto keep the value.

From the rule's source, string_position_in_int.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:

tx0.toml
[rules]
"tx0/cpp:string-position-in-int" = "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:string-position-in-int] reason="..."

tx0 explain tx0/cpp:string-position-in-int shows the same in the terminal. Found a false positive? Report it.