Skip to content
Browse files

Fix memory access checks for accesses one past the end of the ROM.

  • Loading branch information...
1 parent 7b025dd commit b59ba9add47d25f5e21d673343bf9c1e2ad5d898 @nelhage committed May 31, 2011
Showing with 2 additions and 2 deletions.
  1. +2 −2 MMU.js
View
4 MMU.js
@@ -5,14 +5,14 @@ var MMU = {
},
read: function(addr) {
var ea = (addr & ~CPU.PC_SUPERVISOR) >> 2;
- if (ea > MMU.memory.length) {
+ if (ea >= MMU.memory.length) {
throw new Error("Invalid read: " + (addr & ~CPU.PC_SUPERVISOR));
}
return MMU.memory[ea];
},
write: function(addr, data) {
var ea = (addr & ~CPU.PC_SUPERVISOR) >> 2;
- if (ea > MMU.memory.length) {
+ if (ea >= MMU.memory.length) {
throw new Error("Invalid read: " + (addr & ~CPU.PC_SUPERVISOR));
}
MMU.memory[ea] = data;

0 comments on commit b59ba9a

Please sign in to comment.
Something went wrong with that request. Please try again.