From 957434e244f62fbc24e7f44eafc557f6f88f49eb Mon Sep 17 00:00:00 2001 From: Jerrett Longworth Date: Sun, 30 Jul 2023 21:21:33 -0400 Subject: [PATCH] Fix programs that are too long from panicking Signed-off-by: Jerrett Longworth --- src/emulation_core/mips/memory.rs | 2 +- src/main.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/emulation_core/mips/memory.rs b/src/emulation_core/mips/memory.rs index c2b946dce..2abcf1921 100644 --- a/src/emulation_core/mips/memory.rs +++ b/src/emulation_core/mips/memory.rs @@ -35,7 +35,7 @@ impl Memory { fn check_valid_address(&self, address: usize) -> Result<(), String> { if address % 4 != 0 { Err(format!("Address `{address}` is not word-aligned")) - } else if address > self.memory.len() { + } else if address >= self.memory.len() { Err(format!( "Address `{}` out of bounds of memory of size {}", address, diff --git a/src/main.rs b/src/main.rs index 3f300d8a2..a59835a88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,8 +145,10 @@ fn app() -> Html { // Load the binary into the datapath's memory match datapath.initialize(assembled) { Ok(_) => (), - // In the case of an error, stop early. - Err(_) => return, + Err(msg) => { + // In the case of an error, note this and stop early. + parser_text_output.set(format!("This program failed to load into the datapath. Message returned by datapath: {msg}")); + } } // log!(datapath.memory.to_string()); text_model.set_value(&program_info.updated_monaco_string); // Expands pseudo-instructions to their hardware counterpart.