fix: stop off-by-one read past the last line in semantic tokens - #387
Open
Booyaka101 wants to merge 1 commit into
Open
fix: stop off-by-one read past the last line in semantic tokens#387Booyaka101 wants to merge 1 commit into
Booyaka101 wants to merge 1 commit into
Conversation
The position loop ran one index past the end of the line-length table, reading a nil entry and erroring on the arithmetic. Stop at the last valid line instead, which still covers it without the out-of-bounds read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
get_character_position_at_offsetiteratesline(a 0-indexed LSP line number) up to#lines_lengths, but indexes the 1-indexedlines_lengthsas[line + 1]. On the final iteration that readslines_lengths[#lines_lengths + 1](nil) and errors:Iterating to
#lines_lengths - 1covers the last line (its index is#lines_lengths - 1) without the out-of-bounds read. In-range offsets are unaffected — they return earlier in the loop — and an offset past the end now returnsnil, matching the documentedLspPosition|nilreturn.Closes #386