From 083e6b9fbde9db145db9eade18de84a8cd76824f Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 18 Jul 2018 13:19:03 -0700 Subject: [PATCH] Fix off-by-one error in scanner buffer size limit --- src/scanner.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scanner.cc b/src/scanner.cc index 15de616..196153e 100644 --- a/src/scanner.cc +++ b/src/scanner.cc @@ -34,13 +34,13 @@ struct Scanner { Tag &tag = tags[j]; if (tag.type == CUSTOM) { 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(tag.type); buffer[i++] = name_length; tag.custom_tag_name.copy(&buffer[i], name_length); i += name_length; } else { - if (i + 1 > TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break; + if (i + 1 >= TREE_SITTER_SERIALIZATION_BUFFER_SIZE) break; buffer[i++] = static_cast(tag.type); } }