]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4762: using freed memory using synstack() and synID() in WinEnter v8.2.4762
authorzeertzjq <zeertzjq@outlook.com>
Sat, 16 Apr 2022 15:49:24 +0000 (16:49 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 16 Apr 2022 15:49:24 +0000 (16:49 +0100)
Problem:    Using freed memory when using synstack() and synID() in WinEnter.
Solution:   Check using the syntax window. (closes #10204)

src/syntax.c
src/testdir/test_syntax.vim
src/version.c

index 086d9d755e9eab97f5e72f6e54858aaea57459fb..6b71e8dfabeefda1bdea4a1234aaa3ce9373f288 100644 (file)
@@ -6486,8 +6486,9 @@ syn_get_id(
     int                keep_state)  // keep state of char at "col"
 {
     // 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
+    // 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);
index 14ae4c575ff98e027f04520090cd5beaa73b05f5..be2f458287d8f85a3622b153fdc7a5f436034575 100644 (file)
@@ -956,5 +956,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
index 19391268ff64b7db0680d6f570ff1767e5ac303c..1cc0d906b13414d0bad8019923cc740113bad5f7 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4762,
 /**/
     4761,
 /**/