Skip to content

Commit

Permalink
reduce buffer null warnings (attempt)
Browse files Browse the repository at this point in the history
  • Loading branch information
SciLor committed Nov 28, 2024
1 parent 9930675 commit 34b0c15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/platform/platform_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ error_t socketReceive(Socket *socket, void *data_in,
buff->buffer_used = 0;
buff->buffer_size = size;
buff->buffer = osAllocMem(buff->buffer_size);
buff->buffer[buff->buffer_size - 1] = '\0';
socket->interface = (NetInterface *)buff;
}

Expand All @@ -281,7 +282,7 @@ error_t socketReceive(Socket *socket, void *data_in,
const char *ptr = NULL;

/* First, check for the null terminator (0x00) in the buffer */
const char *null_pos = memchr(buff->buffer, 0x00, buff->buffer_used);
const char *null_pos = memchr(buff->buffer, 0x00, max_size);
if (null_pos)
{
/* If null terminator is found, use strchr up to the null */
Expand All @@ -291,7 +292,7 @@ error_t socketReceive(Socket *socket, void *data_in,
{
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);
// ptr = memchr(buff->buffer, flags & 0xFF, max_size);
}

if (ptr)
Expand Down
5 changes: 3 additions & 2 deletions src/platform/platform_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ error_t socketReceive(Socket *socket, void *data_in,
buff->buffer_used = 0;
buff->buffer_size = size;
buff->buffer = osAllocMem(buff->buffer_size);
buff->buffer[buff->buffer_size - 1] = '\0';
socket->interface = (NetInterface *)buff;
}

Expand All @@ -330,7 +331,7 @@ error_t socketReceive(Socket *socket, void *data_in,
const char *ptr = NULL;

/* First, check for the null terminator (0x00) in the buffer */
const char *null_pos = memchr(buff->buffer, 0x00, buff->buffer_used);
const char *null_pos = memchr(buff->buffer, 0x00, max_size);
if (null_pos)
{
/* If null terminator is found, use strchr up to the null */
Expand All @@ -340,7 +341,7 @@ error_t socketReceive(Socket *socket, void *data_in,
{
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);
// ptr = memchr(buff->buffer, flags & 0xFF, buff->buffer_used);
}

if (ptr)
Expand Down

0 comments on commit 34b0c15

Please sign in to comment.