To: vim_dev@googlegroups.com Subject: Patch 8.1.1968 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1968 Problem: Crash when using nested map(). Solution: Clear the pointer in prepare_vimvar(). (Ozaki Kiichi, closes #4890, closes #4891) Files: src/evalvars.c, src/testdir/test_filter_map.vim, src/testdir/test_functions.vim *** ../vim-8.1.1967/src/evalvars.c 2019-09-01 16:01:25.584754569 +0200 --- src/evalvars.c 2019-09-03 16:55:02.816106761 +0200 *************** *** 489,507 **** /* * Prepare v: variable "idx" to be used. ! * Save the current typeval in "save_tv". * When not used yet add the variable to the v: hashtable. */ void prepare_vimvar(int idx, typval_T *save_tv) { *save_tv = vimvars[idx].vv_tv; if (vimvars[idx].vv_type == VAR_UNKNOWN) hash_add(&vimvarht, vimvars[idx].vv_di.di_key); } /* * Restore v: variable "idx" to typeval "save_tv". * When no longer defined, remove the variable from the v: hashtable. */ void --- 489,509 ---- /* * Prepare v: variable "idx" to be used. ! * Save the current typeval in "save_tv" and clear it. * When not used yet add the variable to the v: hashtable. */ void prepare_vimvar(int idx, typval_T *save_tv) { *save_tv = vimvars[idx].vv_tv; + vimvars[idx].vv_str = NULL; // don't free it now if (vimvars[idx].vv_type == VAR_UNKNOWN) hash_add(&vimvarht, vimvars[idx].vv_di.di_key); } /* * Restore v: variable "idx" to typeval "save_tv". + * Note that the v: variable must have been cleared already. * When no longer defined, remove the variable from the v: hashtable. */ void *** ../vim-8.1.1967/src/testdir/test_filter_map.vim 2019-09-02 20:44:02.688728142 +0200 --- src/testdir/test_filter_map.vim 2019-09-03 16:50:08.065396708 +0200 *************** *** 57,62 **** --- 57,65 ---- let x = {"x":10} let r = map(range(2), 'filter(copy(x), "1")') call assert_equal([x, x], r) + + let r = map(copy(x), 'filter(copy(x), "1")') + call assert_equal({"x": x}, r) endfunc " dict with funcref *** ../vim-8.1.1967/src/testdir/test_functions.vim 2019-09-01 20:16:48.003438501 +0200 --- src/testdir/test_functions.vim 2019-09-03 16:52:20.436818274 +0200 *************** *** 1543,1548 **** --- 1543,1552 ---- let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) call assert_equal(1, len(files)) + " Nested readdir() must not crash + let files = readdir('Xdir', 'readdir("Xdir", "1") != []') + call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt']) + eval 'Xdir'->delete('rf') endfunc *** ../vim-8.1.1967/src/version.c 2019-09-02 22:56:20.992583887 +0200 --- src/version.c 2019-09-03 16:44:33.754847947 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1968, /**/ -- Very funny, Scotty. Now beam down my clothes. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///