From 29769dd673fd4def2ea0bf133f9998522ea943c1 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Fri, 8 Oct 2021 19:06:41 +0200
Subject: [PATCH] - fixed engine code warnings pointed out by XCode 13.

---
 source/build/src/clip.cpp                    |  2 +-
 source/build/src/polymost.cpp                |  2 +-
 source/core/cheats.cpp                       | 25 ++++++++------------
 source/core/defparser.cpp                    |  4 ++--
 source/core/g_mapinfo.cpp                    |  2 +-
 source/core/gamecontrol.cpp                  |  2 +-
 source/core/gameinput.cpp                    |  2 +-
 source/core/gameinput.h                      |  2 +-
 source/core/palette.cpp                      |  2 +-
 source/core/rendering/render.h               |  4 ++--
 source/core/rendering/scene/hw_drawstructs.h |  2 ++
 11 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp
index 165f7122c..17a0282ea 100644
--- a/source/build/src/clip.cpp
+++ b/source/build/src/clip.cpp
@@ -1048,7 +1048,7 @@ void getzrange(const vec3_t *pos, int16_t sectnum,
                 if (da.x >= da.y)
                     continue;
                 //It actually got here, through all the continue's!!!
-                int32_t daz, daz2;
+                int32_t daz = 0, daz2 = 0;
                 closest = pos->vec2;
                 if (enginecompatibility_mode == ENGINECOMPATIBILITY_NONE)
                     getsectordist(closest, k, &closest);
diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp
index 89d248e11..027043273 100644
--- a/source/build/src/polymost.cpp
+++ b/source/build/src/polymost.cpp
@@ -1957,7 +1957,7 @@ void polymost_scansector(int32_t sectnum)
 
             int const nextsectnum = wal->nextsector; //Scan close sectors
 
-            if (nextsectnum >= 0 && !(wal->cstat&32) && sectorbordercnt < countof(sectorborder))
+            if (nextsectnum >= 0 && !(wal->cstat&32) && sectorbordercnt < (int)countof(sectorborder))
             if (gotsector[nextsectnum] == 0)
             {
                 double const d = fp1.X* fp2.Y - fp2.X * fp1.Y;
diff --git a/source/core/cheats.cpp b/source/core/cheats.cpp
index b3fe9fd4e..6a34f8b55 100644
--- a/source/core/cheats.cpp
+++ b/source/core/cheats.cpp
@@ -180,25 +180,20 @@ CCMD(give)
 		Printf("give <all|health|weapons|ammo|armor|keys|inventory>: gives requested item\n");
 		return;
 	}
-	size_t found = -1;
+
 	for (size_t i = 0; i < countof(type); i++)
 	{
 		if (!stricmp(argv[1], type[i]))
 		{
-			found = i;
-			break;
+			if (!CheckCheatmode(true, true))
+			{
+				Net_WriteByte(DEM_GIVE);
+				Net_WriteByte((uint8_t)i);
+			}
+			return;
 		}
 	}
-	if (found == -1)
-	{
-		Printf("Unable to give %s\n", argv[1]);
-		return;
-	}
-	if (!CheckCheatmode(true, true))
-	{
-		Net_WriteByte(DEM_GIVE);
-		Net_WriteByte((uint8_t)found);
-	}
+	Printf("Unable to give %s\n", argv[1]);
 }
 
 //---------------------------------------------------------------------------
@@ -522,7 +517,7 @@ CCMD(skill)
 			}
 			else if (currentSkill == -1)
 			{
-				Printf("Current skill is not set (%d)\n");
+				Printf("Current skill is not set\n");
 			}
 			else if (currentSkill == -2)
 			{
@@ -530,7 +525,7 @@ CCMD(skill)
 			}
 			else
 			{
-				Printf("Current skill is an unknown/unsupported value (%d)\n");
+				Printf("Current skill is an unknown/unsupported value (%d)\n", currentSkill);
 			}
 		}
 		else if (argsCount == 2)
diff --git a/source/core/defparser.cpp b/source/core/defparser.cpp
index 6fd75423b..f15603dfb 100644
--- a/source/core/defparser.cpp
+++ b/source/core/defparser.cpp
@@ -350,7 +350,7 @@ void parseCopyTile(FScanner& sc, FScriptPosition& pos)
 
 				if ((unsigned)temppal >= MAXREALPAL)
 				{
-					pos.Message(MSG_ERROR, "copytile: palette number %d out of range (max=%d)\n", MAXREALPAL - 1);
+					pos.Message(MSG_ERROR, "copytile: palette number %d out of range (max=%d)\n", temppal, MAXREALPAL - 1);
 					break;
 				}
 			}
@@ -1665,7 +1665,7 @@ void parseDefineModelFrame(FScanner& sc, FScriptPosition& pos)
 		int err = (md_defineframe(mdglobal.lastmodelid, framename, i, max(0, mdglobal.modelskin), 0.0f, 0));
 		if (err < 0) ok = false; 
 		if (err == -2) pos.Message(MSG_ERROR, "Invalid tile number %d", i);
-		else if (err == -3) pos.Message(MSG_ERROR, "Invalid frame name", framename.GetChars());
+		else if (err == -3) pos.Message(MSG_ERROR, "Invalid frame name '%s'", framename.GetChars());
 	}
 	mdglobal.seenframe = 1;
 }
diff --git a/source/core/g_mapinfo.cpp b/source/core/g_mapinfo.cpp
index 91ece0a53..f5a01f238 100644
--- a/source/core/g_mapinfo.cpp
+++ b/source/core/g_mapinfo.cpp
@@ -306,7 +306,7 @@ void FMapInfoParser::ParseCluster()
 
 bool FMapInfoParser::CheckLegacyMapDefinition(FString& mapname)
 {
-	if (Internal && (g_gameType & GAMEFLAG_BLOOD | GAMEFLAG_DUKECOMPAT | GAMEFLAG_SW) && sc.CheckString("{"))
+	if (Internal && (g_gameType & (GAMEFLAG_BLOOD | GAMEFLAG_DUKECOMPAT | GAMEFLAG_SW)) && sc.CheckString("{"))
 	{
 		sc.MustGetNumber();
 		int vol = sc.Number;
diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp
index 614159afa..757190555 100644
--- a/source/core/gamecontrol.cpp
+++ b/source/core/gamecontrol.cpp
@@ -699,7 +699,7 @@ static TArray<GrpEntry> SetupGame()
 			auto grplower = grp.FileName.MakeLower();
 			FixPathSeperator(grplower);
 			auto pos = grplower.LastIndexOf(gamegrplower);
-			if (pos >= 0 && pos == grplower.Len() - gamegrplower.Len())
+			if (pos >= 0 && pos == ptrdiff_t(grplower.Len() - gamegrplower.Len()))
 			{
 				groupno = g;
 				break;
diff --git a/source/core/gameinput.cpp b/source/core/gameinput.cpp
index ab48ef726..1cefe3b97 100644
--- a/source/core/gameinput.cpp
+++ b/source/core/gameinput.cpp
@@ -77,7 +77,7 @@ void updateTurnHeldAmt(double const scaleAdjust)
 	turnheldtime += scaleAdjust * (120. / GameTicRate);
 }
 
-bool const isTurboTurnTime()
+bool isTurboTurnTime()
 {
 	return turnheldtime >= 590. / GameTicRate;
 }
diff --git a/source/core/gameinput.h b/source/core/gameinput.h
index d84f10305..ccfe6d11e 100644
--- a/source/core/gameinput.h
+++ b/source/core/gameinput.h
@@ -314,6 +314,6 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, PlayerHorizon& w,
 
 
 void updateTurnHeldAmt(double const scaleAdjust);
-bool const isTurboTurnTime();
+bool isTurboTurnTime();
 void resetTurnHeldAmt();
 void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, double const scaleAdjust, int const drink_amt = 0, bool const allowstrafe = true, double const turnscale = 1);
diff --git a/source/core/palette.cpp b/source/core/palette.cpp
index b75354b86..cfb395ed0 100644
--- a/source/core/palette.cpp
+++ b/source/core/palette.cpp
@@ -121,7 +121,7 @@ void paletteLoadFromDisk(void)
     }
 
     // Read base shade table (lookuptables 0).
-    int length = numshades * 256;
+    unsigned length = numshades * 256;
     auto buffer = fil.Read(length);
     if (buffer.Size() != length) return;
     lookups.setTable(0, buffer.Data());
diff --git a/source/core/rendering/render.h b/source/core/rendering/render.h
index 256b65747..5fd8508c6 100644
--- a/source/core/rendering/render.h
+++ b/source/core/rendering/render.h
@@ -64,7 +64,7 @@ inline void mergePortals()
 								for (int n = 0; n < numsectors; n++)
 								{
 									//Printf("Merged %d and %d\n", i, j);
-									if (sector[n].portalnum == j) sector[n].portalnum = i;
+									if (sector[n].portalnum == (int)j) sector[n].portalnum = i;
 								}
 								didsomething = true;
 								break;
@@ -75,4 +75,4 @@ inline void mergePortals()
 			}
 		}
 	}
-}
\ No newline at end of file
+}
diff --git a/source/core/rendering/scene/hw_drawstructs.h b/source/core/rendering/scene/hw_drawstructs.h
index 234ab5e13..f6ff80e89 100644
--- a/source/core/rendering/scene/hw_drawstructs.h
+++ b/source/core/rendering/scene/hw_drawstructs.h
@@ -15,7 +15,9 @@
 #include "hw_renderstate.h"
 #include "hw_cvars.h"
 
+#ifdef _MSC_VER
 #pragma warning(disable:4244) // this gets a bit annoying in the renderer...
+#endif
 
 struct HWHorizonInfo;
 struct HWSkyInfo;