From c0048cb4cdba1611d838342ce594513dfbeff647 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Fri, 1 May 2015 22:37:33 -0700 Subject: [PATCH] check return values of fread MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: utilities/hogcreate.c:66:11: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result] utilities/hogextract.c:47:7: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result] utilities/hogextract.c:51:8: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result] utilities/hogextract.c:52:8: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result] utilities/hogextract.c:67:11: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result] utilities/mvlcreate.c:87:9: error: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Werror=unused-result] --- utilities/hogcreate.c | 6 +++++- utilities/hogextract.c | 20 ++++++++++++++++---- utilities/mvlcreate.c | 6 +++++- utilities/mvlextract.c | 22 +++++++++++++++++----- 4 files changed, 43 insertions(+), 11 deletions(-) diff --git a/utilities/hogcreate.c b/utilities/hogcreate.c index 03096cb6..98ddb239 100644 --- a/utilities/hogcreate.c +++ b/utilities/hogcreate.c @@ -63,7 +63,11 @@ main(int argc, char *argv[]) tmp = SWAPINT(tmp); #endif fwrite(&tmp, 4, 1, hogfile); - fread(buf, statbuf.st_size, 1, readfile); + if ( fread(buf, statbuf.st_size, 1, readfile) != 1 ) { + printf("Error reading %s\n", filename); + fclose(readfile); + exit(EXIT_FAILURE); + } fwrite(buf, statbuf.st_size, 1, hogfile); } fclose(readfile); diff --git a/utilities/hogextract.c b/utilities/hogextract.c index d7d85ac1..d5963dcd 100644 --- a/utilities/hogextract.c +++ b/utilities/hogextract.c @@ -44,12 +44,20 @@ main(int argc, char *argv[]) stat(argv[1], &statbuf); printf("%i\n", (int)statbuf.st_size); buf = (char *)malloc(3); - fread(buf, 3, 1, hogfile); + if ( fread(buf, 3, 1, hogfile) != 1 ) { + printf("Error reading %s\n", argv[1]); + fclose(hogfile); + exit(EXIT_FAILURE); + } printf("Extracting from: %s\n", argv[1]); free(buf); while(ftell(hogfile) MAX_FILES) { // must be a bigendian mvl fprintf(stderr, "warning: nfiles>%d, trying reverse byte order...", @@ -56,8 +60,12 @@ main(int argc, char *argv[]) printf("Extracting from: %s\n", argv[1]); free(buf); for (i = 0; i < nfiles; i++) { - fread(filename[i], 13, 1, mvlfile); - fread(&len[i], 4, 1, mvlfile); + if ( fread(filename[i], 13, 1, mvlfile) != 1 || + fread(&len[i], 4, 1, mvlfile) != 1 ) { + printf("Error reading %s\n", argv[1]); + fclose(mvlfile); + exit(EXIT_FAILURE); + } if (bigendian) len[i] = SWAPINT(len[i]); if (argc == 2 || !strcmp(argv[2], filename[i])) @@ -77,7 +85,11 @@ main(int argc, char *argv[]) if (buf == NULL) { printf("Unable to allocate memory\n"); } else { - fread(buf, len[i], 1, mvlfile); + if ( fread(buf, len[i], 1, mvlfile) != 1 ) { + printf("Error reading %s\n", argv[1]); + fclose(mvlfile); + exit(EXIT_FAILURE); + } writefile = fopen(filename[i], "wb"); fwrite(buf, len[i], 1, writefile); fclose(writefile); -- 2.39.2