[clang] [clang][analyzer] Support `fgetc` in StreamChecker (PR #72627)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 23 01:46:18 PST 2023
================
@@ -259,14 +283,33 @@ void error_indeterminate_clearerr(void) {
fclose(F);
}
+void error_indeterminate_fgetc(void) {
+ FILE *F = fopen("file", "r+");
+ if (!F)
+ return;
+ int rc = fseek(F, 0, SEEK_SET);
+ if (rc) {
+ if (feof(F)) {
+ clang_analyzer_warnIfReached(); // no warning
+ fgetc(F); // no warning
+ } else if (ferror(F)) {
+ fgetc(F); // expected-warning {{might be 'indeterminate'}}
+ } else {
+ fgetc(F); // expected-warning {{might be 'indeterminate'}}
+ }
+ }
+ fclose(F);
+}
+
void error_indeterminate_fputc(void) {
FILE *F = fopen("file", "r+");
if (!F)
return;
int rc = fseek(F, 0, SEEK_SET);
if (rc) {
if (feof(F)) {
----------------
balazske wrote:
The branch `feof(F)` is not needed at all here. There is a previous test case that tells that `feof(F)` is never true when fseek to a 0 position is called.
https://github.com/llvm/llvm-project/pull/72627
More information about the cfe-commits
mailing list