You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An unexpected value is returned by public unsafe static ulong Read(ulong* uPtr, int bitposition, int bits) on small reads.
This seems to be caused by the fact that the following array element is always taken into account: value |= uPtr[index + 1] << (MAXBITS - offset);
The following code reproduces the issue. It prints 31 but it should print 30. An additional bit is enabled due to the OR mentioned above.
const ulong WRITE_VALUE = 30;
byte[] buffer = new byte[1024];
for (int i = 0; i < buffer.Length; ++i)
{
buffer[i] = byte.MaxValue;
}
fixed (byte* ptrBuf = buffer)
{
ulong* ptrUlBuf = (ulong*) ptrBuf;
int writeBitPos = 0;
ArraySerializeUnsafe.Write(ptrUlBuf, WRITE_VALUE, ref writeBitPos, 5);
int readBitPos = 0;
ulong readValue = ArraySerializeUnsafe.Read(ptrUlBuf, readBitPos, 5);
// Prints 31 but should print 30
Debug.Log(readValue);
}
I haven't tested other unsafe functions but if they do something similiar or the same they might also return wrong values on small reads. The safe functions seem to return the correct values though.
The text was updated successfully, but these errors were encountered:
An unexpected value is returned by
public unsafe static ulong Read(ulong* uPtr, int bitposition, int bits)
on small reads.This seems to be caused by the fact that the following array element is always taken into account:
value |= uPtr[index + 1] << (MAXBITS - offset);
The following code reproduces the issue. It prints 31 but it should print 30. An additional bit is enabled due to the OR mentioned above.
I haven't tested other unsafe functions but if they do something similiar or the same they might also return wrong values on small reads. The safe functions seem to return the correct values though.
The text was updated successfully, but these errors were encountered: