Fix crash with invalid autosave (fixes #839)

This commit is contained in:
Cong
2024-03-24 14:02:51 +11:00
parent 5caa08deff
commit 9ade064d12
2 changed files with 5 additions and 5 deletions

View File

@@ -438,7 +438,7 @@ const CampaignSave *AutosaveGetCampaign(Autosave *autosave, const char *path)
const CampaignSave *AutosaveGetLastCampaign(const Autosave *a)
{
if (a->LastCampaignIndex < 0)
if (a->LastCampaignIndex < 0 || a->LastCampaignIndex >= (int)a->Campaigns.size)
{
return NULL;
}

View File

@@ -147,7 +147,7 @@ static int WAD_ExpandBuffer(wad_t *wad, int newsize)
{
wad->handle.buffer = oldarray;
return 1;
}
}
if (oldarray)
{
@@ -859,7 +859,7 @@ static wadentry_t* wi_buffer_add_entry_at(wad_t *wad, const char *name, int inde
unsigned char *dest = &(wad->handle.buffer[wad->buffer_size]);
memcpy(dest, buffer, size);
wadentry_t* entry;
wadentry_t* entry;
if (!(entry = WAD_AddEntryCommon(wad, name, size, wad->buffer_size, index)))
{
waderrno = WADERROR_OUT_OF_MEMORY;
@@ -1068,7 +1068,7 @@ wad_t* WAD_Open(const char *filename)
}
out->type = WI_FILE;
out->handle.file = fp;
out->handle.file = fp;
return out;
}
@@ -1438,7 +1438,7 @@ int WAD_GetEntryCount(wad_t *wad, const char *name)
i++;
}
return i;
return out;
}
// ---------------------------------------------------------------