Fixed bounds check and exception type.
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user