add sanity checks in save_file.c

though it would be a better idea to solve the problem that leads to -1 being passed to these instead
This commit is contained in:
fgsfds 2020-07-07 20:57:18 +03:00
parent 97be18f11d
commit fde15809b7
1 changed files with 8 additions and 1 deletions

View File

@ -342,6 +342,9 @@ static void save_file_bswap(struct SaveBuffer *buf) {
}
void save_file_do_save(s32 fileIndex) {
if (fileIndex < 0 || fileIndex >= NUM_SAVE_FILES)
return;
if (gSaveFileModified)
#ifdef TEXTSAVES
{
@ -370,6 +373,9 @@ void save_file_do_save(s32 fileIndex) {
}
void save_file_erase(s32 fileIndex) {
if (fileIndex < 0 || fileIndex >= NUM_SAVE_FILES)
return;
touch_high_score_ages(fileIndex);
bzero(&gSaveBuffer.files[fileIndex][0], sizeof(gSaveBuffer.files[fileIndex][0]));
@ -379,7 +385,8 @@ void save_file_erase(s32 fileIndex) {
//! Needs to be s32 to match on -O2, despite no return value.
BAD_RETURN(s32) save_file_copy(s32 srcFileIndex, s32 destFileIndex) {
UNUSED s32 pad;
if (srcFileIndex < 0 || srcFileIndex >= NUM_SAVE_FILES || destFileIndex < 0 || destFileIndex >= NUM_SAVE_FILES)
return;
touch_high_score_ages(destFileIndex);
bcopy(&gSaveBuffer.files[srcFileIndex][0], &gSaveBuffer.files[destFileIndex][0],