The count that scanf, fscanf or sscanf returns is ignored, so a failed match goes unnoticed

tx0/c:scanf-result-ignoredrecommendedwarningsecurity/authn-authzdepth fastbug, cwe-252

What it finds

scanf("%d", &n); as a statement: scanf, fscanf and sscanf return how many values they stored, and on input that does not match, the variables keep whatever they held before, often nothing assigned at all. Without the count the code goes on with them.

The call must be a whole expression statement; a cast to void says the result is ignored on purpose.

From the rule's source, scanf_result_ignored.rs.

Example from the rule's tests
#include <stdio.h> int read_number(const char *text){  int n, m;  scanf("%d", &n);tx0 reports: the number of values scanf stored is ignored  if (sscanf(text, "%d", &m) != 1)    return -1;  (void)scanf("%d", &m);  return n + m;}
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:scanf-result-ignored" = "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:scanf-result-ignored] reason="..."

tx0 explain tx0/c:scanf-result-ignored shows the same in the terminal. Found a false positive? Report it.