Fix off-by-one error in scanner buffer size limit

This commit is contained in:
Max Brunsfeld 2018-07-18 13:19:03 -07:00
parent e74795bc0d
commit 083e6b9fbd
1 changed files with 2 additions and 2 deletions

View File

@ -34,13 +34,13 @@ struct Scanner {
Tag &tag = tags[j]; Tag &tag = tags[j];
if (tag.type == CUSTOM) { if (tag.type == CUSTOM) {
unsigned name_length = tag.custom_tag_name.size(); unsigned name_length = tag.custom_tag_name.size();
if (i + 2 + name_length > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break; if (i + 2 + name_length >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break;
buffer[i++] = static_cast<char>(tag.type); buffer[i++] = static_cast<char>(tag.type);
buffer[i++] = name_length; buffer[i++] = name_length;
tag.custom_tag_name.copy(&buffer[i], name_length); tag.custom_tag_name.copy(&buffer[i], name_length);
i += name_length; i += name_length;
} else { } else {
if (i + 1 > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break; if (i + 1 >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break;
buffer[i++] = static_cast<char>(tag.type); buffer[i++] = static_cast<char>(tag.type);
} }
} }