Skip to content

Commit

Permalink
Fix off-by-one in FFI (Double|Float)At(Put) prims
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 20, 2022
1 parent 0086dd4 commit 7492ef8
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ private static NativeObject newExternalAddress(final SqueakImageContext image, f
protected abstract static class PrimFFIDoubleAtNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback {
@Specialization(guards = {"byteArray.isByteType()", "byteOffsetLong > 0"})
protected static final double doFloatAtPut(final NativeObject byteArray, final long byteOffsetLong) {
return VarHandleUtils.getDoubleFromBytes(byteArray.getByteStorage(), (int) byteOffsetLong);
return VarHandleUtils.getDoubleFromBytes(byteArray.getByteStorage(), (int) byteOffsetLong - 1);
}
}

Expand All @@ -333,7 +333,7 @@ protected static final double doFloatAtPut(final NativeObject byteArray, final l
protected abstract static class PrimFFIDoubleAtPutNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback {
@Specialization(guards = {"byteArray.isByteType()", "byteOffsetLong > 0"})
protected static final double doFloatAtPut(final NativeObject byteArray, final long byteOffsetLong, final double value) {
VarHandleUtils.putDoubleIntoBytes(byteArray.getByteStorage(), (int) byteOffsetLong, value);
VarHandleUtils.putDoubleIntoBytes(byteArray.getByteStorage(), (int) byteOffsetLong - 1, value);
return value;
}
}
Expand All @@ -343,7 +343,7 @@ protected static final double doFloatAtPut(final NativeObject byteArray, final l
protected abstract static class PrimFFIFloatAtNode extends AbstractPrimitiveNode implements BinaryPrimitiveFallback {
@Specialization(guards = {"byteArray.isByteType()", "byteOffsetLong > 0"})
protected static final double doFloatAtPut(final NativeObject byteArray, final long byteOffsetLong) {
return VarHandleUtils.getFloatFromBytes(byteArray.getByteStorage(), (int) byteOffsetLong);
return VarHandleUtils.getFloatFromBytes(byteArray.getByteStorage(), (int) byteOffsetLong - 1);
}
}

Expand All @@ -352,7 +352,7 @@ protected static final double doFloatAtPut(final NativeObject byteArray, final l
protected abstract static class PrimFFIFloatAtPutNode extends AbstractPrimitiveNode implements TernaryPrimitiveFallback {
@Specialization(guards = {"byteArray.isByteType()", "byteOffsetLong > 0"})
protected static final double doFloatAtPut(final NativeObject byteArray, final long byteOffsetLong, final double value) {
VarHandleUtils.putFloatIntoBytes(byteArray.getByteStorage(), (int) byteOffsetLong, (float) value);
VarHandleUtils.putFloatIntoBytes(byteArray.getByteStorage(), (int) byteOffsetLong - 1, (float) value);
return value;
}
}
Expand Down

0 comments on commit 7492ef8

Please sign in to comment.