diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 22:29:14 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 22:29:14 +0100 |
| commit | ec0831e82851862a6af2ade12a996634d5dfc64e (patch) | |
| tree | 48c2a5087ea3d99e9d73c245ac098b6bb1b30db5 /lib | |
| parent | e2c322ab3adb85976c15c7668128cf10f699f563 (diff) | |
| download | tools.nes-ec0831e82851862a6af2ade12a996634d5dfc64e.tar.gz tools.nes-ec0831e82851862a6af2ade12a996634d5dfc64e.zip | |
Prevent assignments on relative references
It is a really weird thing to do, but on a twisted way I can see how
someone could think of such a monstrosity. Panicking on such a case is
not valid because that's not the fault from the assembler but from the
programmer, and so a proper message should be displayed instead.
This was detected via the fuzzer, but it was a side effect from
e7c5e63d04f6 ("Evaluate bare numbers as decimal values").
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index c59150c..1f7c9a5 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -929,6 +929,7 @@ impl<'a> Assembler<'a> { Ok(right) } + // Evaluate the given node as a relative reference. fn evaluate_anonymous_relative_reference(&mut self, node: &PNode) -> Result<Bundle, Error> { self.literal_mode = Some(LiteralMode::Plain); @@ -957,7 +958,12 @@ impl<'a> Assembler<'a> { }), } } - _ => panic!("unexpected evaluation of relative reference"), + Stage::Context => Err(Error { + line: node.value.line, + source: self.source_for(node), + global: false, + message: "trying to evaluate a relative reference as a bare value".to_string(), + }), } } @@ -2264,6 +2270,16 @@ mod tests { } #[test] + fn trying_to_assign_on_relative_reference() { + assert_error( + "Var = :-", + 1, + false, + "trying to evaluate a relative reference as a bare value", + ); + } + + #[test] fn unknown_variables() { assert_error( "lda #Variable", |
