]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0586: Crash with TextPut autocmd when pasting in terminal buffer v9.2.0586
authorFoxe Chen <chen.foxe@gmail.com>
Mon, 1 Jun 2026 21:08:20 +0000 (21:08 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 1 Jun 2026 21:08:20 +0000 (21:08 +0000)
Problem:  Crash with TextPut autocmd when pasting in normal mode in a
          terminal buffer.
Solution: Skip the TextPut autocmds when reg and insert are both NULL
          and regname is not '.' (Foxe Chen).

closes: #20407

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/register.c
src/testdir/test_autocmd.vim
src/version.c

index 9daa7729e849d11eedc5bda8ee3e9c67a3c4bb8c..358fe6454f56146c04e3c4eaba36f9484ae2d456 100644 (file)
@@ -1190,6 +1190,11 @@ put_do_autocmd(
     if (recursive || regname == '_')
        return;
 
+    if (regname != '.' && insert == NULL
+           && reg == NULL)
+       // Can happen when pasting text in normal mode in a terminal buffer
+       return;
+
     v_event = get_v_event(&save_v_event);
 
     list = list_alloc();
@@ -1219,7 +1224,6 @@ put_do_autocmd(
     }
     else
     {
-       assert(reg != NULL);
        for (n = 0; n < reg->y_size; n++)
            list_append_string(list, reg->y_array[n].string,
                    (int)reg->y_array[n].length);
index a1f282e06da270e23528c5d12a91717bc5b1030e..54116a5857fff08b68845ddd6047237eb9795e10 100644 (file)
@@ -6094,7 +6094,35 @@ func Test_TextPutX()
   unlet g:post_event
   unlet g:pre_event
   bwipe!
+endfunc
+
+" Test that attempting to put text in normal mode terminal buffer does not
+" result in a crash. This only happens when terminal is only window in tabpage
+" it seems.
+func Test_TextPutPost_term_norm()
+  CheckFeature terminal
+
+  tabnew
+  term ++curwin
+
+  let bnr = bufnr('$')
+  call WaitForAssert({-> assert_equal('running', term_getstatus(bnr))})
+
+  call feedkeys("\<C-\>\<C-N>", 'xt')
+  call WaitForAssert({-> assert_equal('running,normal', term_getstatus(bnr))})
 
+  let err = 0
+
+  try
+    call feedkeys("p", 'xt')
+  catch /^Vim\%((\S\+)\)\=:E21:/
+    let err = 1
+  endtry
+
+  call assert_true(err)
+
+  unlet err
+  bwipe!
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index be7bb521b4d6a194841e8efc53bbe0377900d056..e020aedc51f8b859f4d85804eef733862a7e0c57 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    586,
 /**/
     585,
 /**/