Fix out of bounds RAM flush.

This can happen whenever the PC wraps around a mirror.
This commit is contained in:
David Guillen Fandos 2022-01-03 01:23:51 +01:00
parent 908fb831e0
commit e71290e0ad
1 changed files with 12 additions and 4 deletions

View File

@ -3448,11 +3448,19 @@ void flush_translation_cache_ram(void)
// Proceed to clean the SMC area if needed
// (also try to memset as little as possible for performance)
if(iwram_code_max)
memset(&iwram[iwram_code_min], 0, iwram_code_max - iwram_code_min);
if (iwram_code_max) {
if(iwram_code_max > iwram_code_min)
memset(&iwram[iwram_code_min], 0, iwram_code_max - iwram_code_min);
else
memset(iwram, 0, 0x8000);
}
if(ewram_code_max)
memset(&ewram[0x40000 + ewram_code_min], 0, ewram_code_max - ewram_code_min);
if (ewram_code_max) {
if(ewram_code_max > ewram_code_min)
memset(&ewram[0x40000 + ewram_code_min], 0, ewram_code_max - ewram_code_min);
else
memset(&ewram[0x40000], 0, 0x40000);
}
iwram_code_min = ~0U;
iwram_code_max = 0U;