[clang] [clang][analyzer] StreamChecker: Add more APIs, invalidate fscanf args (PR #82476)
Alejandro Álvarez Ayllón via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 21 05:19:56 PST 2024
================
@@ -339,3 +363,107 @@ void fflush_on_open_failed_stream(void) {
}
fclose(F);
}
+
+void test_fscanf_eof() {
+ FILE *F1 = tmpfile();
+ if (!F1)
+ return;
+
+ int a;
+ unsigned b;
+ int ret = fscanf(F1, "%d %u", &a, &b);
+ char c = fgetc(F1); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+ // expected-warning at -1 {{File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior}}
----------------
alejandro-alvarez-sonarsource wrote:
Yes, there is a note such as
```
clang/test/Analysis/stream.c Line 374: Assuming stream reaches end-of-file here
```
https://github.com/llvm/llvm-project/pull/82476
More information about the cfe-commits
mailing list