changeset 825:e6f2c9dbf6c8

Prevent crashes if game tries to access the ROM area outside of the size of the actual ROM
author Michael Pavone <pavone@retrodev.com>
date Tue, 04 Aug 2015 21:43:20 -0700
parents 3b8267fd1687
children 9060946ce219
files romdb.c
diffstat 1 files changed, 3 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/romdb.c	Mon Aug 03 22:31:13 2015 -0700
+++ b/romdb.c	Tue Aug 04 21:43:20 2015 -0700
@@ -493,7 +493,7 @@
 		memcpy(info->map+2, base_map, sizeof(memmap_chunk) * base_chunks);
 		
 		if (ram_start >= rom_end) {
-			info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000;
+			info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
 			//TODO: ROM mirroring
 			info->map[0].mask = 0xFFFFFF;
 			info->map[0].flags = MMAP_READ;
@@ -542,8 +542,8 @@
 		memset(info->map, 0, sizeof(memmap_chunk));
 		memcpy(info->map+1, base_map, sizeof(memmap_chunk) * base_chunks);
 		
-		info->map[0].end =rom_end > 0x400000 ? rom_end : 0x400000;
-		info->map[0].mask = 0xFFFFFF;
+		info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000;
+		info->map[0].mask = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF;
 		info->map[0].flags = MMAP_READ;
 		info->map[0].buffer = rom;
 		info->save_type = SAVE_NONE;