Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix infinite loop for argument object not supported by % #285

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

vanaigr
Copy link

@vanaigr vanaigr commented Nov 6, 2023

If the argument textobject is modified and o contains a character that is not supported by % (or the matchpairs do not contain that character):

'a': {'argument': [{'o': 'a', 'c': 'b', 's': 'c'}]}

then using this textobject can result in Vim freezing if the unsupported character is located inside of a pair of matching symbols.
For example, pressing daa with the cursor before

(a)

would freeze the editor.

The issue is that the function for finding the boundary of the argument uses % on the found symbol, and if % doesn't know where to jump on that symbol, it would move the cursor to the beginning of the outer pair of matching items (opening parenthesis in this case) - before the cursor's last position, which leads to searchpos finding the same match again, creating an infinite loop.

The fix is to check whether the % has moved the cursor backwards and return it to its last position, so that the searchpos would find a next match (matching at cursor position is not set in a:flags2).

The iteration count check is not necessary, but it takes around 30 seconds for it to return an error on my laptop for the example above, and would prevent Vim from completely freezing if something else causes the loop to never exit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant