]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
rustls: fix clang-tidy warning
authorViktor Szakats <commit@vsz.me>
Sun, 21 Sep 2025 19:55:30 +0000 (21:55 +0200)
committerViktor Szakats <commit@vsz.me>
Mon, 22 Sep 2025 08:11:31 +0000 (10:11 +0200)
Seen with v21.1.1, non-debug-enabled build:
```
lib/vtls/rustls.c:415:23: error: File position of the stream might be 'indeterminate'
after a failed operation. Can cause undefined behavior [clang-analyzer-unix.Stream,-warnings-as-errors]
  415 |     const size_t rr = fread(buf, 1, sizeof(buf), f);
      |                       ^
```
Ref: https://github.com/curl/curl/actions/runs/17898248031/job/50887746633?pr=18660#step:11:174

Cherry-picked from #18660
Closes #18670

lib/vtls/rustls.c

index 87c23544ef4c60ea6250c175d1c777d8705c726f..e081c4651ac8594a5cd8e6b509ba7cc79df64d06 100644 (file)
@@ -410,7 +410,7 @@ read_file_into(const char *filename,
     return 0;
   }
 
-  while(!feof(f)) {
+  for(;;) {
     uint8_t buf[256];
     const size_t rr = fread(buf, 1, sizeof(buf), f);
     if(rr == 0 ||
@@ -418,6 +418,8 @@ read_file_into(const char *filename,
       fclose(f);
       return 0;
     }
+    if(rr < sizeof(buf))
+      break;
   }
 
   return fclose(f) == 0;