[PATCH] D69948: [Checkers] Added support for freopen to StreamChecker.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 3 07:18:26 PST 2019


balazske added inline comments.


================
Comment at: clang/test/Analysis/stream.c:160
+    } else {
+      // Open failed, f1 points now to an invalid stream but this condition is currently not checked.
+      rewind(f1);
----------------
martong wrote:
> This comment is confusing for me. Maybe there are typos here?
> Isn't the 'freopen' failed? `fopen` was successful and it's return value was checked in line 153.
> `f1` seems to be ok here (still associated with "foo.c"), only `f2` is bad, as we see in line 162.
> 
> Or `f1` is already closed here, even though it could not open the new file?
> 
> 
> > If a new filename is specified, the function first attempts to close any file already associated with stream (third parameter) and disassociates it. Then, independently of whether that stream was successfuly closed or not, freopen opens the file specified by filename and associates it with the stream just as fopen would do using the specified mode.
> 
> https://stackoverflow.com/questions/20908740/check-the-return-value-of-freopen-in-c
> 
The `freopen` has failed, not the `fopen`. I think we can not know if f1 points to any file after this, or is in closed state (but we know that is not safe to use). Probably both the close and the re-open can fail.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69948





More information about the cfe-commits mailing list