<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/133954>133954</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            False-positive due to bad reasoning for file I/O clang:static analyzer
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          alavrentiev
      </td>
    </tr>
</table>

<pre>
    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.

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxkVEGPnDoM_jXmYi0KgVngwIGd7Ujv9C69V4Y4Q97LJKMkTLv99VWA3W1VKYIQ7M-fP9uhGM3VMQ9weoHTa0FrWnwYyNIjsEuGH8Xk1dtw9oqRHNm3nxww8N2HFJFQk438dPfRJPNgNA7TYiJGk1ZKxrsSxAhi_LpwYJBtRHJonDbOJEbr_R0DkzLuijr4WwY0lkv8uhx_Z-8SGRcxLYzaW-u_Z-PZK4Y6I8OzOJYYtQ8IsoP6JS_ZI7QvIMZofvK3hO5bDoVQv6LOO5DdtGrNAeQZq_zIhl7_dt7nU33PmzojwVnCKBDkBeQFqx6-SOieoRdjjOstE9uzT4Hphv7OYRMBNRkb__KX7Yf_xVjGXUXv0Ost3QPmZq5LwokRZGuc4sThZhylrCeSThy2OhjL6jNkiWdyONMaGVenWBvHCide6GF82ItidFbrU5dzliazexdup_vOVvydLch2985UTESov2AuBE6B6f9Ds_YVxFiW5cf-95KNCUFKKUBKhGdxoD0LnMk5f6QtKQdklY2SP872WFKi0UgbStVvBgtvPYUL5YTZIdn8_YYHClI85MrVpbg3LSWcKfKfJL771WYQ5B80J_uGILMe4-boFEa_hds61UTkHyax2vE4t67a6kk2o-6SPIvNMefcZraOHxzQz_MaYlaoUEOt-rqngoeqbepTXYmmK5ZBkqqqaiZ9OlV1M3HXylpWdat4arknWZhBCnkSjaiqrhJNW3ZattR3omuE7Ka-h0bwjYwtrX3cSh-uhYlx5aGq6_7UFJYmtvH9HghDtnqa1muERlgTU_z0SyZZHi5_jr5aeSsOqSx_9G4bah-2icZ_QF7-xdmSu0I9xkTJzB_3SbEGOywp3WOe6a3driYt61TO_gbykgMfr6d78P_xnEBeNvYR5OVI4DHIXwEAAP__wEN8-A">