From 490300daab72fbc6bd5b68cc461bcfe45d531071 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 13 Oct 2021 13:29:17 -0400 Subject: Disallow negative sizes in SAVEBLOCK_CHUNK --- src/save.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/save.c b/src/save.c index 3ce4025bf..2049ca9c1 100644 --- a/src/save.c +++ b/src/save.c @@ -39,11 +39,12 @@ // (u8 *)structure was removed from the first statement of the macro in Emerald // and Fire Red/Leaf Green. 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 \ +} const struct SaveSectionOffsets gSaveSectionOffsets[] = { -- cgit v1.2.3