errno is tested after a conversion function without being set to zero before the call

tx0/cpp:errno-not-clearedrecommendedwarningreliability/error-handlingdepth fastbug

What it finds

n = strtol(s, &end, 10); if (errno == ERANGE): the conversion functions set errno on failure but never clear it, so a value left from an earlier call is mistaken for an error of this one. errno = 0; before the call makes the test mean something.

The function must test errno after the call and assign it zero nowhere before the call.

From the rule's source, errno_not_cleared.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:errno-not-cleared" = "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:errno-not-cleared] reason="..."

tx0 explain tx0/cpp:errno-not-cleared shows the same in the terminal. Found a false positive? Report it.