diff options
author | GriffinR <griffin.g.richards@gmail.com> | 2021-10-13 13:43:58 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-13 13:43:58 -0400 |
commit | 7f123f4d0ff5b393822d4364adc7b96ecfa66e0d (patch) | |
tree | 296e826cbd080bce3ec5bb8baa2350988ca32f16 /src | |
parent | 466e98a98364e641edef4fdd09b3e38a553ce158 (diff) | |
parent | 490300daab72fbc6bd5b68cc461bcfe45d531071 (diff) |
Merge pull request #470 from GriffinRichards/fix-saveblockchunk
Disallow negative sizes in SAVEBLOCK_CHUNK
Diffstat (limited to 'src')
-rw-r--r-- | src/save.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/save.c b/src/save.c index 2c01a3f57..6d8a14871 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[] = { |