Skip to content

Commit

Permalink
add crashfix for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Oct 18, 2024
1 parent 71b21f8 commit 630d531
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/platform/platform_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,19 @@ error_t socketReceive(Socket *socket, void *data_in,

if ((flags & SOCKET_FLAG_BREAK_CHAR) && buff->buffer_used)
{
/* warning: searches outside buffer if binary */
const char *ptr = strchr(buff->buffer, flags & 0xFF);
/* First, check for the null terminator (0x00) in the buffer */
const char *null_pos = memchr(buff->buffer, 0x00, buff->buffer_used);
if (null_pos)
{
/* If null terminator is found, use strchr up to the null */
ptr = strchr(buff->buffer, flags & 0xFF);
}
else
{
TRACE_WARNING("buffer does not contain null terminator\r\n");
/* If no null terminator, safely use memchr over the whole buffer */
ptr = memchr(buff->buffer, flags & 0xFF, buff->buffer_used);
}

if (ptr)
{
Expand Down

0 comments on commit 630d531

Please sign in to comment.