]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm/hs: suppress scan-build warning
authorVictor Julien <vjulien@oisf.net>
Wed, 7 May 2025 18:51:48 +0000 (20:51 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 9 May 2025 05:50:41 +0000 (07:50 +0200)
 util-mpm-hs-cache.c:83:25: warning: Value of 'errno' was not checked and may be overwritten by function 'fread' [unix.Errno]
   83 |     size_t bytes_read = fread(buffer, 1, file_sz, file);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

"After calling 'rewind' reading 'errno' is required to find out if the call has failed".

src/util-mpm-hs-cache.c

index 5b91c0197b814554b070334cf892e03adbad5ad9..75cdee21717572bdedf0eafcced7c41fb38d621c 100644 (file)
@@ -79,7 +79,14 @@ static char *HSReadStream(const char *file_path, size_t *buffer_sz)
     }
 
     // Rewind file pointer and read the file into the buffer
+    errno = 0;
     rewind(file);
+    if (errno != 0) {
+        SCLogDebug("Failed to rewind file %s: %s", file_path, strerror(errno));
+        SCFree(buffer);
+        fclose(file);
+        return NULL;
+    }
     size_t bytes_read = fread(buffer, 1, file_sz, file);
     if (bytes_read != (size_t)file_sz) {
         SCLogDebug("Failed to read the entire file %s: %s", file_path, strerror(errno));