[PATCH] D78374: [Analyzer][StreamChecker] Added evaluation of fread and fwrite.

Balázs Kéri via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 13 09:10:59 PDT 2020


balazske marked 2 inline comments as done.
balazske added a comment.

The intent is to model the fread-fwrite function failure by returning the error value and set the stream into error state. The error state is a composite of **ferror** and **feof**. The questions are now, at what case do these functions fail and with what error type?



================
Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:107
+  /// This value applies to all execution paths in ErrorState except the FEOF
+  /// case. In more detail, an EOF+indeterminate state is the same as EOF state.
+  bool FilePositionIndeterminate = false;
----------------
Szelethus wrote:
> The standard suggests that this happens on FERROR, not FEOF.
> 
> > If an error occurs, the resulting value of the file position indicator for the stream is indeterminate. If a partial element is read, its value is indeterminate.
> 
> It would be wild if the stream wouldn't set the FEOF flag after reaching the end of the file. Also, I would imagine FEOF being usually implemented with the file position indicator.
> 
> ```lang=bash
> $ cat test.cpp`
> ```
> ```lang=cpp
> #include "stdio.h"
> 
> int main() {
>   FILE *F = fopen("test.cpp", "r");
>   char Buf[1024];
>   const int READ_COUNT = 99999;
>   if (READ_COUNT != fread(Buf, sizeof(char), READ_COUNT, F)) {
>     printf("%i\n", feof(F));
>   }
> }
> ```
> ```lang=bash
> $ build/bin/clang++ test.cpp && ./a.out 
> 1
> 
> ```
> 
> Operations on an EOF and indeterminate stream are very different.
I wanted to say in that comment that `FilePositionIndeterminate` should be ignored if the `ErrorState` is `ErrorFEof`. In other words the file is never indeterminate if in EOF state.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78374





More information about the cfe-commits mailing list