avoid demo lump name collisions (#712)

* check if the demo file name gets truncated to a lump name that is already present

* only apply to demos loaded from the command line

* no need to copy string, lumpinfo[] isn't going to change anymore at this point

* lumps called DEMO* are considered safe

* correct order

* Update w_wad.c

* comments

* reverse search order
This commit is contained in:
Fabian Greffrath 2022-09-03 13:15:29 +02:00 committed by GitHub
parent 73ea00854b
commit 8d4ccf9a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 0 deletions

View File

@ -3675,6 +3675,9 @@ void D_CheckNetPlaybackSkip(void);
void G_DeferedPlayDemo(char* name)
{
// [FG] avoid demo lump name collisions
W_DemoLumpNameCollision(&name);
defdemoname = name;
gameaction = ga_playdemo;

View File

@ -555,6 +555,47 @@ boolean W_IsIWADLump (const int lump)
lumpinfo[lump].wad_file == wadfiles[0];
}
// [FG] avoid demo lump name collisions
void W_DemoLumpNameCollision(char **name)
{
const char *const safename = "DEMO1";
char basename[9];
int i, lump;
ExtractFileBase(*name, basename);
// [FG] lumps called DEMO* are considered safe
if (!strncasecmp(basename, safename, 4))
{
return;
}
lump = W_CheckNumForName(basename);
if (lump >= 0)
{
for (i = lump - 1; i >= 0; i--)
{
if (!strncasecmp(lumpinfo[i].name, basename, 8))
{
break;
}
}
if (i >= 0)
{
fprintf(stderr, "Demo lump name collision detected with lump \'%.8s\' from %s.\n",
lumpinfo[i].name, W_WadNameForLump(i));
// [FG] the DEMO1 lump is almost certainly always a demo lump
M_StringCopy(lumpinfo[lump].name, safename, 8);
*name = lumpinfo[lump].name;
W_InitLumpHash();
}
}
}
void W_CloseFileDescriptors(void)
{
int i;

View File

@ -121,6 +121,7 @@ extern void WritePredefinedLumpWad(const char *filename); // jff 5/6/98
// [FG] name of the WAD file that contains the lump
const char *W_WadNameForLump (const int lump);
boolean W_IsIWADLump (const int lump);
void W_DemoLumpNameCollision(char **name);
void W_CloseFileDescriptors(void);