File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -348,7 +348,7 @@ void socket_run(int exit_on_failure)
348
348
349
349
if (count > 0 ) /* Data received */
350
350
{
351
- if (count == g_buffer_size )
351
+ if (count == g_buffer_size && buffer [ count - 1 ] != '\0' )
352
352
{
353
353
/* if message is bigger than our buffer, dynamically allocate more data until we receive it all */
354
354
int new_count , new_buffer_size ;
@@ -379,15 +379,7 @@ void socket_run(int exit_on_failure)
379
379
count += new_count ;
380
380
381
381
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 ;
389
382
break ;
390
- }
391
383
}
392
384
else if (new_count < 0 ) /* Error */
393
385
{
@@ -410,6 +402,13 @@ void socket_run(int exit_on_failure)
410
402
411
403
if (g_receive_cb )
412
404
{
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
+
413
412
msg .data = msgbuffer ;
414
413
415
414
while (count > 0 )
You can’t perform that action at this time.
0 commit comments