Handle out-of-bound read in utf16_iterate

Also simplify the test so we call `utf16_iterate` directly. Calling
`utf16_iterate` via `SpyInput` and `ts_document_parse` doesn't seem to reliably
trigger the problem using valgrind.

valgrind also doesn't detect the problem if we use a string literal like:
  `utf16_iterate("", 1, &code_point);`
This commit is contained in:
Phil Turnbull 2017-07-17 13:57:10 -07:00
parent 035abc1e15
commit e7662c2213
3 changed files with 23 additions and 13 deletions

View file

@ -72,19 +72,6 @@ describe("Document", [&]() {
"(array (true) (false))");
});
it("handles truncated UTF16 data", [&]() {
char *content = reinterpret_cast<char*>(malloc(1));
spy_input->content = string((const char *)content, 1);
spy_input->encoding = TSInputEncodingUTF16;
ts_document_set_input(document, spy_input->input());
ts_document_invalidate(document);
ts_document_parse(document);
free(content);
});
it("allows columns to be measured in either bytes or characters", [&]() {
const char16_t content[] = u"[true, false]";
spy_input->content = string((const char *)content, sizeof(content));