Fix instances of lump searching not being case insensitive

This commit is contained in:
James R 2022-11-25 16:30:11 -08:00
parent 90e3d01395
commit 9abb5c0e62

View file

@ -1070,16 +1070,11 @@ UINT16 W_CheckNumForMapPwad(const char *name, UINT32 hash, UINT16 wad, UINT16 st
UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; UINT16 i;
static char uname[8 + 1]; UINT32 hash = quickncasehash(name, 8);
UINT32 hash;
if (!TestValidLump(wad,0)) if (!TestValidLump(wad,0))
return INT16_MAX; return INT16_MAX;
strlcpy(uname, name, sizeof uname);
strupr(uname);
hash = quickncasehash(uname, 8);
// //
// scan forward // scan forward
// start at 'startlump', useful parameter when there are multiple // start at 'startlump', useful parameter when there are multiple
@ -1092,7 +1087,7 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
if (lump_p->hash != hash) if (lump_p->hash != hash)
continue; continue;
if (strncmp(lump_p->name, uname, sizeof(uname) - 1)) if (strncasecmp(lump_p->name, name, 8))
continue; continue;
return i; return i;
} }
@ -1111,16 +1106,11 @@ UINT16 W_CheckNumForNamePwad(const char *name, UINT16 wad, UINT16 startlump)
UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump) UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
UINT16 i; UINT16 i;
static char uname[256 + 1]; UINT32 hash = quickncasehash(name, 8); // Not a mistake, legacy system for short lumpnames
UINT32 hash;
if (!TestValidLump(wad,0)) if (!TestValidLump(wad,0))
return INT16_MAX; return INT16_MAX;
strlcpy(uname, name, sizeof uname);
strupr(uname);
hash = quickncasehash(uname, 8); // Not a mistake, legacy system for short lumpnames
// //
// scan forward // scan forward
// start at 'startlump', useful parameter when there are multiple // start at 'startlump', useful parameter when there are multiple
@ -1133,7 +1123,7 @@ UINT16 W_CheckNumForLongNamePwad(const char *name, UINT16 wad, UINT16 startlump)
{ {
if (lump_p->hash != hash) if (lump_p->hash != hash)
continue; continue;
if (strcmp(lump_p->longname, uname)) if (strcasecmp(lump_p->longname, name))
continue; continue;
return i; return i;
} }
@ -1227,7 +1217,7 @@ lumpnum_t W_CheckNumForName(const char *name)
{ {
if (!lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname[8] if (!lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname[8]
&& lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumphash == hash && lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumphash == hash
&& strncmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name, 8) == 0) && strncasecmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name, 8) == 0)
{ {
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1); lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum; return lumpnumcache[lumpnumcacheindex].lumpnum;
@ -1282,7 +1272,7 @@ lumpnum_t W_CheckNumForLongName(const char *name)
for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--) for (i = lumpnumcacheindex + LUMPNUMCACHESIZE; i > lumpnumcacheindex; i--)
{ {
if (lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumphash == hash if (lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumphash == hash
&& strcmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0) && strcasecmp(lumpnumcache[i & (LUMPNUMCACHESIZE - 1)].lumpname, name) == 0)
{ {
lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1); lumpnumcacheindex = i & (LUMPNUMCACHESIZE - 1);
return lumpnumcache[lumpnumcacheindex].lumpnum; return lumpnumcache[lumpnumcacheindex].lumpnum;