Skip to content

Commit

Permalink
Allocate new unsigned char buffer for processed line in heap, fixing …
Browse files Browse the repository at this point in the history
…crash

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Jul 21, 2023
1 parent cd67afc commit 6a21c64
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,10 @@ - (void)processInBuffer

if (firstSeparatorIndex.location == NSNotFound) {
NSLog(@"No separator found. Creating new buffer qith space for null terminator.");
unsigned char newBuffer[inBufferLength + 1];
memcpy(&newBuffer, buffer, inBufferLength);
buffer = &newBuffer[0];

unsigned char *newBuffer = malloc(sizeof(unsigned char) * (inBufferLength + 1));
memcpy(newBuffer, buffer, inBufferLength);
buffer = newBuffer;
nullTerminatorIndex = inBufferLength;
} else {
nullTerminatorIndex = firstSeparatorIndex.location;
Expand Down

0 comments on commit 6a21c64

Please sign in to comment.