shithub: choc

Download patch

ref: 9b92453235f5de11b1ed3f8af979c0445716ccab
parent: 96e0123cd27a88a69c4582eb1e7c8dda66f3114d
parent: 5bd5e1629b58120d60810bd870faf0107a310834
author: Mike Swanson <mikeonthecomputer@gmail.com>
date: Sat Jan 27 10:26:25 EST 2018

Merge pull request #974 from turol/warnings

Treat warnings as errors in travis build

--- a/.travis.sh
+++ b/.travis.sh
@@ -3,7 +3,7 @@
 if [ "$ANALYZE" = "true" ] ; then
 	cppcheck --error-exitcode=1 -j2 -UTESTING -Iopl -Isrc -Isrc/setup opl pcsound src textscreen > /dev/null
 else
-	./autogen.sh
+	./autogen.sh --enable-werror
 	make
 	make install DESTDIR=/tmp/whatever
 	make dist
--- a/configure.ac
+++ b/configure.ac
@@ -105,6 +105,12 @@
 AC_CHECK_TOOL(OBJDUMP, objdump, )
 AC_CHECK_TOOL(STRIP, strip, )
 
+AC_ARG_ENABLE([werror], AS_HELP_STRING([--enable-werror], [Treat warnings as errors]))
+
+AS_IF([test "x$enable_werror" = "xyes"], [
+        CFLAGS="$CFLAGS -Werror"
+])
+
 AM_CONDITIONAL(HAVE_WINDRES, test "$WINDRES" != "")
 AM_CONDITIONAL(HAVE_PYTHON, $HAVE_PYTHON)
 
--- a/src/doom/m_menu.c
+++ b/src/doom/m_menu.c
@@ -510,6 +510,7 @@
 
     for (i = 0;i < load_end;i++)
     {
+        int retval;
         M_StringCopy(name, P_SaveGameFile(i), sizeof(name));
 
 	handle = fopen(name, "rb");
@@ -519,9 +520,9 @@
             LoadMenu[i].status = 0;
             continue;
         }
-	fread(&savegamestrings[i], 1, SAVESTRINGSIZE, handle);
+        retval = fread(&savegamestrings[i], 1, SAVESTRINGSIZE, handle);
 	fclose(handle);
-	LoadMenu[i].status = 1;
+        LoadMenu[i].status = retval == SAVESTRINGSIZE;
     }
 }
 
--- a/src/heretic/mn_menu.c
+++ b/src/heretic/mn_menu.c
@@ -642,6 +642,7 @@
 
     for (i = 0; i < 6; i++)
     {
+        int retval;
         filename = SV_Filename(i);
         fp = fopen(filename, "rb+");
 	free(filename);
@@ -652,9 +653,9 @@
             SlotStatus[i] = 0;
             continue;
         }
-        fread(&SlotText[i], SLOTTEXTLEN, 1, fp);
+        retval = fread(&SlotText[i], 1, SLOTTEXTLEN, fp);
         fclose(fp);
-        SlotStatus[i] = 1;
+        SlotStatus[i] = retval == SLOTTEXTLEN;
     }
     slottextloaded = true;
 }
--- a/src/heretic/p_saveg.c
+++ b/src/heretic/p_saveg.c
@@ -131,7 +131,12 @@
 
 void SV_Read(void *buffer, int size)
 {
-    fread(buffer, size, 1, SaveGameFP);
+    int retval = fread(buffer, 1, size, SaveGameFP);
+    if (retval != size)
+    {
+        I_Error("Incomplete read in SV_Read: Expected %d, got %d bytes",
+            size, retval);
+    }
 }
 
 byte SV_ReadByte(void)
--- a/src/hexen/sv_save.c
+++ b/src/hexen/sv_save.c
@@ -3372,7 +3372,12 @@
 
 static void SV_Read(void *buffer, int size)
 {
-    fread(buffer, size, 1, SavingFP);
+    int retval = fread(buffer, 1, size, SavingFP);
+    if (retval != size)
+    {
+        I_Error("Incomplete read in SV_Read: Expected %d, got %d bytes",
+            size, retval);
+    }
 }
 
 static byte SV_ReadByte(void)
--- a/src/i_sdlmusic.c
+++ b/src/i_sdlmusic.c
@@ -649,8 +649,15 @@
 
     while (!feof(fs))
     {
+        char *retval;
         M_StringCopy(line, "", sizeof(line));
-        fgets(line, sizeof(line), fs);
+        retval = fgets(line, sizeof(line), fs);
+
+        if (retval == NULL)
+        {
+            fprintf(stderr, "%s:%i: Unexpected end of file\n", filename, linenum);
+            break;
+        }
 
         error = ParseSubstituteLine(filename, line);
 
--- a/src/strife/m_menu.c
+++ b/src/strife/m_menu.c
@@ -547,6 +547,7 @@
 
     for(i = 0; i < load_end; i++)
     {
+        int retval;
         if(fname)
             Z_Free(fname);
         fname = M_SafeFilePath(savegamedir, M_MakeStrifeSaveDir(i, "\\name"));
@@ -559,9 +560,9 @@
             LoadMenu[i].status = 0;
             continue;
         }
-        fread(savegamestrings[i], 1, SAVESTRINGSIZE, handle);
+        retval = fread(savegamestrings[i], 1, SAVESTRINGSIZE, handle);
         fclose(handle);
-        LoadMenu[i].status = 1;
+        LoadMenu[i].status = retval == SAVESTRINGSIZE;
     }
 
     if(fname)
--- a/src/strife/m_saves.c
+++ b/src/strife/m_saves.c
@@ -293,8 +293,12 @@
 
     if((f = fopen(srcpath, "rb")))
     {
-        fread(mission_objective, 1, OBJECTIVE_LEN, f);
+        int retval = fread(mission_objective, 1, OBJECTIVE_LEN, f);
         fclose(f);
+        if (retval != OBJECTIVE_LEN)
+        {
+            I_Error("M_ReadMisObj: error while reading mission objective");
+        }
     }
 
     Z_Free(srcpath);
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -526,6 +526,7 @@
 {
     char *cmd;
     size_t cmd_len;
+    int retval;
 
     cmd_len = strlen(url) + 30;
     cmd = malloc(cmd_len);
@@ -546,8 +547,13 @@
     TXT_snprintf(cmd, cmd_len, "xdg-open \"%s\"", url);
 #endif
 
-    system(cmd);
+    retval = system(cmd);
     free(cmd);
+    if (retval != 0)
+    {
+        fprintf(stderr, "TXT_OpenURL: error executing '%s'; return code %d\n",
+            cmd, retval);
+    }
 }
 
 #endif /* #ifndef _WIN32 */