Skip to content

Commit

Permalink
[many] off by one...
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Apr 6, 2024
1 parent 08a5eea commit a597500
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go/src/ram.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (ram *RAM) get(addr uint16) uint8 {
}
var bank = uint32(ram.ram_bank) * RAM_BANK_SIZE
var offset = uint32(addr) - 0xA000
if bank+offset > ram.cart.ram_size {
if bank+offset >= ram.cart.ram_size {
// this should never happen because we die on ram_bank being
// set to a too-large value
panic("Reading from external ram beyond limit: {:04x} ({:02x}:{:04x})")
Expand Down
2 changes: 1 addition & 1 deletion nim/src/ram.nim
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ template get*(self: RAM, address: uint16): uint8 =

let bank = self.ramBank.int * RAM_BANK_SIZE.int;
let offset = address.int - 0xA000;
if bank + offset > self.cart.ram_size.int:
if bank + offset >= self.cart.ram_size.int:
# this should never happen because we die on ramBank being
# set to a too-large value
raise errors.InvalidRamRead.newException("FIXME brgbsd")
Expand Down
2 changes: 1 addition & 1 deletion rs/src/ram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl RAM {
}
let bank = self.ram_bank as usize * RAM_BANK_SIZE as usize;
let offset = addr as usize - 0xA000;
if bank + offset > self.cart.ram_size as usize {
if bank + offset >= self.cart.ram_size as usize {
// this should never happen because we die on ram_bank being
// set to a too-large value
panic!(
Expand Down
2 changes: 1 addition & 1 deletion zig/src/ram.zig
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub const RAM = struct {
}
var bank = self.ram_bank * RAM_BANK_SIZE;
var offset = addr - 0xA000;
if (bank + offset > self.cart.ram_size) {
if (bank + offset >= self.cart.ram_size) {
// this should never happen because we die on ram_bank being
// set to a too-large value
print("Reading from external ram beyond limit: {} ({}:{})\n", .{ bank + offset, self.ram_bank, (addr - 0xA000) });
Expand Down

0 comments on commit a597500

Please sign in to comment.