From: Rebecca Cran Date: Wed, 4 Apr 2018 23:18:42 +0000 (-0600) Subject: Fix return value checking of fread() in iolog.c X-Git-Tag: fio-3.6~17 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=2b8b8f0dccb4c7e97aee3b7d7e13d8528467d64e;hp=dfd3fe1adfe3b018c837f95ad4c4bb8e28d3d42c Fix return value checking of fread() in iolog.c According to http://pubs.opengroup.org/onlinepubs/7908799/xsh/fread.html fread() returns a size_t, not ssize_t, and returns a value of 0 on both eof and an error. Therefore, check both feof() and ferror() to determine whether the call succeeded. Signed-off-by: Jens Axboe --- diff --git a/iolog.c b/iolog.c index 2b5eaf0c..bfafc032 100644 --- a/iolog.c +++ b/iolog.c @@ -978,7 +978,7 @@ int iolog_file_inflate(const char *file) struct iolog_compress ic; z_stream stream; struct stat sb; - ssize_t ret; + size_t ret; size_t total; void *buf; FILE *f; @@ -1000,12 +1000,12 @@ int iolog_file_inflate(const char *file) ic.seq = 1; ret = fread(ic.buf, ic.len, 1, f); - if (ret < 0) { + if (ret == 0 && ferror(f)) { perror("fread"); fclose(f); free(buf); return 1; - } else if (ret != 1) { + } else if (ferror(f) || (!feof(f) && ret != 1)) { log_err("fio: short read on reading log\n"); fclose(f); free(buf);