[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
Thu Jan 11 00:56:29 PST 2024
================
@@ -324,6 +343,60 @@ 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}}
+ } else {
+ 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 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);
+}
+
+void error_ftello(void) {
+ FILE *F = tmpfile();
+ if (!F)
+ return;
+ long rc = ftello(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}}
----------------
balazske wrote:
To be exact, this test should be a copy of the previous test, only with `ftello` (and use of `off_t`).
https://github.com/llvm/llvm-project/pull/77580
More information about the cfe-commits
mailing list