From 8eb499d3541579ab0a9cad8fc454259b3688999b Mon Sep 17 00:00:00 2001 From: Peter Lesslie Date: Tue, 26 Nov 2019 19:36:33 -0600 Subject: [PATCH] Check for fread failure On failure fread may return either a short read or 0. Need to use ferror to detect error versus eof. --- programs/fileio.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index a45dedc46..8fc25d357 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1769,7 +1769,7 @@ static int FIO_passThrough(const FIO_prefs_t* const prefs, size_t alreadyLoaded) { size_t const blockSize = MIN(64 KB, bufferSize); - size_t readFromInput = 1; + size_t readFromInput; unsigned storedSkips = 0; /* assumption : ress->srcBufferLoaded bytes already loaded and stored within buffer */ @@ -1779,10 +1779,15 @@ static int FIO_passThrough(const FIO_prefs_t* const prefs, return 1; } } - while (readFromInput) { + do { readFromInput = fread(buffer, 1, blockSize, finput); storedSkips = FIO_fwriteSparse(prefs, foutput, buffer, readFromInput, storedSkips); + } while (readFromInput == blockSize); + if (ferror(finput)) { + DISPLAYLEVEL(1, "Pass-through read error : %s\n", strerror(errno)); + return 1; } + assert(feof(finput)); FIO_fwriteSparseEnd(prefs, foutput, storedSkips); return 0;