Skip to content

Commit 27da7de

Browse files
committed
patch 8.1.1968: crash when using nested map()
Problem: Crash when using nested map(). Solution: Clear the pointer in prepare_vimvar(). (Ozaki Kiichi, closes #4890, closes #4891)
1 parent 8e0a8e7 commit 27da7de

4 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/evalvars.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,19 +489,21 @@ get_spellword(list_T *list, char_u **pp)
489489

490490
/*
491491
* Prepare v: variable "idx" to be used.
492-
* Save the current typeval in "save_tv".
492+
* Save the current typeval in "save_tv" and clear it.
493493
* When not used yet add the variable to the v: hashtable.
494494
*/
495495
void
496496
prepare_vimvar(int idx, typval_T *save_tv)
497497
{
498498
*save_tv = vimvars[idx].vv_tv;
499+
vimvars[idx].vv_str = NULL; // don't free it now
499500
if (vimvars[idx].vv_type == VAR_UNKNOWN)
500501
hash_add(&vimvarht, vimvars[idx].vv_di.di_key);
501502
}
502503

503504
/*
504505
* Restore v: variable "idx" to typeval "save_tv".
506+
* Note that the v: variable must have been cleared already.
505507
* When no longer defined, remove the variable from the v: hashtable.
506508
*/
507509
void

src/testdir/test_filter_map.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func Test_filter_map_nested()
5757
let x = {"x":10}
5858
let r = map(range(2), 'filter(copy(x), "1")')
5959
call assert_equal([x, x], r)
60+
61+
let r = map(copy(x), 'filter(copy(x), "1")')
62+
call assert_equal({"x": x}, r)
6063
endfunc
6164

6265
" dict with funcref

src/testdir/test_functions.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,10 @@ func Test_readdir()
15431543
let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1})
15441544
call assert_equal(1, len(files))
15451545

1546+
" Nested readdir() must not crash
1547+
let files = readdir('Xdir', 'readdir("Xdir", "1") != []')
1548+
call sort(files)->assert_equal(['bar.txt', 'dir', 'foo.txt'])
1549+
15461550
eval 'Xdir'->delete('rf')
15471551
endfunc
15481552

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1968,
764766
/**/
765767
1967,
766768
/**/

0 commit comments

Comments
 (0)