From 4f0c1d11eb29c7ac185e171a97d1f02cd9fea61d Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 4 Jan 2017 17:25:30 -0500 Subject: [PATCH] 16 bytes alignment for extra buffer --- NTCPSession.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 5e44429d..65da5def 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -532,10 +532,12 @@ namespace transport uint8_t * buf = nullptr, * moreBuf = m_ReceiveBuffer; if (moreBytes + m_ReceiveBufferOffset > NTCP_BUFFER_SIZE) { - buf = new uint8_t[moreBytes + m_ReceiveBufferOffset]; - if (m_ReceiveBufferOffset) - memcpy (buf, m_ReceiveBuffer, m_ReceiveBufferOffset); + buf = new uint8_t[moreBytes + m_ReceiveBufferOffset + 16]; moreBuf = buf; + uint8_t rem = ((size_t)buf) & 0x0f; + if (rem) moreBuf += (16 - rem); // align 16 + if (m_ReceiveBufferOffset) + memcpy (moreBuf, m_ReceiveBuffer, m_ReceiveBufferOffset); } moreBytes = m_Socket.read_some (boost::asio::buffer (moreBuf + m_ReceiveBufferOffset, moreBytes), ec); if (ec)