Issue 133954
Summary False-positive due to bad reasoning for file I/O clang:static analyzer
Labels
Assignees
Reporter alavrentiev
    Code analyzer reports a false-positive in this situation.

There's an infinite loop reading from a file. The loop contains the following code:
```
for (;;) {
size_t n_read = fread(buffer, 1, sizeof(buffer), fp);
  // 19←Assuming this stream operation fails
  // 27←File position of the stream might be 'indeterminate' after a failed operation. Can cause undefined behavior

if ( n_read <= 0 ) {
 // 20←Assuming 'n_read' is > 0
 break;
}
...
}
```
At "20" `n_read` cannot be "assumed" to be "> 0" if at "19" the read had been already assumed as failed, as in that case `n_read` would be exactly *0*, and so the loop is exited in the conditional `break` and "27" never occurs.

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to