From 921abc404d5d85a9443f63d0f01cefcf102e8b72 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Sat, 11 Mar 2017 19:02:00 +0100
Subject: [PATCH] - fixed GCC warnings and errors

(Is there anyway to tone down GCC's warning level? It outputs too many false positives for potentially uninitialized variables in which the genuine errors get drowned.)
---
 src/am_map.cpp                                |  1 +
 src/b_move.cpp                                |  1 +
 src/b_think.cpp                               |  1 +
 src/dthinker.cpp                              |  2 +-
 src/g_level.cpp                               |  1 +
 src/g_statusbar/sbar_mugshot.cpp              |  1 +
 src/gl/renderer/gl_postprocess.cpp            |  2 +-
 src/gl/scene/gl_portal.cpp                    |  2 +-
 src/p_conversation.cpp                        |  1 +
 src/p_maputl.cpp                              |  1 +
 src/p_pspr.cpp                                |  7 +++--
 src/p_things.cpp                              |  1 +
 src/p_udmf.cpp                                |  2 +-
 src/polyrenderer/scene/poly_wallsprite.cpp    |  2 +-
 src/r_utility.cpp                             |  2 +-
 .../music_audiotoolbox_mididevice.cpp         |  2 +-
 src/sound/oalsound.cpp                        |  2 +-
 src/swrenderer/scene/r_portal.cpp             |  2 +-
 src/swrenderer/things/r_decal.cpp             |  4 +++
 src/swrenderer/things/r_visiblesprite.cpp     |  5 ++++
 src/swrenderer/viewport/r_walldrawer.h        | 30 +++++++++----------
 21 files changed, 45 insertions(+), 27 deletions(-)

diff --git a/src/am_map.cpp b/src/am_map.cpp
index 480ef3e09f..ba7c301d8d 100644
--- a/src/am_map.cpp
+++ b/src/am_map.cpp
@@ -70,6 +70,7 @@
 #include "a_keys.h"
 #include "r_data/colormaps.h"
 #include "g_levellocals.h"
+#include "actorinlines.h"
 
 
 //=============================================================================
diff --git a/src/b_move.cpp b/src/b_move.cpp
index 0354be8bff..9361d55615 100644
--- a/src/b_move.cpp
+++ b/src/b_move.cpp
@@ -21,6 +21,7 @@
 #include "d_player.h"
 #include "p_spec.h"
 #include "p_checkposition.h"
+#include "actorinlines.h"
 #include "math/cmath.h"
 
 static FRandom pr_botopendoor ("BotOpenDoor");
diff --git a/src/b_think.cpp b/src/b_think.cpp
index f286dd30f5..25932f390e 100644
--- a/src/b_think.cpp
+++ b/src/b_think.cpp
@@ -21,6 +21,7 @@
 #include "d_event.h"
 #include "d_player.h"
 #include "vectors.h"
+#include "actorinlines.h"
 
 static FRandom pr_botmove ("BotMove");
 
diff --git a/src/dthinker.cpp b/src/dthinker.cpp
index 4b690efbc8..cbac457c65 100644
--- a/src/dthinker.cpp
+++ b/src/dthinker.cpp
@@ -183,7 +183,7 @@ void DThinker::SerializeThinkers(FSerializer &arc, bool hubLoad)
 					int size = arc.ArraySize();
 					for (int j = 0; j < size; j++)
 					{
-						DThinker *thinker;
+						DThinker *thinker = nullptr;
 						arc(nullptr, thinker);
 						if (thinker != nullptr)
 						{
diff --git a/src/g_level.cpp b/src/g_level.cpp
index 734f03bb65..f63ef3af1e 100644
--- a/src/g_level.cpp
+++ b/src/g_level.cpp
@@ -91,6 +91,7 @@
 
 #include "g_hub.h"
 #include "g_levellocals.h"
+#include "actorinlines.h"
 
 #include <string.h>
 
diff --git a/src/g_statusbar/sbar_mugshot.cpp b/src/g_statusbar/sbar_mugshot.cpp
index 18e0fec42a..650a37063c 100644
--- a/src/g_statusbar/sbar_mugshot.cpp
+++ b/src/g_statusbar/sbar_mugshot.cpp
@@ -41,6 +41,7 @@
 #include "sbarinfo.h"
 #include "templates.h"
 #include "r_utility.h"
+#include "actorinlines.h"
 
 #define ST_RAMPAGEDELAY 		(2*TICRATE)
 #define ST_MUCHPAIN 			20
diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp
index 00478e3406..4688e0393e 100644
--- a/src/gl/renderer/gl_postprocess.cpp
+++ b/src/gl/renderer/gl_postprocess.cpp
@@ -840,7 +840,7 @@ int FGLRenderer::PTM_BestColor (const uint32_t *pal_in, int r, int g, int b, int
 	static float trackpowtable = 0.;
 
 	double fbestdist, fdist;
-	int bestcolor;
+	int bestcolor = 0;
 
 	if (firstTime || trackpowtable != gl_paltonemap_powtable)
 	{
diff --git a/src/gl/scene/gl_portal.cpp b/src/gl/scene/gl_portal.cpp
index ca5b5ae50f..4a16b03ebd 100644
--- a/src/gl/scene/gl_portal.cpp
+++ b/src/gl/scene/gl_portal.cpp
@@ -847,7 +847,7 @@ void GLLinePortal::PushState()
 void GLLinePortal::PopState()
 {
 	FStateVec4 &v = gl_RenderState.GetClipLine();
-	float e;
+	float e = 0;
 	planestack.Pop(e);
 	planestack.Pop(v.vec[3]);
 	planestack.Pop(v.vec[2]);
diff --git a/src/p_conversation.cpp b/src/p_conversation.cpp
index 46475c04dd..d01fb51934 100644
--- a/src/p_conversation.cpp
+++ b/src/p_conversation.cpp
@@ -62,6 +62,7 @@
 #include "menu/menu.h"
 #include "g_levellocals.h"
 #include "virtual.h"
+#include "actorinlines.h"
 
 // The conversations as they exist inside a SCRIPTxx lump.
 struct Response
diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp
index 603a0897f5..7ec64e8dbd 100644
--- a/src/p_maputl.cpp
+++ b/src/p_maputl.cpp
@@ -40,6 +40,7 @@
 #include "p_blockmap.h"
 #include "r_utility.h"
 #include "actor.h"
+#include "actorinlines.h"
 
 // State.
 #include "r_state.h"
diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp
index 1f036d1ff1..11bfc4b026 100644
--- a/src/p_pspr.cpp
+++ b/src/p_pspr.cpp
@@ -143,10 +143,11 @@ DPSprite::DPSprite(player_t *owner, AActor *caller, int id)
   Owner(owner),
   Sprite(0),
   ID(id),
-  processPending(true),
-  alpha(1),
-  RenderStyle(STYLE_Normal)
+  processPending(true)
 {
+	alpha = 1;
+	RenderStyle = STYLE_Normal;
+
 	DPSprite *prev = nullptr;
 	DPSprite *next = Owner->psprites;
 	while (next != nullptr && next->ID < ID)
diff --git a/src/p_things.cpp b/src/p_things.cpp
index d4298f934b..da6f56cac4 100644
--- a/src/p_things.cpp
+++ b/src/p_things.cpp
@@ -52,6 +52,7 @@
 #include "math/cmath.h"
 #include "actorptrselect.h"
 #include "g_levellocals.h"
+#include "actorinlines.h"
 
 // Set of spawnable things for the Thing_Spawn and Thing_Projectile specials.
 FClassMap SpawnableThings;
diff --git a/src/p_udmf.cpp b/src/p_udmf.cpp
index edb3b5364b..5aa2945acc 100644
--- a/src/p_udmf.cpp
+++ b/src/p_udmf.cpp
@@ -1813,7 +1813,7 @@ public:
 		vd->zCeiling = vd->zFloor = vd->flags = 0;
 
 		sc.MustGetToken('{');
-		double x, y;
+		double x = 0, y = 0;
 		while (!sc.CheckToken('}'))
 		{
 			FName key = ParseKey();
diff --git a/src/polyrenderer/scene/poly_wallsprite.cpp b/src/polyrenderer/scene/poly_wallsprite.cpp
index a563f026df..cee3641a16 100644
--- a/src/polyrenderer/scene/poly_wallsprite.cpp
+++ b/src/polyrenderer/scene/poly_wallsprite.cpp
@@ -59,7 +59,7 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const Vec4f &cli
 	left.X = pos.X - x1 * angcos;
 	left.Y = pos.Y - x1 * angsin;
 	right.X = left.X + x2 * angcos;
-	right.Y = right.Y + x2 * angsin;
+	right.Y = left.Y + x2 * angsin;
 
 	//int scaled_to = tex->GetScaledTopOffset();
 	//int scaled_bo = scaled_to - tex->GetScaledHeight();
diff --git a/src/r_utility.cpp b/src/r_utility.cpp
index 02c22cba9a..9ea78cf3b0 100644
--- a/src/r_utility.cpp
+++ b/src/r_utility.cpp
@@ -1064,7 +1064,7 @@ void FCanvasTextureInfo::Serialize(FSerializer &arc)
 	{
 		if (arc.BeginArray("canvastextures"))
 		{
-			AActor *viewpoint;
+			AActor *viewpoint = nullptr;
 			int fov;
 			FTextureID picnum;
 			while (arc.BeginObject(nullptr))
diff --git a/src/sound/mididevices/music_audiotoolbox_mididevice.cpp b/src/sound/mididevices/music_audiotoolbox_mididevice.cpp
index 6d904a4352..08aa252050 100644
--- a/src/sound/mididevices/music_audiotoolbox_mididevice.cpp
+++ b/src/sound/mididevices/music_audiotoolbox_mididevice.cpp
@@ -325,7 +325,7 @@ void AudioToolboxMIDIDevice::TimerCallback(CFRunLoopTimerRef timer, void* info)
 
 #undef AT_MIDI_CHECK_ERROR
 
-MIDIDevice *CreateAudioToolboxMIDTDevice()
+MIDIDevice *CreateAudioToolboxMIDIDevice()
 {
 	return new AudioToolboxMIDIDevice();
 }
diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp
index ff82f288b4..90639624a3 100644
--- a/src/sound/oalsound.cpp
+++ b/src/sound/oalsound.cpp
@@ -2057,7 +2057,7 @@ MIDIDevice* OpenALSoundRenderer::CreateMIDIDevice() const
 	extern unsigned mididevice;
 	return CreateWinMIDIDevice(mididevice);
 #elif defined __APPLE__
-	return CreateAudioToolboxMIDIDevice;
+	return CreateAudioToolboxMIDIDevice();
 #else
 	return new OPLMIDIDevice(nullptr);
 #endif
diff --git a/src/swrenderer/scene/r_portal.cpp b/src/swrenderer/scene/r_portal.cpp
index c725af6159..8c2768c92a 100644
--- a/src/swrenderer/scene/r_portal.cpp
+++ b/src/swrenderer/scene/r_portal.cpp
@@ -231,7 +231,7 @@ namespace swrenderer
 			
 			Thread->TranslucentPass->Render();
 
-			VisiblePlane *pl;
+			VisiblePlane *pl = nullptr;	// quiet, GCC!
 			visplaneStack.Pop(pl);
 			if (pl->Alpha > 0 && pl->picnum != skyflatnum)
 			{
diff --git a/src/swrenderer/things/r_decal.cpp b/src/swrenderer/things/r_decal.cpp
index 498d95e0f6..c33769691d 100644
--- a/src/swrenderer/things/r_decal.cpp
+++ b/src/swrenderer/things/r_decal.cpp
@@ -166,6 +166,10 @@ namespace swrenderer
 		// Get the top and bottom clipping arrays
 		switch (decal->RenderFlags & RF_CLIPMASK)
 		{
+		default:
+			// keep GCC quiet.
+			return;
+
 		case RF_CLIPFULL:
 			if (curline->backsector == NULL)
 			{
diff --git a/src/swrenderer/things/r_visiblesprite.cpp b/src/swrenderer/things/r_visiblesprite.cpp
index b2e3da8005..f636afa282 100644
--- a/src/swrenderer/things/r_visiblesprite.cpp
+++ b/src/swrenderer/things/r_visiblesprite.cpp
@@ -358,6 +358,11 @@ namespace swrenderer
 							neardepth = ds->sz2, fardepth = ds->sz1;
 						}
 					}
+					else
+					{
+						// GCC complained about this case, is there something missing here?
+						fardepth = neardepth = 0;
+					}
 
 					// Check if sprite is in front of draw seg:
 					if ((!spr->IsWallSprite() && neardepth > spr->depth) || ((spr->IsWallSprite() || fardepth > spr->depth) &&
diff --git a/src/swrenderer/viewport/r_walldrawer.h b/src/swrenderer/viewport/r_walldrawer.h
index e6d5309328..b7afddc21c 100644
--- a/src/swrenderer/viewport/r_walldrawer.h
+++ b/src/swrenderer/viewport/r_walldrawer.h
@@ -50,29 +50,29 @@ namespace swrenderer
 
 		int TextureFracBits() const { return dc_wall_fracbits; }
 
-		FVector3 dc_normal;
-		FVector3 dc_viewpos;
-		FVector3 dc_viewpos_step;
+		FVector3 dc_normal = { 0,0,0 };
+		FVector3 dc_viewpos = { 0,0,0 };
+		FVector3 dc_viewpos_step = { 0,0,0 };
 		DrawerLight *dc_lights = nullptr;
 		int dc_num_lights = 0;
 
 	private:
 		uint8_t *dc_dest = nullptr;
 		int dc_dest_y = 0;
-		int dc_count;
+		int dc_count = 0;
 		
-		fixed_t dc_iscale;
-		fixed_t dc_texturefrac;
-		uint32_t dc_texturefracx;
-		uint32_t dc_textureheight;
-		const uint8_t *dc_source;
-		const uint8_t *dc_source2;
-		int dc_wall_fracbits;
+		fixed_t dc_iscale = 0;
+		fixed_t dc_texturefrac = 0;
+		uint32_t dc_texturefracx = 0;
+		uint32_t dc_textureheight = 0;
+		const uint8_t *dc_source = nullptr;
+		const uint8_t *dc_source2 = nullptr;
+		int dc_wall_fracbits = 0;
 		
-		uint32_t *dc_srcblend;
-		uint32_t *dc_destblend;
-		fixed_t dc_srcalpha;
-		fixed_t dc_destalpha;
+		uint32_t *dc_srcblend = nullptr;
+		uint32_t *dc_destblend = nullptr;
+		fixed_t dc_srcalpha = 0;
+		fixed_t dc_destalpha = 0;
 
 		typedef void(SWPixelFormatDrawers::*WallDrawerFunc)(const WallDrawerArgs &args);
 		WallDrawerFunc wallfunc = nullptr;