From b229d0750056d249ed88faa392ce3999c67cd9b4 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@zdoom.fake>
Date: Sun, 23 Apr 2006 09:02:19 +0000
Subject: [PATCH] SVN r65 (trunk)

---
 docs/rh-log.txt         | 7 +++++++
 src/g_shared/a_keys.cpp | 4 ++--
 src/p_switch.cpp        | 4 ++--
 src/r_data.cpp          | 6 ++++--
 src/sdl/sdlvideo.cpp    | 1 +
 src/v_font.cpp          | 2 +-
 6 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/docs/rh-log.txt b/docs/rh-log.txt
index 401f9899d..0a17fab9e 100644
--- a/docs/rh-log.txt
+++ b/docs/rh-log.txt
@@ -1,3 +1,10 @@
+April 22, 2006 (Changes by Graf Zahl)
+- Fixed: V_InitCustomFonts initialized lastlump to -1 instead of 0.
+- Fixed: CreateTexture never checked whether it could read from the
+  texture lump. Since the minimum valid length is 13 bytes for a
+  1x1 pixel patch everything below that will now return with an error.
+- Fixed a few occurences of mismatched free's for new'd memory.
+
 April 21, 2006 (Changes by Graf Zahl)
 - Fixed: To prevent the pointer cleanup code from crashing numsectors has
   to be set to 0 when the sectors array is deleted.
diff --git a/src/g_shared/a_keys.cpp b/src/g_shared/a_keys.cpp
index c14b7493f..828b27095 100644
--- a/src/g_shared/a_keys.cpp
+++ b/src/g_shared/a_keys.cpp
@@ -294,8 +294,8 @@ static void ParseLock()
 		}
 	}
 	// copy the messages if the other one does not exist
-	if (!lock->remotemsg && lock->message) lock->remotemsg=strdup(lock->message);
-	if (!lock->message && lock->remotemsg) lock->message=strdup(lock->remotemsg);
+	if (!lock->remotemsg && lock->message) lock->remotemsg = copystring(lock->message);
+	if (!lock->message && lock->remotemsg) lock->message = copystring(lock->remotemsg);
 	lock->keylist.ShrinkToFit();
 }
 
diff --git a/src/p_switch.cpp b/src/p_switch.cpp
index dfcef3184..c44c2a707 100644
--- a/src/p_switch.cpp
+++ b/src/p_switch.cpp
@@ -292,7 +292,7 @@ void P_ProcessSwitchDef ()
 		{
 			free (def1);
 		}
-		free (picname);
+		delete [] picname;
 		return;
 	}
 
@@ -316,7 +316,7 @@ void P_ProcessSwitchDef ()
 	def2->PairIndex = AddSwitchDef (def1);
 	def1->PairIndex = AddSwitchDef (def2);
 	def1->QuestPanel = def2->QuestPanel = quest;
-	free (picname);
+	delete [] picname;
 }
 
 FSwitchDef *ParseSwitchDef (bool ignoreBad)
diff --git a/src/r_data.cpp b/src/r_data.cpp
index ea84da9df..aac0f79f8 100644
--- a/src/r_data.cpp
+++ b/src/r_data.cpp
@@ -234,9 +234,11 @@ int FTextureManager::CreateTexture (int lumpnum, int usetype)
 {
 	FTexture *out = NULL;
     enum { t_patch, t_raw, t_imgz, t_png } type = t_patch;
-	DWORD first4bytes;
+	DWORD first4bytes=0;
 
-	if (lumpnum < 0)
+	// Must check the length of the lump. Zero length flat markers (F1_START etc.) will come through here.
+	// 13 is the minimum length of andthing valid (i.e a 1x1 pixel Doom patch.)
+	if (lumpnum < 0 || Wads.LumpLength(lumpnum)<13)
 	{
 		return -1;
 	}
diff --git a/src/sdl/sdlvideo.cpp b/src/sdl/sdlvideo.cpp
index 8311aacf5..121effbb3 100644
--- a/src/sdl/sdlvideo.cpp
+++ b/src/sdl/sdlvideo.cpp
@@ -277,6 +277,7 @@ SDLFB::SDLFB (int width, int height, bool fullscreen)
 	NeedGammaUpdate = false;
 	UpdatePending = false;
 	NotPaletted = false;
+	FlashAmount = 0;
 	
 	Screen = SDL_SetVideoMode (width, height, vid_displaybits,
 		SDL_HWSURFACE|SDL_HWPALETTE|SDL_DOUBLEBUF|SDL_ANYFORMAT|
diff --git a/src/v_font.cpp b/src/v_font.cpp
index 240c76c4a..c28a17d4b 100644
--- a/src/v_font.cpp
+++ b/src/v_font.cpp
@@ -1233,7 +1233,7 @@ void V_InitCustomFonts()
 	char namebuffer[16], templatebuf[16];
 	int adder=0;
 	int i;
-	int llump,lastlump=-1;
+	int llump,lastlump=0;
 	int format;
 	int start;
 	int first;