[clang] [clang][analyzer] Support `fgets` in the SteamChecker (PR #73638)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 24 02:47:33 PST 2024


================
@@ -778,42 +781,61 @@ void StreamChecker::evalFgetc(const FnDescription *Desc, const CallEvent &Call,
   assertStreamStateOpened(OldSS);
 
----------------
steakhal wrote:

This patch caused a downstream test failure.
Here is the fix:

```suggestion
  // We don't model the buffer, thus they should escape.
  State = Call.invalidateRegions(C.blockCount(), State);
```

Test where it currently breaks:
```c++
void test_double_switch_ok() {
  char buffer[10] = {10};
  FILE *F1 = tmpfile();
  if (!F1)
    return;

  char* s = fgets(buffer, sizeof(buffer), F1); // ok
  if (s) {
    clang_analyzer_dump_char(buffer[0]); // expected-warning {{conj_$}} Should not preserve the previous value, thus should not be 10.
  }
  // Hmm, what do we know of the buffer on failure? IDK.

  fclose(F1);
}
```

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


More information about the cfe-commits mailing list