aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/errors.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-18 10:25:12 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-18 10:25:12 +0100
commit03dae41b2ec20905af780bbcf5c033f683f19efb (patch)
tree1cc770e2c553394d9760aa28a47440061c43d559 /lib/xixanta/src/errors.rs
parentda49e5e75f81a05081d1b858b6ea78cb378c017c (diff)
downloadtools.nes-03dae41b2ec20905af780bbcf5c033f683f19efb.tar.gz
tools.nes-03dae41b2ec20905af780bbcf5c033f683f19efb.zip
Prevent addresses which are out of bounds
In some bad scenarios addresses might be pointing out of bounds (e.g. a reference further than 0xFFFF). This has to be avoided and through fuzzy testing we even got Rust panics for out of bounds u16 arithmetic. Hence, just go through usize for the actual computation and check with u16::MAX. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/errors.rs')
-rw-r--r--lib/xixanta/src/errors.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/xixanta/src/errors.rs b/lib/xixanta/src/errors.rs
index d64183d..f6317d4 100644
--- a/lib/xixanta/src/errors.rs
+++ b/lib/xixanta/src/errors.rs
@@ -37,6 +37,7 @@ pub enum ContextErrorReason {
UnknownVariable,
BadScope,
Label,
+ Bounds,
Other,
}
@@ -45,18 +46,23 @@ pub struct ContextError {
pub line: usize,
pub reason: ContextErrorReason,
pub message: String,
+ pub global: bool,
}
impl std::error::Error for ContextError {}
impl fmt::Display for ContextError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(
- f,
- "Context error (line {}): {}.",
- self.line + 1,
- self.message
- )
+ if self.global {
+ write!(f, "Context error: {}.", self.message)
+ } else {
+ write!(
+ f,
+ "Context error (line {}): {}.",
+ self.line + 1,
+ self.message
+ )
+ }
}
}