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)
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 )
You can’t perform that action at this time.
0 commit comments