mirror of
https://github.com/TheOfficialFloW/bd-jb
synced 2024-11-21 16:35:05 -05:00
Improve bounds checking.
This commit is contained in:
parent
ae092232a1
commit
3347cbb544
@ -40,42 +40,42 @@ public class Buffer {
|
||||
}
|
||||
|
||||
public byte getByte(int offset) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int8.SIZE);
|
||||
return api.read8(address + offset);
|
||||
}
|
||||
|
||||
public short getShort(int offset) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int16.SIZE);
|
||||
return api.read16(address + offset);
|
||||
}
|
||||
|
||||
public int getInt(int offset) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int32.SIZE);
|
||||
return api.read32(address + offset);
|
||||
}
|
||||
|
||||
public long getLong(int offset) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int64.SIZE);
|
||||
return api.read64(address + offset);
|
||||
}
|
||||
|
||||
public void putByte(int offset, byte value) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int8.SIZE);
|
||||
api.write8(address + offset, value);
|
||||
}
|
||||
|
||||
public void putShort(int offset, short value) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int16.SIZE);
|
||||
api.write16(address + offset, value);
|
||||
}
|
||||
|
||||
public void putInt(int offset, int value) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int32.SIZE);
|
||||
api.write32(address + offset, value);
|
||||
}
|
||||
|
||||
public void putLong(int offset, long value) {
|
||||
checkOffset(offset);
|
||||
checkOffset(offset, Int64.SIZE);
|
||||
api.write64(address + offset, value);
|
||||
}
|
||||
|
||||
@ -83,8 +83,8 @@ public class Buffer {
|
||||
api.memset(address, value, size);
|
||||
}
|
||||
|
||||
private void checkOffset(int offset) {
|
||||
if (offset < 0 || offset >= size) {
|
||||
private void checkOffset(int offset, int length) {
|
||||
if (offset < 0 || (offset + length) > size) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ abstract class IntBase {
|
||||
}
|
||||
|
||||
private void checkOffset(int offset) {
|
||||
if (offset < 0 || offset >= size) {
|
||||
if (offset < 0 || (offset + elementSize()) > size) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user