Skip to content

Commit

Permalink
Fix crash with invalid autosave (fixes #839)
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Mar 24, 2024
1 parent 5caa08d commit 9ade064
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/autosave.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/cdogs/cwolfmap/wad/wad.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static int WAD_ExpandBuffer(wad_t *wad, int newsize)
{
wad->handle.buffer = oldarray;
return 1;
}
}

if (oldarray)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -1438,7 +1438,7 @@ int WAD_GetEntryCount(wad_t *wad, const char *name)
i++;
}

return i;
return out;
}

// ---------------------------------------------------------------
Expand Down

0 comments on commit 9ade064

Please sign in to comment.