The result of getchar, getc or fgetc is stored in a char, where EOF cannot be told apart

tx0/c:stream-character-in-charstrictwarningreliability/arithmeticdepth fastbug, cwe-197

What it finds

char c = getchar();: getchar, getc and fgetc return an int so that EOF is a value apart from every character. Stored in a char, EOF becomes a character, the byte 255 either ends the input early or EOF is never seen, depending on whether char is signed.

The result must be stored, without a cast, in a variable declared as a char of any signedness in the file.

From the rule's source, stream_character_in_char.rs.

Example from the rule's tests
#include <stdio.h> int first(FILE *f){  char c = getchar();tx0 reports: getchar returns an int, and c as a char cannot keep EOF apart  unsigned char u;  int fine = fgetc(f);  u = getc(f);tx0 reports: u as a char  return c + u + fine;}
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 strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/c:stream-character-in-char" = "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:stream-character-in-char] reason="..."

tx0 explain tx0/c:stream-character-in-char shows the same in the terminal. Found a false positive? Report it.