[clang] [clang][analyzer] Support `fputs` in the StreamChecker (PR #73335)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 27 02:15:02 PST 2023
================
@@ -141,6 +141,24 @@ void error_fputc(void) {
fputc('A', F); // expected-warning {{Stream might be already closed}}
}
+void error_fputs(void) {
+ FILE *F = tmpfile();
+ if (!F)
+ return;
+ int Ret = fputs("XYZ", F);
+ if (Ret >= 0) {
+ clang_analyzer_eval(feof(F) || ferror(F)); // expected-warning {{FALSE}}
+ fputs("QWD", F); // no-warning
+ } else {
+ clang_analyzer_eval(Ret == EOF); // expected-warning {{TRUE}}
+ clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+ clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+ fputs("QWD", F); // expected-warning {{might be 'indeterminate'}}
+ }
+ fclose(F);
+ fputs("ABC", F); // expected-warning {{Stream might be already closed}}
+}
+
----------------
balazske wrote:
One type of test is missing, where the stream is in EOF state (`StreamTesterChecker_make_feof_stream(F)` can be used to get such a stream `F`) and a `fputc` or `fputs` is called. Then no error and no warning should be generated, and the state after the call should be non-error and non-EOF.
https://github.com/llvm/llvm-project/pull/73335
More information about the cfe-commits
mailing list