[clang] [analyzer] Note last "fclose" call from "ensureStreamOpened" (PR #109112)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 18 02:57:38 PDT 2024


================
@@ -1849,11 +1889,12 @@ ProgramStateRef StreamChecker::ensureStreamOpened(SVal StreamVal,
   if (SS->isClosed()) {
     // Using a stream pointer after 'fclose' causes undefined behavior
     // according to cppreference.com .
-    ExplodedNode *N = C.generateErrorNode();
-    if (N) {
-      C.emitReport(std::make_unique<PathSensitiveBugReport>(
+    if (ExplodedNode *N = C.generateErrorNode()) {
+      auto R = std::make_unique<PathSensitiveBugReport>(
           BT_UseAfterClose,
-          "Stream might be already closed. Causes undefined behaviour.", N));
+          "Stream might be already closed. Causes undefined behaviour.", N);
----------------
NagyDonat wrote:

```suggestion
          "Use of a stream that might be already closed", N);
```
As a somewhat offtopic remark, I'd suggest that you should replace this warning message because it's awkward and not phrased like the "usual" messages from the majority of the checkers.

Feel free to tweak my suggestion -- it's probably possible to find a slightly better wording.

I kept that the message says "might", which is presumably there because on other execution paths the stream might be still open -- but there are many other checkers which don't bother with this ambiguity and would boldly report "Use of a stream that is already closed" at this point.

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


More information about the cfe-commits mailing list