From 78641cfde398d2cd71649f6911ee1bf4953498c0 Mon Sep 17 00:00:00 2001 From: Emin Fedar Date: Wed, 2 Aug 2023 15:42:20 +0300 Subject: [PATCH] fix: allocate one more byte to add null termination --- async-sockets/include/tcpsocket.hpp | 2 +- async-sockets/include/udpsocket.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/async-sockets/include/tcpsocket.hpp b/async-sockets/include/tcpsocket.hpp index 2f31dea..9ee8781 100644 --- a/async-sockets/include/tcpsocket.hpp +++ b/async-sockets/include/tcpsocket.hpp @@ -96,7 +96,7 @@ class TCPSocket : public BaseSocket private: static void Receive(TCPSocket* socket) { - char tempBuffer[BUFFER_SIZE]; + char tempBuffer[BUFFER_SIZE+1]; ssize_t messageLength; while ((messageLength = recv(socket->sock, tempBuffer, BUFFER_SIZE, 0)) > 0) diff --git a/async-sockets/include/udpsocket.hpp b/async-sockets/include/udpsocket.hpp index 3610358..f9b8b9a 100644 --- a/async-sockets/include/udpsocket.hpp +++ b/async-sockets/include/udpsocket.hpp @@ -135,7 +135,7 @@ class UDPSocket : public BaseSocket private: static void Receive(UDPSocket* udpSocket) { - char tempBuffer[BUFFER_SIZE]; + char tempBuffer[BUFFER_SIZE+1]; ssize_t messageLength; while ((messageLength = recv(udpSocket->sock, tempBuffer, BUFFER_SIZE, 0)) != -1) @@ -154,7 +154,7 @@ class UDPSocket : public BaseSocket sockaddr_in hostAddr; socklen_t hostAddrSize = sizeof(hostAddr); - char tempBuffer[BUFFER_SIZE]; + char tempBuffer[BUFFER_SIZE+1]; ssize_t messageLength; while ((messageLength = recvfrom(udpSocket->sock, tempBuffer, BUFFER_SIZE, 0, (sockaddr* )&hostAddr, &hostAddrSize)) != -1)