CServer::ProcessClientPacket(): Adjust the debug message buffer size

We allocated 512 bytes to dump up to 32 data bytes in a hex form.
According to the str_hex() implementation, we need three bytes per the
source data byte (a byte is represented as a two-digit hexadecimal number
with appended space char) plus the null-termination.

We actually could re-use the last space char for the null, but it is not
implemented in str_hex(). Keep this logic as-is.

The stack-allocated buffer size reduced from 512 to 97 bytes.
This commit is contained in:
Alexander Akulich 2021-09-14 20:53:35 +03:00
parent 92abe8d545
commit 895a0b3451

View file

@ -1716,8 +1716,9 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
{
if(g_Config.m_Debug)
{
char aBuf[512];
str_hex(aBuf, sizeof(aBuf), pPacket->m_pData, minimum(pPacket->m_DataSize, 32));
constexpr int MaxDumpedDataSize = 32;
char aBuf[MaxDumpedDataSize * 3 + 1];
str_hex(aBuf, sizeof(aBuf), pPacket->m_pData, minimum(pPacket->m_DataSize, MaxDumpedDataSize));
char aBufMsg[256];
str_format(aBufMsg, sizeof(aBufMsg), "strange message ClientID=%d msg=%d data_size=%d", ClientID, Msg, pPacket->m_DataSize);