Skip to content

Commit

Permalink
vim-patch:8.2.4762: using freed memory using synstack() and synID() i…
Browse files Browse the repository at this point in the history
…n WinEnter (neovim#18136)

Problem:    Using freed memory when using synstack() and synID() in WinEnter.
Solution:   Check using the syntax window. (closes vim/vim#10204)
vim/vim@ca7e86c
  • Loading branch information
zeertzjq committed Apr 16, 2022
1 parent 3f2e929 commit dcf7bc4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nvim/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -5802,8 +5802,8 @@ char_u *get_syntax_name(expand_T *xp, int idx)
int syn_get_id(win_T *wp, long lnum, colnr_T col, int trans, bool *spellp, int keep_state)
{
// When the position is not after the current position and in the same
// line of the same buffer, need to restart parsing.
if (wp->w_buffer != syn_buf || lnum != current_lnum || col < current_col) {
// line of the same window with the same buffer, need to restart parsing.
if (wp != syn_win || wp->w_buffer != syn_buf || lnum != current_lnum || col < current_col) {
syntax_start(wp, lnum);
} else if (col > current_col) {
// next_match may not be correct when moving around, e.g. with the
Expand Down
13 changes: 13 additions & 0 deletions src/nvim/testdir/test_syntax.vim
Original file line number Diff line number Diff line change
Expand Up @@ -794,5 +794,18 @@ func Test_syn_include_contains_TOP()
bw!
endfunc

" This was using freed memory
func Test_WinEnter_synstack_synID()
autocmd WinEnter * call synstack(line("."), col("."))
autocmd WinEnter * call synID(line('.'), col('.') - 1, 1)
call setline(1, 'aaaaa')
normal! $
new
close

au! WinEnter
bw!
endfunc


" vim: shiftwidth=2 sts=2 expandtab

0 comments on commit dcf7bc4

Please sign in to comment.