Skip to content

Commit

Permalink
fix: set bufferSize.
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz committed Jul 27, 2024
1 parent dc0e94f commit 9a729c9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,17 @@ EosDetector::~EosDetector() {

EosDetectorType EosDetector::append(int tokenId, const char* piece) {
int pieceLength = strlen(piece);
int length = bufferPos + pieceLength + 1;
if (length > bufferSize) {
char* newBuffer = new char[length];
int newSize = bufferPos + pieceLength + 1;
if (newSize > bufferSize) {
char* newBuffer = new char[newSize];
if (bufferPos > 0)
memcpy(newBuffer, buffer, bufferPos);
if (bufferSize > 0)
delete[] buffer;
buffer = newBuffer;
bufferSize = newSize;
}
memcpy(buffer + bufferPos, piece, pieceLength + 1);
memcpy(&buffer[bufferPos], piece, pieceLength + 1);
bufferPos += pieceLength;

// detection
Expand Down

0 comments on commit 9a729c9

Please sign in to comment.