1
0

Fixed slot parsing in 1.2.5 causing weird behavior ( http://forum.mc-server.org/showthread.php?tid=551&pid=4413#pid4413 )

Also added some asserts into ByteBuffer so that this won't happen again.

git-svn-id: http://mc-server.googlecode.com/svn/trunk@842 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-09-06 18:17:47 +00:00
parent 0ba2be666f
commit c3f82c53db
2 changed files with 6 additions and 1 deletions

View File

@ -350,6 +350,7 @@ bool cByteBuffer::WriteBEUTF16String16(const AString & a_Value)
bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count) bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count)
{ {
ASSERT(a_Count >= 0);
NEEDBYTES(a_Count); NEEDBYTES(a_Count);
char * Dst = (char *)a_Buffer; // So that we can do byte math char * Dst = (char *)a_Buffer; // So that we can do byte math
int BytesToEndOfBuffer = m_BufferSize - m_ReadPos; int BytesToEndOfBuffer = m_BufferSize - m_ReadPos;
@ -374,6 +375,7 @@ bool cByteBuffer::ReadBuf(void * a_Buffer, int a_Count)
bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count) bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count)
{ {
ASSERT(a_Count >= 0);
PUTBYTES(a_Count); PUTBYTES(a_Count);
char * Src = (char *)a_Buffer; // So that we can do byte math char * Src = (char *)a_Buffer; // So that we can do byte math
int BytesToEndOfBuffer = m_BufferSize - m_WritePos; int BytesToEndOfBuffer = m_BufferSize - m_WritePos;
@ -398,6 +400,7 @@ bool cByteBuffer::WriteBuf(const void * a_Buffer, int a_Count)
bool cByteBuffer::ReadString(AString & a_String, int a_Count) bool cByteBuffer::ReadString(AString & a_String, int a_Count)
{ {
ASSERT(a_Count >= 0);
NEEDBYTES(a_Count); NEEDBYTES(a_Count);
a_String.clear(); a_String.clear();
a_String.reserve(a_Count); a_String.reserve(a_Count);
@ -423,6 +426,7 @@ bool cByteBuffer::ReadString(AString & a_String, int a_Count)
bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars) bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars)
{ {
// Reads 2 * a_NumChars bytes and interprets it as a UTF16 string, converting it into UTF8 string a_String // Reads 2 * a_NumChars bytes and interprets it as a UTF16 string, converting it into UTF8 string a_String
ASSERT(a_NumChars >= 0);
AString RawData; AString RawData;
if (!ReadString(RawData, a_NumChars * 2)) if (!ReadString(RawData, a_NumChars * 2))
{ {
@ -438,6 +442,7 @@ bool cByteBuffer::ReadUTF16String(AString & a_String, int a_NumChars)
bool cByteBuffer::SkipRead(int a_Count) bool cByteBuffer::SkipRead(int a_Count)
{ {
ASSERT(a_Count >= 0);
if (!CanReadBytes(a_Count)) if (!CanReadBytes(a_Count))
{ {
return false; return false;

View File

@ -1310,7 +1310,7 @@ int cProtocol125::ParseItem(cItem & a_Item)
HANDLE_PACKET_READ(ReadBEShort, short, EnchantNumBytes); HANDLE_PACKET_READ(ReadBEShort, short, EnchantNumBytes);
if (EnchantNumBytes == 0) if (EnchantNumBytes <= 0)
{ {
return PARSE_OK; return PARSE_OK;
} }