diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-18 10:25:12 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-18 10:25:12 +0100 |
| commit | 03dae41b2ec20905af780bbcf5c033f683f19efb (patch) | |
| tree | 1cc770e2c553394d9760aa28a47440061c43d559 /lib/xixanta/src/errors.rs | |
| parent | da49e5e75f81a05081d1b858b6ea78cb378c017c (diff) | |
| download | tools.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.rs | 18 |
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 + ) + } } } |
