fix register bounds check

This commit is contained in:
ipc 2023-08-13 17:00:26 +02:00
parent 41e275c778
commit b3591f2f96
1 changed files with 2 additions and 2 deletions

View File

@ -376,7 +376,7 @@ impl Cpu {
fn reg_read(&mut self, reg: u8) -> u32 {
let reg = reg as usize;
if reg > self.reg.len() {
if reg >= self.reg.len() {
panic!("invalid register read");
}
self.reg[reg]
@ -384,7 +384,7 @@ impl Cpu {
fn reg_write(&mut self, reg: u8, val: u32) {
let reg = reg as usize;
if reg > self.reg.len() {
if reg >= self.reg.len() {
panic!("invalid register write");
}
self.reg[reg] = val;