Skip to content

Commit

Permalink
Merge pull request Wilfred#90 from elm-tooling/fix-null-pointer-as-ar…
Browse files Browse the repository at this point in the history
…gument

Fix null pointer as argument
  • Loading branch information
razzeee authored Mar 9, 2021
2 parents eaad25a + 5b2a115 commit 508f760
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ namespace
{
size_t i = 0;

size_t stack_size = runback.size();
if (stack_size > UINT8_MAX)
stack_size = UINT8_MAX;
buffer[i++] = stack_size;
size_t runback_count = runback.size();
if (runback_count > UINT8_MAX)
runback_count = UINT8_MAX;
buffer[i++] = runback_count;

memcpy(&buffer[i], runback.data(), stack_size);
i += stack_size;
if (runback_count > 0)
{
memcpy(&buffer[i], runback.data(), runback_count);
}
i += runback_count;

buffer[i++] = indent_length;

Expand Down Expand Up @@ -63,7 +66,11 @@ namespace

size_t runback_count = (uint8_t)buffer[i++];
runback.resize(runback_count);
memcpy(runback.data(), &buffer[i], runback_count);
if (runback_count > 0)
{

memcpy(runback.data(), &buffer[i], runback_count);
}
i += runback_count;
indent_length = buffer[i++];
for (; i < length; i++)
Expand Down

0 comments on commit 508f760

Please sign in to comment.