ByteBuffer: fully defined Position handling

Cast input ints into unsigned to make them 2s complement guarand.
This commit is contained in:
Tiger Wang 2022-01-14 21:07:07 +00:00 committed by Alexander Harkness
parent da0fdbe113
commit e3d0874f7d

View File

@ -487,8 +487,8 @@ bool cByteBuffer::ReadLEInt(int & a_Value)
bool cByteBuffer::ReadXYZPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ) bool cByteBuffer::ReadXYZPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
{ {
CHECK_THREAD CHECK_THREAD
Int64 Value; UInt64 Value;
if (!ReadBEInt64(Value)) if (!ReadBEUInt64(Value))
{ {
return false; return false;
} }
@ -512,8 +512,8 @@ bool cByteBuffer::ReadXYZPosition64(int & a_BlockX, int & a_BlockY, int & a_Bloc
bool cByteBuffer::ReadXZYPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ) bool cByteBuffer::ReadXZYPosition64(int & a_BlockX, int & a_BlockY, int & a_BlockZ)
{ {
CHECK_THREAD CHECK_THREAD
Int64 Value; UInt64 Value;
if (!ReadBEInt64(Value)) if (!ReadBEUInt64(Value))
{ {
return false; return false;
} }
@ -771,10 +771,10 @@ bool cByteBuffer::WriteXYZPosition64(Int32 a_BlockX, Int32 a_BlockY, Int32 a_Blo
{ {
CHECK_THREAD CHECK_THREAD
CheckValid(); CheckValid();
return WriteBEInt64( return WriteBEUInt64(
(static_cast<Int64>(a_BlockX & 0x3FFFFFF) << 38) | ((static_cast<UInt64>(a_BlockX) & 0x3FFFFFF) << 38) |
(static_cast<Int64>(a_BlockY & 0xFFF) << 26) | ((static_cast<UInt64>(a_BlockY) & 0xFFF) << 26) |
(static_cast<Int64>(a_BlockZ & 0x3FFFFFF)) (static_cast<UInt64>(a_BlockZ) & 0x3FFFFFF)
); );
} }
@ -786,10 +786,10 @@ bool cByteBuffer::WriteXZYPosition64(Int32 a_BlockX, Int32 a_BlockY, Int32 a_Blo
{ {
CHECK_THREAD CHECK_THREAD
CheckValid(); CheckValid();
return WriteBEInt64( return WriteBEUInt64(
(static_cast<Int64>(a_BlockX & 0x3FFFFFF) << 38) | ((static_cast<UInt64>(a_BlockX) & 0x3FFFFFF) << 38) |
(static_cast<Int64>(a_BlockZ & 0x3FFFFFF) << 12) | ((static_cast<UInt64>(a_BlockZ) & 0x3FFFFFF) << 12) |
(static_cast<Int64>(a_BlockY & 0xFFF)) (static_cast<UInt64>(a_BlockY) & 0xFFF)
); );
} }