[PATCH] D75045: [analyzer] Improved check of `fgetc` in StreamChecker.

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 24 07:08:39 PST 2020


martong added inline comments.


================
Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:356
+    State = State->set<StreamMap>(
+        StreamSym, StreamState{SS->K, false, SS->ShouldCallFerror});
+  }
----------------
Maybe adding a comment like `false /*Feof*/` could make this more readable. Even better, using two different strong types instead of the bool args could make it even more safe, but if that's too much hassle then it is may be not worth (I don't know if LLVM has a proper infrastructure for strong types).


================
Comment at: clang/test/Analysis/stream.c:182
+
+void check_fgetc_error() {
+  FILE *fp = fopen("foo.c", "r");
----------------
Do you have tests for `getc` as well? Maybe we could have at least one for getc too.


================
Comment at: clang/test/Analysis/stream.c:218
+    feof(fp);
+    fclose(fp); // expected-warning {{Should call}}
+  }
----------------
Perhaps `Should call ferror` is more informative for the readers of the tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75045/new/

https://reviews.llvm.org/D75045





More information about the cfe-commits mailing list