diff options
| author | 2016-09-05 11:46:00 +0200 | |
|---|---|---|
| committer | 2016-09-06 11:44:15 +0200 | |
| commit | 98392fb5e373e85ff9341ab3b193bc9ec005d6dd (patch) | |
| tree | ecce2a62579fadf4316843db4560dee587b2bc68 /src/emu/dirom.cpp | |
| parent | d2e070f63ac578c140898253a4d1cad970fec6dc (diff) | |
dirom: Resist to out-of-bounds bank numbers [O. Galibert]
Diffstat (limited to 'src/emu/dirom.cpp')
| -rw-r--r-- | src/emu/dirom.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/emu/dirom.cpp b/src/emu/dirom.cpp index 75ca04b1546..eb0d6ea29b8 100644 --- a/src/emu/dirom.cpp +++ b/src/emu/dirom.cpp @@ -21,6 +21,11 @@ void device_rom_interface::set_rom_bank(int bank) if(!m_bank) emu_fatalerror("%s: device_rom_interface::set_rom_bank called without banking setup", device().tag()); + if(bank >= m_bank_count) { + device().logerror("Warning: requested bank %x higher than actual bank count %x\n", bank, m_bank_count); + bank = bank % m_bank_count; + } + m_cur_bank = bank; m_bank->set_entry(bank); } @@ -35,14 +40,14 @@ void device_rom_interface::set_rom(const void *base, UINT32 size) { UINT32 mend = m_rom_config.addr_width() == 32 ? 0xffffffff : (1 << m_rom_config.addr_width()) - 1; UINT32 rend = size-1; - UINT32 banks = mend == 0xffffffff ? 1 : (rend+1) / (mend+1); - if(banks < 1) - banks = 1; + m_bank_count = mend == 0xffffffff ? 1 : (rend+1) / (mend+1); + if(m_bank_count < 1) + m_bank_count = 1; if(rend >= mend) { space().install_read_bank(0, mend, device().tag()); m_bank = device().machine().memory().banks().find(device().tag())->second.get(); - m_bank->configure_entries(0, banks, const_cast<void *>(base), mend+1); + m_bank->configure_entries(0, m_bank_count, const_cast<void *>(base), mend+1); m_cur_bank = 0; } else { @@ -67,6 +72,7 @@ void device_rom_interface::interface_pre_start() m_bank = nullptr; m_cur_bank = -1; device().save_item(NAME(m_cur_bank)); + device().save_item(NAME(m_bank_count)); device().machine().save().register_postload(save_prepost_delegate(FUNC(device_rom_interface::reset_bank), this)); if(!has_configured_map(0)) { |
