Skip to content

Commit

Permalink
Do not memcpy from empty source (#147)
Browse files Browse the repository at this point in the history
* Do not memcpy from empty source

* Update scanner.c

---------

Co-authored-by: Vladimir Makaev <[email protected]>
  • Loading branch information
yangchi and VladimirMakaev authored Oct 9, 2024
1 parent ec98567 commit 76f53c4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,10 @@ void tree_sitter_kotlin_external_scanner_destroy(void *payload) {

unsigned tree_sitter_kotlin_external_scanner_serialize(void *payload, char *buffer) {
Stack *stack = (Stack *)payload;
memcpy(buffer, stack->contents, stack->size);
if (stack->size > 0) {
// it's an undefined behavior to memcpy 0 bytes
memcpy(buffer, stack->contents, stack->size);
}
return stack->size;
}

Expand Down

0 comments on commit 76f53c4

Please sign in to comment.