forked from Mirrorlandia_minetest/minetest
Fix incorrect string length check after cast
This commit is contained in:
parent
c735497a65
commit
82c6363559
@ -110,11 +110,12 @@ NetworkPacket& NetworkPacket::operator>>(std::string& dst)
|
|||||||
|
|
||||||
NetworkPacket& NetworkPacket::operator<<(const std::string &src)
|
NetworkPacket& NetworkPacket::operator<<(const std::string &src)
|
||||||
{
|
{
|
||||||
u16 msgsize = src.size();
|
if (src.size() > STRING_MAX_LEN) {
|
||||||
if (msgsize > STRING_MAX_LEN) {
|
|
||||||
throw PacketError("String too long");
|
throw PacketError("String too long");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u16 msgsize = src.size();
|
||||||
|
|
||||||
*this << msgsize;
|
*this << msgsize;
|
||||||
|
|
||||||
putRawString(src.c_str(), (u32)msgsize);
|
putRawString(src.c_str(), (u32)msgsize);
|
||||||
@ -124,11 +125,12 @@ NetworkPacket& NetworkPacket::operator<<(const std::string &src)
|
|||||||
|
|
||||||
void NetworkPacket::putLongString(const std::string &src)
|
void NetworkPacket::putLongString(const std::string &src)
|
||||||
{
|
{
|
||||||
u32 msgsize = src.size();
|
if (src.size() > LONG_STRING_MAX_LEN) {
|
||||||
if (msgsize > LONG_STRING_MAX_LEN) {
|
|
||||||
throw PacketError("String too long");
|
throw PacketError("String too long");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 msgsize = src.size();
|
||||||
|
|
||||||
*this << msgsize;
|
*this << msgsize;
|
||||||
|
|
||||||
putRawString(src.c_str(), msgsize);
|
putRawString(src.c_str(), msgsize);
|
||||||
@ -160,11 +162,12 @@ NetworkPacket& NetworkPacket::operator>>(std::wstring& dst)
|
|||||||
|
|
||||||
NetworkPacket& NetworkPacket::operator<<(const std::wstring &src)
|
NetworkPacket& NetworkPacket::operator<<(const std::wstring &src)
|
||||||
{
|
{
|
||||||
u16 msgsize = src.size();
|
if (src.size() > WIDE_STRING_MAX_LEN) {
|
||||||
if (msgsize > WIDE_STRING_MAX_LEN) {
|
|
||||||
throw PacketError("String too long");
|
throw PacketError("String too long");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u16 msgsize = src.size();
|
||||||
|
|
||||||
*this << msgsize;
|
*this << msgsize;
|
||||||
|
|
||||||
// Write string
|
// Write string
|
||||||
|
Loading…
Reference in New Issue
Block a user