Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing "address out of bank range" check on instructions addresses #37

Merged
merged 1 commit into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "customasm"
version = "0.10.6"
version = "0.10.7"
edition = "2018"
authors = ["Henrique Lorenzi <https://hlorenzi.com>"]
description = "An assembler for custom, user-defined instruction sets!"
Expand Down
3 changes: 3 additions & 0 deletions src/asm/assembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ impl AssemblerState
Some(addr) => addr,
None => return Err(report.error_span("address overflowed valid range", span))
};

if bankdef_index != 0 && addr >= bankdef.addr + bankdef.size
{ return Err(report.error_span("address is out of bank range", span)); }

Ok(addr)
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,8 @@ fn test_banks()

test("", "#bankdef \"hello\" { #addr 0, #size 10 } \n #res 1 \n #addr 0 \n #res 1", Pass((4, "")));
test("", "#bankdef \"hello\" { #addr 10, #size 10 } \n #res 1 \n #addr 0 \n #res 1", Fail(("asm", 3, "out of bank range")));
test("test -> 0x12", "#bankdef \"hello\" { #addr 0, #size 3, #outp 0 } \n #res 1 \n test \n test", Pass((4, "001212")));
test("test -> 0x12", "#bankdef \"hello\" { #addr 0, #size 2, #outp 0 } \n #res 1 \n test \n test", Fail(("asm", 4, "out of bank range")));

test("", "#bankdef \"hello\" { #addr 0, #size 4, #outp 0 }
#bankdef \"world\" { #addr 0, #size 4, #outp 0 }",
Expand Down