diff --git a/src/p_saveg.c b/src/p_saveg.c
index 01711a737f43db7001dc8ae87cd712e528c1a63d..029df08f4befdbe0f897ee781cb52038f099bcd8 100644
--- a/src/p_saveg.c
+++ b/src/p_saveg.c
@@ -502,14 +502,11 @@ static void P_NetArchiveWorld(void)
 	maplinedef_t *mld;
 	const sector_t *ss = sectors;
 	UINT8 diff, diff2;
-	char *lumpfullName;
 
 	WRITEUINT32(save_p, ARCHIVEBLOCK_WORLD);
 	put = save_p;
 
-	lumpfullName = (wadfiles[WADFILENUM(lastloadedmaplumpnum)]->lumpinfo + LUMPNUM(lastloadedmaplumpnum))->name2;
-
-	if (!strnicmp(lumpfullName + strlen(lumpfullName) - 4, ".wad", 4)) // welp it's a map wad in a pk3
+	if (W_IsLumpWad(lastloadedmaplumpnum)) // welp it's a map wad in a pk3
 	{ // HACK: Open wad file rather quickly so we can get the data from the relevant lumps
 		UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC);
 		filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
@@ -658,7 +655,6 @@ static void P_NetArchiveWorld(void)
 
 	WRITEUINT16(put, 0xffff);
 
-
 	// do lines
 	for (i = 0; i < numlines; i++, mld++, li++)
 	{
diff --git a/src/p_setup.c b/src/p_setup.c
index 497bba4458c6981ad7df4d3a09d4e77937792edf..a9fc57652f63d54a5f1b88966c4ac8db49e81649 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -2658,7 +2658,6 @@ boolean P_SetupLevel(boolean skipprecip)
 	// use gamemap to get map number.
 	// 99% of the things already did, so.
 	// Map header should always be in place at this point
-	char *lumpfullName;
 	INT32 i, loadprecip = 1, ranspecialwipe = 0;
 	INT32 loademblems = 1;
 	INT32 fromnetsave = 0;
@@ -2841,8 +2840,7 @@ boolean P_SetupLevel(boolean skipprecip)
 	// As it is implemented right now, we're assuming an uncompressed WAD.
 	// (As in, a normal PWAD, not ZWAD or anything. The lump itself can be compressed.)
 	// We're not accounting for extra lumps and scrambled lump positions. Any additional data will cause an error.
-	lumpfullName = (wadfiles[WADFILENUM(lastloadedmaplumpnum)]->lumpinfo + LUMPNUM(lastloadedmaplumpnum))->name2;
-	if (!strnicmp(lumpfullName + strlen(lumpfullName) - 4, ".wad", 4))
+	if (W_IsLumpWad(lastloadedmaplumpnum))
 	{
 		// Remember that we're assuming that the WAD will have a specific set of lumps in a specific order.
 		UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC);
diff --git a/src/p_spec.c b/src/p_spec.c
index 498ebcf7d2c2bce8a71be72fe4db9be975296c15..0b005baff88d86ce2e55ee57d5df88fd029039d7 100644
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -6307,9 +6307,8 @@ void P_SpawnSpecials(INT32 fromnetsave)
 				{
 					UINT8 *data;
 					UINT16 b;
-					char *lumpfullName = (wadfiles[WADFILENUM(lastloadedmaplumpnum)]->lumpinfo + LUMPNUM(lastloadedmaplumpnum))->name2;
 
-					if (!strnicmp(lumpfullName + strlen(lumpfullName) - 4, ".wad", 4)) // welp it's a map wad in a pk3
+					if (W_IsLumpWad(lastloadedmaplumpnum)) // welp it's a map wad in a pk3
 					{ // HACK: Open wad file rather quickly so we can get the data from the sidedefs lump
 						UINT8 *wadData = W_CacheLumpNum(lastloadedmaplumpnum, PU_STATIC);
 						filelump_t *fileinfo = (filelump_t *)(wadData + ((wadinfo_t *)wadData)->infotableofs);
diff --git a/src/w_wad.c b/src/w_wad.c
index 0dea2c3525de6f62edec0e61dad48f9114ffc510..816bbd44f4b352ff97ecfb5826e4eeb8c48fa381 100644
--- a/src/w_wad.c
+++ b/src/w_wad.c
@@ -1051,6 +1051,19 @@ size_t W_LumpLength(lumpnum_t lumpnum)
 	return W_LumpLengthPwad(WADFILENUM(lumpnum),LUMPNUM(lumpnum));
 }
 
+//
+// W_IsLumpWad
+// Is the lump a WAD? (presumably in a PK3)
+//
+boolean W_IsLumpWad(lumpnum_t lumpnum)
+{
+	const char *lumpfullName = (wadfiles[WADFILENUM(lumpnum)]->lumpinfo + LUMPNUM(lumpnum))->name2;
+
+	if (strlen(lumpfullName) < 4)
+		return false; // can't possibly be a wad can it?
+	return !strnicmp(lumpfullName + strlen(lumpfullName) - 4, ".wad", 4);
+}
+
 /* report a zlib or i/o error */
 void zerr(int ret)
 {
diff --git a/src/w_wad.h b/src/w_wad.h
index 26e87f3c2dc260f8f854a4e9765bf1e6108af3a2..ef4213579faf2120bda9b9459e79a9746b29f41c 100644
--- a/src/w_wad.h
+++ b/src/w_wad.h
@@ -139,6 +139,8 @@ UINT8 W_LumpExists(const char *name); // Lua uses this.
 size_t W_LumpLengthPwad(UINT16 wad, UINT16 lump);
 size_t W_LumpLength(lumpnum_t lumpnum);
 
+boolean W_IsLumpWad(lumpnum_t lumpnum); // for loading maps from WADs in PK3s
+
 void zerr(int ret); // zlib error checking
 
 size_t W_ReadLumpHeaderPwad(UINT16 wad, UINT16 lump, void *dest, size_t size, size_t offset);