From e167892affd57194487ad0955fd9f53c63763757 Mon Sep 17 00:00:00 2001 From: darcy Date: Tue, 17 Sep 2024 22:50:06 +1000 Subject: [PATCH 1/2] Fix off-by-one error for negative offset range-checking --- src/air.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/air.rs b/src/air.rs index c88f41c..4877de3 100644 --- a/src/air.rs +++ b/src/air.rs @@ -323,7 +323,7 @@ impl AsmLine { let (offset, _) = label_pos.overflowing_sub(self.line); let offset = (offset as i16) - 1; // Must fit in specified offset bits - if offset.abs() > 2i16.pow(bits - 1) - 1 { + if offset.abs() > 2i16.pow(bits - 1) - if offset > 0 { 1 } else { 0 } { bail!( severity = Severity::Error, r#"Difference between label and label reference is too large: at line {}, referencing line {} From bcf4b2d158d63763f31d1876d3ef28afcfb9f6fd Mon Sep 17 00:00:00 2001 From: darcy Date: Fri, 20 Sep 2024 19:40:57 +1000 Subject: [PATCH 2/2] Fix test for label range --- src/air.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/air.rs b/src/air.rs index 4877de3..f45fd35 100644 --- a/src/air.rs +++ b/src/air.rs @@ -436,7 +436,7 @@ mod test { }; assert!(asm.emit().is_err()); let asm = AsmLine { - line: 256, + line: 257, stmt: AirStmt::Branch { flag: Flag::Nzp, dest_label: Label::Ref(1),