Skip to content

Commit 9d4dc13

Browse files
committed
Fix socket reads of messages of exactly 1024 in size
Signed-off-by: falkTX <[email protected]>
1 parent 8ad95cb commit 9d4dc13

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/socket.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ void socket_run(int exit_on_failure)
348348

349349
if (count > 0) /* Data received */
350350
{
351-
if (count == g_buffer_size)
351+
if (count == g_buffer_size && buffer[count - 1] != '\0')
352352
{
353353
/* if message is bigger than our buffer, dynamically allocate more data until we receive it all */
354354
int new_count, new_buffer_size;
@@ -379,15 +379,7 @@ void socket_run(int exit_on_failure)
379379
count += new_count;
380380

381381
if (msgbuffer[count - 1] == '\0')
382-
{
383-
// ignore leftover null bytes
384-
while (count > 1 && msgbuffer[count - 1] == '\0')
385-
--count;
386-
387-
// make sure to keep 1 null byte at the end of the string
388-
++count;
389382
break;
390-
}
391383
}
392384
else if (new_count < 0) /* Error */
393385
{
@@ -410,6 +402,13 @@ void socket_run(int exit_on_failure)
410402

411403
if (g_receive_cb)
412404
{
405+
// ignore leftover null bytes
406+
while (count > 1 && msgbuffer[count - 1] == '\0')
407+
--count;
408+
409+
// make sure to keep 1 null byte at the end of the string
410+
++count;
411+
413412
msg.data = msgbuffer;
414413

415414
while (count > 0)

0 commit comments

Comments
 (0)