]> granicus.if.org Git - vim/commitdiff
patch 8.1.1968: crash when using nested map() v8.1.1968
authorBram Moolenaar <Bram@vim.org>
Tue, 3 Sep 2019 15:13:37 +0000 (17:13 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 3 Sep 2019 15:13:37 +0000 (17:13 +0200)
Problem:    Crash when using nested map().
Solution:   Clear the pointer in prepare_vimvar(). (Ozaki Kiichi,
            closes #4890, closes #4891)

src/evalvars.c
src/testdir/test_filter_map.vim
src/testdir/test_functions.vim
src/version.c

index e6fb3d8988b660176e836dcbdfbe447b800ae5ec..9e1a24d3f0fb03c45cde6e7134dc7a2c350b23db 100644 (file)
@@ -489,19 +489,21 @@ get_spellword(list_T *list, char_u **pp)
 
 /*
  * Prepare v: variable "idx" to be used.
- * Save the current typeval in "save_tv".
+ * 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
index 72a8d841e95a5f146ed3036f3de8b63d3c2ce872..e144538de672479b87dec1bd2316eb487434a57a 100644 (file)
@@ -57,6 +57,9 @@ func Test_filter_map_nested()
   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
index 6984c23cce1483edbee141c58c33595fae9f06e2..20718bcc0791651a0c3d51ed385d2264cfc31b67 100644 (file)
@@ -1543,6 +1543,10 @@ func Test_readdir()
   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
 
index f5c9eec8722d00f32066482e6ee26ce14727fa2c..5dbdc9fa4e150e8ab31aad861539eac7a72fda34 100644 (file)
@@ -761,6 +761,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1968,
 /**/
     1967,
 /**/