[clang] [clang][analyzer] StreamChecker: Add more APIs, invalidate fscanf args (PR #82476)

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 03:35:35 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}}
----------------
NagyDonat wrote:

Do I understand it correctly that here the checker would print a note explaining that it assumes that `fscanf` reaches the end-of-file? Without that this checker behavior would be difficult to understand.

https://github.com/llvm/llvm-project/pull/82476


More information about the cfe-commits mailing list