Don't panic if we can't serialize our state (#80)

pull/315/head
Owen Shepherd 2022-05-19 18:09:09 +07:00 committed by GitHub
parent ff5c879d9b
commit 1b54c3f394
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

4
src/scanner.c vendored

@ -1591,7 +1591,9 @@ bool tree_sitter_haskell_external_scanner_scan(void *indents_v, TSLexer *lexer,
unsigned tree_sitter_haskell_external_scanner_serialize(void *indents_v, char *buffer) { unsigned tree_sitter_haskell_external_scanner_serialize(void *indents_v, char *buffer) {
indent_vec *indents = (indent_vec*) indents_v; indent_vec *indents = (indent_vec*) indents_v;
unsigned to_copy = sizeof(indents->data[0]) * indents->len; unsigned to_copy = sizeof(indents->data[0]) * indents->len;
assert(to_copy <= TREE_SITTER_SERIALIZATION_BUFFER_SIZE); if (to_copy > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
return 0;
}
memcpy(buffer, indents->data, to_copy); memcpy(buffer, indents->data, to_copy);
return to_copy; return to_copy;
} }