aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-25 23:19:00 +0800
committerGitHub <noreply@github.com>2023-04-25 23:19:00 +0800
commitac9f8669a8e4bd0cf13468d316d1746be65d3cdc (patch)
treedf048541b93297fd2de9038301dbaaab2bb114be /test
parentcacc2dc4192d17439107453733e7da6a4043cdd0 (diff)
downloadrneovim-ac9f8669a8e4bd0cf13468d316d1746be65d3cdc.tar.gz
rneovim-ac9f8669a8e4bd0cf13468d316d1746be65d3cdc.tar.bz2
rneovim-ac9f8669a8e4bd0cf13468d316d1746be65d3cdc.zip
vim-patch:9.0.0875: using freed memory when executing delfunc at more prompt (#23314)
Problem: Using freed memory when executing delfunc at the more prompt. Solution: Check function list not changed in another place. (closes vim/vim#11437) https://github.com/vim/vim/commit/398a26f7fcd58fbc6e2329f892edbb7479a971bb Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'test')
-rw-r--r--test/functional/vimscript/eval_spec.lua31
-rw-r--r--test/old/testdir/test_functions.vim27
2 files changed, 56 insertions, 2 deletions
diff --git a/test/functional/vimscript/eval_spec.lua b/test/functional/vimscript/eval_spec.lua
index b411b1e379..b3f2c1bfeb 100644
--- a/test/functional/vimscript/eval_spec.lua
+++ b/test/functional/vimscript/eval_spec.lua
@@ -191,11 +191,10 @@ describe('listing functions using :function', function()
endfunction]]):format(num), exec_capture(('function <lambda>%s'):format(num)))
end)
- -- FIXME: If the same function is deleted, the crash still happens. #20790
it('does not crash if another function is deleted while listing', function()
local screen = Screen.new(80, 24)
screen:attach()
- matches('Vim%(function%):E454: function list was modified', pcall_err(exec_lua, [=[
+ matches('Vim%(function%):E454: Function list was modified$', pcall_err(exec_lua, [=[
vim.cmd([[
func Func1()
endfunc
@@ -219,6 +218,34 @@ describe('listing functions using :function', function()
]=]))
assert_alive()
end)
+
+ it('does not crash if the same function is deleted while listing', function()
+ local screen = Screen.new(80, 24)
+ screen:attach()
+ matches('Vim%(function%):E454: Function list was modified$', pcall_err(exec_lua, [=[
+ vim.cmd([[
+ func Func1()
+ endfunc
+ func Func2()
+ endfunc
+ func Func3()
+ endfunc
+ ]])
+
+ local ns = vim.api.nvim_create_namespace('test')
+
+ vim.ui_attach(ns, { ext_messages = true }, function(event, _, content)
+ if event == 'msg_show' and content[1][2] == 'function Func1()' then
+ vim.cmd('delfunc Func2')
+ end
+ end)
+
+ vim.cmd('function')
+
+ vim.ui_detach(ns)
+ ]=]))
+ assert_alive()
+ end)
end)
it('no double-free in garbage collection #16287', function()
diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim
index a1f34ea8b6..0dd780e3fb 100644
--- a/test/old/testdir/test_functions.vim
+++ b/test/old/testdir/test_functions.vim
@@ -2618,4 +2618,31 @@ func Test_virtcol()
bwipe!
endfunc
+func Test_delfunc_while_listing()
+ CheckRunVimInTerminal
+
+ let lines =<< trim END
+ set nocompatible
+ for i in range(1, 999)
+ exe 'func ' .. 'MyFunc' .. i .. '()'
+ endfunc
+ endfor
+ au CmdlineLeave : call timer_start(0, {-> execute('delfunc MyFunc622')})
+ END
+ call writefile(lines, 'Xfunctionclear', 'D')
+ let buf = RunVimInTerminal('-S Xfunctionclear', {'rows': 12})
+
+ " This was using freed memory. The height of the terminal must be so that
+ " the next function to be listed with "j" is the one that is deleted in the
+ " timer callback, tricky!
+ call term_sendkeys(buf, ":func /MyFunc\<CR>")
+ call TermWait(buf, 50)
+ call term_sendkeys(buf, "j")
+ call TermWait(buf, 50)
+ call term_sendkeys(buf, "\<CR>")
+
+ call StopVimInTerminal(buf)
+endfunc
+
+
" vim: shiftwidth=2 sts=2 expandtab