A char variable is compared with EOF, which a char cannot tell apart from a real character
What it finds
char c; while ((c = getchar()) != EOF): getchar returns an int so that EOF differs from every character. Stored in a char, either the byte 0xFF reads as EOF and ends the loop early, or, where char is unsigned, EOF never matches and the loop does not end. The variable must be an int.
The variable must be declared in the file as char, signed char or unsigned char, and EOF must come from the headers.
From the rule's source, char_compared_with_eof.rs.
#include <stdio.h> int count(FILE *f){ char c; int i; int n = 0; while ((c = fgetc(f)) != EOF)tx0 reports: c is a char, which cannot hold EOF apart from the characters n++; while ((i = fgetc(f)) != EOF) n++; return n;} Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/c:char-compared-with-eof" = "off"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:char-compared-with-eof] reason="..."tx0 explain tx0/c:char-compared-with-eof shows the same in the terminal. Found a false positive? Report it.