Fixed bounds check and exception type.

This commit is contained in:
Florian Nücke
2020-09-26 11:59:35 +02:00
parent 452f02e102
commit d68271c99b
2 changed files with 6 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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: