From 928963656d68dbface669773eecfb6b22ba15da5 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 1 May 2010 19:22:52 +0000 Subject: Fix compiler warnings with savegame and response file code. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1926 --- src/g_game.c | 4 ++++ src/m_argv.c | 9 +++++++-- src/p_saveg.c | 22 ++++++++++++++++++++-- src/p_saveg.h | 1 + 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 542c1a7d..b0532f42 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1490,6 +1490,8 @@ void G_DoLoadGame (void) return; } + savegame_error = false; + if (!P_ReadSaveGameHeader()) { fclose(save_stream); @@ -1557,6 +1559,8 @@ void G_DoSaveGame (void) return; } + savegame_error = false; + P_WriteSaveGameHeader(savedescription); P_ArchivePlayers (); diff --git a/src/m_argv.c b/src/m_argv.c index 78404d35..7fc15863 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -89,12 +89,17 @@ static void LoadResponseFile(int argv_index) size = M_FileLength(handle); // Read in the entire file - // Allocate one byte extra - this is incase there is an argument + // Allocate one byte extra - this is in case there is an argument // at the end of the response file, in which case a '\0' will be // needed. file = malloc(size + 1); - fread(file, size, 1, handle); + + if (fread(file, 1, size, handle) < size) + { + I_Error("Failed to read entire response file"); + } + fclose(handle); // Create new arguments list array diff --git a/src/p_saveg.c b/src/p_saveg.c index e557e494..d2a4393d 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -44,6 +44,7 @@ FILE *save_stream; int savegamelength; +boolean savegame_error; // Get the filename of a temporary file to write the savegame to. After // the file has been successfully saved, it will be renamed to the @@ -88,14 +89,31 @@ static byte saveg_read8(void) { byte result; - fread(&result, 1, 1, save_stream); + if (fread(&result, 1, 1, save_stream) < 1) + { + if (!savegame_error) + { + fprintf(stderr, "saveg_read8: Unexpected end of file while " + "reading save game\n"); + + savegame_error = true; + } + } return result; } static void saveg_write8(byte value) { - fwrite(&value, 1, 1, save_stream); + if (fwrite(&value, 1, 1, save_stream) < 1) + { + if (!savegame_error) + { + fprintf(stderr, "saveg_write8: Error while writing save game\n"); + + savegame_error = true; + } + } } static short saveg_read16(void) diff --git a/src/p_saveg.h b/src/p_saveg.h index 3a96cc3e..5488289c 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -64,6 +64,7 @@ void P_ArchiveSpecials (void); void P_UnArchiveSpecials (void); extern FILE *save_stream; +extern boolean savegame_error; #endif -- cgit v1.2.3