[clang] [clang][analyzer] Fix argument invalidations in StreamChecker. (PR #79470)

Alejandro Álvarez Ayllón via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 21 06:24:19 PST 2024


================
@@ -763,6 +779,11 @@ void StreamChecker::evalFreadFwrite(const FnDescription *Desc,
     return;
   }
 
+  // At read, invalidate the buffer in any case of error or success,
+  // except if EOF was already present.
+  if (IsFread && (OldSS->ErrorState != ErrorFEof))
+    State = escapeArgs(State, C, Call, {0});
----------------
alejandro-alvarez-sonarsource wrote:

>From what I can tell, the lambda `UpdateBufferRegionForFread` is already used to take care of this in a more fine-grained manner. For instance:

```cpp
int buffer[10];
buffer[5] = 42;
if (1 == fread(buffer, sizeof(int), 5, fd)) {
    assert(buffer[5] == 42);
}
```

Before this change, the assertion would pass, since lambda took `nmemb` into account. With this change, the whole buffer is invalidated.

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


More information about the cfe-commits mailing list