From 0a19794cec0bab9e2b94e4a2161951098790c852 Mon Sep 17 00:00:00 2001 From: harry Date: Sun, 29 Jan 2023 12:32:47 -0500 Subject: [PATCH] Fixed a few warnings for -Wunused-result with fread usage. --- src/cart.cpp | 12 ++++++++++-- src/emufile.cpp | 6 +++++- src/file.cpp | 5 ++++- src/netplay.cpp | 5 ++++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/cart.cpp b/src/cart.cpp index 26f7627c..55741b7f 100644 --- a/src/cart.cpp +++ b/src/cart.cpp @@ -562,10 +562,18 @@ void FCEU_LoadGameSave(CartInfo *LocalHWInfo) { std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); sp = FCEUD_UTF8fopen(soot, "rb"); - if (sp != NULL) { + if (sp != NULL) + { for (int x = 0; x < 4; x++) + { if (LocalHWInfo->SaveGame[x]) - fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp); + { + if ( fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp) != static_cast(LocalHWInfo->SaveGameLen[x]) ) + { + FCEU_printf("Warning save game data read came up short!\n"); + } + } + } } } } diff --git a/src/emufile.cpp b/src/emufile.cpp index ee4d32fb..a4edb7e8 100644 --- a/src/emufile.cpp +++ b/src/emufile.cpp @@ -23,6 +23,7 @@ THE SOFTWARE. #include "emufile.h" #include "utils/xstring.h" +#include #include bool EMUFILE::readAllBytes(std::vector* dstbuf, const std::string& fname) @@ -84,7 +85,10 @@ void EMUFILE_FILE::truncate(size_t length) #ifdef _MSC_VER _chsize(_fileno(fp),length); #else - ftruncate(fileno(fp),length); + if ( ftruncate(fileno(fp),length) != 0 ) + { + printf("Warning: EMUFILE_FILE::truncate failed\n"); + } #endif // this is probably wrong if mode is "wb" fclose(fp); diff --git a/src/file.cpp b/src/file.cpp index 0a18b240..ef3e2c14 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -132,7 +132,10 @@ void ApplyIPS(FILE *ips, FCEUFILE* fp) memset(buf+fp->size,0,offset+size-fp->size); fp->size=offset+size; } - fread(buf+offset,1,size,ips); + if ( fread(buf+offset,1,size,ips) != static_cast(size) ) + { + FCEU_printf(" Warn IPS data read came up short!\n"); + } } count++; } diff --git a/src/netplay.cpp b/src/netplay.cpp index 4d2003ad..bbec7365 100644 --- a/src/netplay.cpp +++ b/src/netplay.cpp @@ -122,7 +122,10 @@ int FCEUNET_SendFile(uint8 cmd, char *fn) FCEUX_fstat(fileno(fp),&sb); len = sb.st_size; buf = (char*)FCEU_dmalloc(len); //mbg merge 7/17/06 added cast - fread(buf, 1, len, fp); + if ( fread(buf, 1, len, fp) != static_cast(len) ) + { + FCEU_printf("Warning: FCEUNET_SendFile failed to load complete file.\n"); + } fclose(fp); cbuf = (char*)FCEU_dmalloc(4 + len + len / 1000 + 12); //mbg merge 7/17/06 added cast