From 0d295aff2835c7c92049f885da38dd306480d826 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Sun, 1 Jul 2018 10:02:33 +0900 Subject: [PATCH] Fix net reads when len < available packet size --- modules/net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/net.c b/modules/net.c index 1b1d0974..0376c439 100644 --- a/modules/net.c +++ b/modules/net.c @@ -743,7 +743,7 @@ size_t net_recv(struct socket* socket, uint8_t* buffer, size_t len) { free(node); } - size_to_read = MIN(len, offset + socket->bytes_available); + size_to_read = MIN(len, socket->bytes_available); if (tcpdata->payload != 0) { memcpy(buffer + offset, tcpdata->payload + socket->bytes_read, size_to_read); @@ -752,8 +752,8 @@ size_t net_recv(struct socket* socket, uint8_t* buffer, size_t len) { offset += size_to_read; if (size_to_read < socket->bytes_available) { - socket->bytes_available = socket->bytes_available - size_to_read; - socket->bytes_read = size_to_read; + socket->bytes_available -= size_to_read; + socket->bytes_read += size_to_read; socket->current_packet = tcpdata; } else { socket->bytes_available = 0;