Fix crash w/ goto_previous_sibling when parent node has leading extra child (#4472) (#4473)

* Fix crash w/ goto_previous_sibling when parent node has leading extra
child Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>



* Fix lint



---------


(cherry picked from commit f91255a201)

Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
This commit is contained in:
tree-sitter-ci-bot[bot] 2025-05-27 17:35:57 -07:00 committed by GitHub
parent 02f9c1502b
commit 75550c8e2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 90 additions and 46 deletions

View file

@ -129,14 +129,18 @@ static inline bool ts_tree_cursor_child_iterator_previous(
};
*visible = ts_subtree_visible(*child);
bool extra = ts_subtree_extra(*child);
if (!extra && self->alias_sequence) {
*visible |= self->alias_sequence[self->structural_child_index];
self->structural_child_index--;
}
self->position = length_backtrack(self->position, ts_subtree_padding(*child));
self->child_index--;
if (!extra && self->alias_sequence) {
*visible |= self->alias_sequence[self->structural_child_index];
if (self->child_index > 0) {
self->structural_child_index--;
}
}
// unsigned can underflow so compare it to child_count
if (self->child_index < self->parent.ptr->child_count) {
Subtree previous_child = ts_subtree_children(self->parent)[self->child_index];