[clang] [analyzer] Fix StreamChecker crash in fread modeling (PR #108393)

DonĂ¡t Nagy via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 12 07:02:37 PDT 2024


================
@@ -443,3 +443,33 @@ void test_unaligned_start_read(void) {
     fclose(fp);
   }
 }
+
+void no_crash_if_count_is_negative(long s, unsigned char *buffer) {
+  FILE *fp = fopen("path", "r");
+  if (fp) {
+    if (s * s == -1) {
----------------
NagyDonat wrote:

Nitpick: $s^2 = -1$ is mathematically impossible (even if we allow overflows: `0xffff...f` $= (4^{k})^2 - 1$  where $k$ is the number of `f` digits and two consecutive integers that are >1 cannot be both perfect squares). I know that the static analyzer doesn't know this and will happily assume that `s * s == -1` -- but it would be still nicer to use a different example.

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


More information about the cfe-commits mailing list