]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix harness test
authorYann Collet <cyan@fb.com>
Thu, 17 Oct 2019 21:29:48 +0000 (14:29 -0700)
committerYann Collet <cyan@fb.com>
Thu, 17 Oct 2019 21:29:48 +0000 (14:29 -0700)
doc/educational_decoder/harness.c

index de2e1235814052bdbc8831725e99dd0fb0859c23..a704f6bdb29fc125f0c81e59f62b2b08d937037f 100644 (file)
@@ -39,19 +39,15 @@ static size_t read_file(const char *path, u8 **ptr)
         exit(1);
     }
 
-    size_t pos = 0;
-    while (!feof(f)) {
-        size_t const read = fread(*ptr + pos, 1, size, f);
-        if (ferror(f)) {
-            fprintf(stderr, "error while reading file %s \n", path);
-            exit(1);
-        }
-        pos += read;
+    size_t const read = fread(*ptr, 1, size, f);
+    if (read != size) {  /* must read everything in one pass */
+        fprintf(stderr, "error while reading file %s \n", path);
+        exit(1);
     }
 
     fclose(f);
 
-    return pos;
+    return read;
 }
 
 static void write_file(const char *path, const u8 *ptr, size_t size)