]> git.sesse.net Git - pistorm/commitdiff
Only allow get_mapped functions to return RAM and ROM ranges
authorbeeanyew <beeanyew@gmail.com>
Thu, 3 Jun 2021 09:14:49 +0000 (11:14 +0200)
committerbeeanyew <beeanyew@gmail.com>
Thu, 3 Jun 2021 09:14:49 +0000 (11:14 +0200)
config_file/config_file.c

index 526efd64ad02145f1322823aaba6089c6ee18530..d60b9b7844a0b4f681c895a3aed176012a34fe09 100644 (file)
@@ -538,8 +538,10 @@ int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address) {
   for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
     if (cfg->map_type[i] == MAPTYPE_NONE || !cfg->map_data[i])
       continue;
-    if (address >= cfg->map_offset[i] && address < cfg->map_high[i])
-      return i;
+    else if (address >= cfg->map_offset[i] && address < cfg->map_high[i]) {
+      if (cfg->map_type[i] == MAPTYPE_RAM || cfg->map_type[i] == MAPTYPE_RAM_NOALLOC || cfg->map_type[i] == MAPTYPE_ROM)
+        return i;
+    }
   }
 
   return -1;
@@ -549,12 +551,9 @@ uint8_t *get_mapped_data_pointer_by_address(struct emulator_config *cfg, uint32_
   for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
     if (cfg->map_type[i] == MAPTYPE_NONE || !cfg->map_data[i])
       continue;
-    if (address >= cfg->map_offset[i] && address < cfg->map_high[i]) {
-      if (cfg->map_type[i] == MAPTYPE_RAM || cfg->map_type[i] == MAPTYPE_RAM_NOALLOC) {
+    else if (address >= cfg->map_offset[i] && address < cfg->map_high[i]) {
+      if (cfg->map_type[i] == MAPTYPE_RAM || cfg->map_type[i] == MAPTYPE_RAM_NOALLOC || cfg->map_type[i] == MAPTYPE_ROM)
         return cfg->map_data[i] + (address - cfg->map_offset[i]);
-      } else {
-        return NULL;
-      }
     }
   }