[clang] [clang][analyzer] Support 'tello' and 'fseeko' in the StreamChecker (PR #77580)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 10 09:01:15 PST 2024
================
@@ -324,6 +355,57 @@ void error_fseek_0(void) {
fclose(F);
}
+void error_fseeko_0(void) {
+ FILE *F = fopen("file", "r");
+ if (!F)
+ return;
+ int rc = fseeko(F, 0, SEEK_SET);
+ if (rc) {
+ int IsFEof = feof(F), IsFError = ferror(F);
+ // Get ferror or no error, but not feof.
+ clang_analyzer_eval(IsFError);
+ // expected-warning at -1 {{FALSE}}
+ // expected-warning at -2 {{TRUE}}
+ clang_analyzer_eval(IsFEof);
+ // expected-warning at -1 {{FALSE}}
+ // Error flags should not change.
+ clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+ if (IsFError)
+ clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+ else
+ clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+ } else {
+ clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+ clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+ // Error flags should not change.
+ clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+ clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+ }
+ fclose(F);
+}
+
+void error_ftell(void) {
+ FILE *F = fopen("file", "r");
+ if (!F)
+ return;
+ long Ret = ftell(F);
+ if (!(Ret >= 0)) {
+ clang_analyzer_eval(Ret == -1L); // expected-warning {{TRUE}}
+ }
+ fclose(F);
+}
+
+void error_ftello(void) {
+ FILE *F = fopen("file", "r");
+ if (!F)
+ return;
+ off_t Ret = ftello(F);
+ if (!(Ret == -1)) {
+ clang_analyzer_eval(Ret >= 0); // expected-warning {{TRUE}}
+ }
+ fclose(F);
+}
+
----------------
balazske wrote:
This test should be better:
```
void error_ftell(void) {
FILE *F = fopen("file", "r");
if (!F)
return;
long rc = ftell(F);
if (rc >= 0)
clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
else
clang_analyzer_eval(rc == -1); // expected-warning {{TRUE}}
clang_analyzer_eval(feof(F) && ferror(F)); // expected-warning {{FALSE}}
StreamTesterChecker_make_feof_stream(F);
rc = ftell(F);
clang_analyzer_eval(feof(F)); // expected-warning {{TRUE}}
clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
StreamTesterChecker_make_ferror_stream(F);
rc = ftell(F);
clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
fclose(F);
}
```
https://github.com/llvm/llvm-project/pull/77580
More information about the cfe-commits
mailing list