mirror of
https://github.com/holub/mame
synced 2025-04-20 15:32:45 +03:00
divtlb.cpp: remove a crash caused by the modulus operator
In the original code all values are signed integers, so m_dynindex would overflow and become negative, then the modulus of a negative value by a positive one would generate a negative result and finally the next array read would make the program crash. Also the maximum value plus one of m_dynindex is not generally a multiple of m_dynamic and this would cause a jump in the values of liveindex.
This commit is contained in:
parent
57ddc51b52
commit
855c9d4087
@ -177,8 +177,9 @@ bool device_vtlb_interface::vtlb_fill(offs_t address, int intention)
|
||||
// if this is the first successful translation for this address, allocate a new entry
|
||||
if ((entry & VTLB_FLAGS_MASK) == 0)
|
||||
{
|
||||
int liveindex = m_dynindex++ % m_dynamic;
|
||||
int liveindex = m_dynindex;
|
||||
|
||||
m_dynindex = (m_dynindex + 1) % m_dynamic;
|
||||
|
||||
// if an entry already exists at this index, free it
|
||||
if (m_live[liveindex] != 0)
|
||||
@ -277,7 +278,10 @@ void device_vtlb_interface::vtlb_dynload(u32 index, offs_t address, vtlb_entry v
|
||||
return;
|
||||
}
|
||||
|
||||
int liveindex = m_dynindex++ % m_dynamic;
|
||||
int liveindex = m_dynindex;
|
||||
|
||||
m_dynindex = (m_dynindex + 1) % m_dynamic;
|
||||
|
||||
// is entry already live?
|
||||
if (!(entry & VTLB_FLAG_VALID))
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user