Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEMO-413] Fix index checking for byte access of MemoryChunk using UNSAFE #234

Merged
merged 2 commits into from
Aug 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class MemoryChunk {
@SuppressWarnings("restriction")
protected static final long BYTE_ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
private static final boolean LITTLE_ENDIAN = (ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN);
private static final int BYTE_SIZE = 1;
private static final int SHORT_SIZE = 2;
private static final int CHAR_SIZE = 2;
private static final int INT_SIZE = 4;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void release() {
@SuppressWarnings("restriction")
public final byte get(final int index) {
final long pos = address + index;
if (checkIndex(index, pos, 0)) {
if (checkIndex(index, pos, BYTE_SIZE)) {
return UNSAFE.getByte(pos);
} else if (address > addressLimit) {
throw new IllegalStateException("MemoryChunk has been freed");
Expand All @@ -135,7 +136,7 @@ public final byte get(final int index) {
@SuppressWarnings("restriction")
public final void put(final int index, final byte b) {
final long pos = address + index;
if (checkIndex(index, pos, 0)) {
if (checkIndex(index, pos, BYTE_SIZE)) {
UNSAFE.putByte(pos, b);
} else if (address > addressLimit) {
throw new IllegalStateException("MemoryChunk has been freed");
Expand Down