Skip to content

Commit

Permalink
fix: allocate one more byte to add null termination
Browse files Browse the repository at this point in the history
  • Loading branch information
eminfedar committed Aug 2, 2023
1 parent d66588d commit 78641cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion async-sockets/include/tcpsocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions async-sockets/include/udpsocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 78641cf

Please sign in to comment.