diff --git a/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java b/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java index b02ad38a..8569d938 100644 --- a/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java +++ b/src/main/java/li/cil/circuity/vm/device/memory/ByteBufferMemory.java @@ -29,7 +29,7 @@ public class ByteBufferMemory implements PhysicalMemory { @Override public int load(final int offset, final int sizeLog2) throws MemoryAccessException { - if (offset < 0 || offset >= data.limit() - (1 << sizeLog2)) { + if (offset < 0 || offset > data.limit() - (1 << sizeLog2)) { throw new LoadFaultException(offset); } switch (sizeLog2) { @@ -46,7 +46,7 @@ public class ByteBufferMemory implements PhysicalMemory { @Override public void store(final int offset, final int value, final int sizeLog2) throws MemoryAccessException { - if (offset < 0 || offset >= data.limit() - (1 << sizeLog2)) { + if (offset < 0 || offset > data.limit() - (1 << sizeLog2)) { throw new StoreFaultException(offset); } switch (sizeLog2) { diff --git a/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java b/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java index 7274099a..2f7774cc 100644 --- a/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java +++ b/src/main/java/li/cil/circuity/vm/device/memory/UnsafeMemory.java @@ -5,6 +5,7 @@ import li.cil.circuity.api.vm.device.memory.PhysicalMemory; import li.cil.circuity.api.vm.device.memory.Sizes; import li.cil.circuity.vm.UnsafeGetter; import li.cil.circuity.vm.device.memory.exception.LoadFaultException; +import li.cil.circuity.vm.device.memory.exception.StoreFaultException; import sun.misc.Cleaner; import sun.misc.Unsafe; import sun.misc.VM; @@ -52,7 +53,7 @@ public final class UnsafeMemory implements PhysicalMemory { @Override public int load(final int offset, final int sizeLog2) throws MemoryAccessException { - if (offset < 0 || offset >= size - (1 << sizeLog2)) { + if (offset < 0 || offset > size - (1 << sizeLog2)) { throw new LoadFaultException(offset); } switch (sizeLog2) { @@ -69,8 +70,8 @@ public final class UnsafeMemory implements PhysicalMemory { @Override public void store(final int offset, final int value, final int sizeLog2) throws MemoryAccessException { - if (offset < 0 || offset >= size - (1 << sizeLog2)) { - throw new LoadFaultException(offset); + if (offset < 0 || offset > size - (1 << sizeLog2)) { + throw new StoreFaultException(offset); } switch (sizeLog2) { case Sizes.SIZE_8_LOG2: