Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ static inline unsigned serialize(Scanner *scanner, char *buffer) {
buffer[size++] = (char)scanner->open_heredocs.size;
for (uint32_t i = 0; i < scanner->open_heredocs.size; i++) {
Heredoc *heredoc = array_get(&scanner->open_heredocs, i);
if (size + 2 + heredoc->word.size >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
if (size + 3 + sizeof(uint32_t) + heredoc->word.size >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe 2 is incorrect in the old code: we write 3 bools below, not 2.

return 0;
}
buffer[size++] = (char)heredoc->end_word_indentation_allowed;
buffer[size++] = (char)heredoc->allows_interpolation;
buffer[size++] = (char)heredoc->started;
buffer[size++] = (char)heredoc->word.size;
memcpy(&buffer[size], &heredoc->word.size, sizeof(uint32_t));
size += sizeof(uint32_t);
memcpy(&buffer[size], heredoc->word.contents, heredoc->word.size);
size += heredoc->word.size;
}
Expand Down Expand Up @@ -149,7 +150,9 @@ static inline void deserialize(Scanner *scanner, const char *buffer, unsigned le
heredoc.started = buffer[size++];

heredoc.word = (String)array_new();
uint8_t word_length = buffer[size++];
uint32_t word_length;
memcpy(&word_length, &buffer[size], sizeof(uint32_t));
size += sizeof(uint32_t);
array_reserve(&heredoc.word, word_length);
memcpy(heredoc.word.contents, &buffer[size], word_length);
heredoc.word.size = word_length;
Expand Down
16 changes: 16 additions & 0 deletions test/corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,22 @@ heredoc content
(heredoc_content)
(heredoc_end)))

========================================
heredoc with long identifier (>255 chars)
========================================

<<~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
content
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

---

(program
(heredoc_beginning)
(heredoc_body
(heredoc_content)
(heredoc_end)))

========================================
heredoc with interspersed end word
========================================
Expand Down
Loading