[PATCH] D15921: [analyzer] Utility to match function calls.

Alexander Riccio via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 5 13:47:21 PST 2016


ariccio added a subscriber: ariccio.
ariccio added a comment.

Side note: Has anybody ever considered just treating `fopen` and `fclose` like `malloc` and `free`?

On Windows I use a trick that I discovered what I call "the `_Post_ptr_invalid_` hack" because* the `_Post_ptr_invalid_` SAL annotation lets me treat the argument to `CloseHandle` like the argument to `free`, and reports double closes as double frees.

Here we'd just treat the `FILE*` as a different region of memory, to check that they're not mixed.

- this also works in part because a Windows `HANDLE` is just a `typedef`d `void*`


================
Comment at: cfe/trunk/lib/StaticAnalyzer/Checkers/SimpleStreamChecker.cpp:106
@@ -108,3 +105,3 @@
 SimpleStreamChecker::SimpleStreamChecker()
-    : IIfopen(nullptr), IIfclose(nullptr) {
+    : OpenFn("fopen"), CloseFn("fclose", 1) {
   // Initialize the bug types.
----------------
Why specify the RequiredArgs for `fclose`,  and not `fopen`?


Repository:
  rL LLVM

http://reviews.llvm.org/D15921





More information about the cfe-commits mailing list