chiark / gitweb /
Check fread return status x3
authorMatthew Vernon <matthew@debian.org>
Fri, 7 Nov 2025 11:52:59 +0000 (11:52 +0000)
committerMatthew Vernon <matthew@debian.org>
Fri, 7 Nov 2025 14:35:30 +0000 (14:35 +0000)
Again, spotted by newer build tools.

buildcmp.c

index 9d977883b48d3f7451c5b8e8b38d67fe76d30bed..aef3358e5504fd18bce4a05d98fc81c5d36a8ffb 100644 (file)
@@ -94,10 +94,16 @@ static void put_header(void)
     strncpy( fh.description, "Compressed Data File", TSL_DESCRSZ );
     
     /* Process the squish statistics */
-    fread( &d, sizeof(int), 1, sf );
+    if(fread( &d, sizeof(int), 1, sf ) < 1){
+      perror("Failed to read Window size from squish.stats");
+      exit(1);
+    }
     printf( "Window size (bytes): %d\n", d );
     univ_assign(fh.wsize, d);
-    fread( &d, sizeof(int), 1, sf );
+    if(fread( &d, sizeof(int), 1, sf ) < 1){
+      perror("Failed to read Number of windows from squish.stats");
+      exit(1);
+    }
     printf( "Number of windows: %d\n", d );
     count = d;
     univ_assign(fh.wnum, d);
@@ -110,7 +116,10 @@ static void put_header(void)
     winx = (Univ_Int *) w_table;
 
     for (i=0; i <= count; i++) {
-       fread( &d, sizeof(int), 1, sf );
+      if(fread( &d, sizeof(int), 1, sf ) < 1){
+       perror("Failed to read Window start point from squish.stats");
+       exit(1);
+      }        
        univ_assign(*winx++, j=d+headersize);
        printf( "Window[%d] starts at %d\n", i, j );
     }