summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGriffinR <griffin.g.richards@gmail.com>2021-10-13 13:30:53 -0400
committerGitHub <noreply@github.com>2021-10-13 13:30:53 -0400
commitb9f6dd128d210a9cbcbc46ec7beaa99bddf56872 (patch)
treeb82f989ec12954ae35e0efa9c837eec81c0c7cff /src
parentf55a8cb688267cf5b9aa2da08d9c2523f4c0d702 (diff)
parent5860e0e9372f89f4fc32b225c3bd7b7de91b78c1 (diff)
Merge pull request #1515 from GriffinRichards/fix-saveblockchunk
Disallow negative sizes in SAVEBLOCK_CHUNK
Diffstat (limited to 'src')
-rw-r--r--src/save.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/save.c b/src/save.c
index 52301df03..a05d2c184 100644
--- a/src/save.c
+++ b/src/save.c
@@ -43,11 +43,12 @@ static u8 HandleWriteSector(u16 a1, const struct SaveSectionLocation *location);
// (u8 *)structure was removed from the first statement of the macro in Emerald.
// This is because malloc is used to allocate addresses so storing the raw
// addresses should not be done in the offsets information.
-#define SAVEBLOCK_CHUNK(structure, chunkNum) \
-{ \
- chunkNum * SECTOR_DATA_SIZE, \
- min(sizeof(structure) - chunkNum * SECTOR_DATA_SIZE, SECTOR_DATA_SIZE) \
-} \
+#define SAVEBLOCK_CHUNK(structure, chunkNum) \
+{ \
+ chunkNum * SECTOR_DATA_SIZE, \
+ sizeof(structure) >= chunkNum * SECTOR_DATA_SIZE ? \
+ min(sizeof(structure) - chunkNum * SECTOR_DATA_SIZE, SECTOR_DATA_SIZE) : 0 \
+}
static const struct SaveSectionOffsets sSaveSectionOffsets[] =
{