shithub: choc

Download patch

ref: 928963656d68dbface669773eecfb6b22ba15da5
parent: f151517ba6b7e7caf7b49e8ceafbf0969959e068
author: Simon Howard <fraggle@gmail.com>
date: Sat May 1 15:22:52 EDT 2010

Fix compiler warnings with savegame and response file code.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 1926

--- a/src/g_game.c
+++ b/src/g_game.c
@@ -1490,6 +1490,8 @@
         return;
     }
 
+    savegame_error = false;
+
     if (!P_ReadSaveGameHeader())
     {
         fclose(save_stream);
@@ -1556,6 +1558,8 @@
     {
         return;
     }
+
+    savegame_error = false;
 
     P_WriteSaveGameHeader(savedescription);
  
--- a/src/m_argv.c
+++ b/src/m_argv.c
@@ -89,12 +89,17 @@
     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
--- 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 @@
 {
     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)
--- a/src/p_saveg.h
+++ b/src/p_saveg.h
@@ -64,6 +64,7 @@
 void P_UnArchiveSpecials (void);
 
 extern FILE *save_stream;
+extern boolean savegame_error;
 
 
 #endif