Packet& Packet::operator >>(char* data)
{
// First extract string length
Uint32 length = 0;
*this >> length;
if ((length > 0) && CheckSize(length))
{
// Then extract characters
std::memcpy(data, GetData() + myReadPos, length);
data[length] = '\0';
// Update reading position
myReadPos += length;
}
return *this;
}
This piece of code is made for buffer overflow. This function should be aware of teh size pointed by data.
As C++ as a string class, this operator overloading should just be removed in my oppinion. To ensure the possibility of binding throw C, a function can be added like read(char* data, size_t maxCharRead).