Patch 8.1.1964
Problem: Crash when using nested map() and filter().
Solution: Do not set the v:key type to string without clearing the pointer.
(closes #4888)
Files: src/eval.c, src/testdir/test_filter_map.vim
*** ../vim-8.1.1963/src/eval.c 2019-09-01 16:01:25.584754569 +0200
--- src/eval.c 2019-09-02 20:42:53.869075662 +0200
***************
*** 7185,7192 ****
hashtab_T *ht;
hashitem_T *hi;
dict_T *d = NULL;
- typval_T save_val;
- typval_T save_key;
blob_T *b = NULL;
int rem;
int todo;
--- 7185,7190 ----
***************
*** 7225,7242 ****
* was not passed as argument. */
if (expr->v_type != VAR_UNKNOWN)
{
prepare_vimvar(VV_VAL, &save_val);
! /* We reset "did_emsg" to be able to detect whether an error
! * occurred during evaluation of the expression. */
save_did_emsg = did_emsg;
did_emsg = FALSE;
- prepare_vimvar(VV_KEY, &save_key);
if (argvars[0].v_type == VAR_DICT)
{
- set_vim_var_type(VV_KEY, VAR_STRING);
-
ht = &d->dv_hashtab;
hash_lock(ht);
todo = (int)ht->ht_used;
--- 7223,7241 ----
* was not passed as argument. */
if (expr->v_type != VAR_UNKNOWN)
{
+ typval_T save_val;
+ typval_T save_key;
+
prepare_vimvar(VV_VAL, &save_val);
+ prepare_vimvar(VV_KEY, &save_key);
! // We reset "did_emsg" to be able to detect whether an error
! // occurred during evaluation of the expression.
save_did_emsg = did_emsg;
did_emsg = FALSE;
if (argvars[0].v_type == VAR_DICT)
{
ht = &d->dv_hashtab;
hash_lock(ht);
todo = (int)ht->ht_used;
***************
*** 7274,7280 ****
--- 7273,7281 ----
int i;
typval_T tv;
+ // set_vim_var_nr() doesn't set the type
set_vim_var_type(VV_KEY, VAR_NUMBER);
+
for (i = 0; i < b->bv_ga.ga_len; i++)
{
tv.v_type = VAR_NUMBER;
***************
*** 7285,7291 ****
if (tv.v_type != VAR_NUMBER)
{
emsg(_(e_invalblob));
! return;
}
tv.v_type = VAR_NUMBER;
blob_set(b, i, tv.vval.v_number);
--- 7286,7292 ----
if (tv.v_type != VAR_NUMBER)
{
emsg(_(e_invalblob));
! break;
}
tv.v_type = VAR_NUMBER;
blob_set(b, i, tv.vval.v_number);
***************
*** 7300,7308 ****
}
}
}
! else
{
! // argvars[0].v_type == VAR_LIST
set_vim_var_type(VV_KEY, VAR_NUMBER);
for (li = l->lv_first; li != NULL; li = nli)
--- 7301,7309 ----
}
}
}
! else // argvars[0].v_type == VAR_LIST
{
! // set_vim_var_nr() doesn't set the type
set_vim_var_type(VV_KEY, VAR_NUMBER);
for (li = l->lv_first; li != NULL; li = nli)
*** ../vim-8.1.1963/src/testdir/test_filter_map.vim 2019-01-14
22:22:25.584624342 +0100
--- src/testdir/test_filter_map.vim 2019-09-02 20:33:05.560231673 +0200
***************
*** 53,58 ****
--- 53,64 ----
call assert_equal([0, 2, 4, 6], map([1, 2, 3, 4], function('s:filter4')))
endfunc
+ func Test_filter_map_nested()
+ let x = {"x":10}
+ let r = map(range(2), 'filter(copy(x), "1")')
+ call assert_equal([x, x], r)
+ endfunc
+
" dict with funcref
func Test_filter_map_dict_expr_funcref()
let dict = {"foo": 1, "bar": 2, "baz": 3}
*** ../vim-8.1.1963/src/version.c 2019-09-01 23:27:02.142724494 +0200
--- src/version.c 2019-09-02 20:43:23.436925999 +0200
***************
*** 763,764 ****
--- 763,766 ----
{ /* Add new patch number below this line */
+ /**/
+ 1964,
/**/
--
hundred-and-one symptoms of being an internet addict:
168. You have your own domain name.
/// Bram Moolenaar -- [email protected] -- 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 ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/201909021846.x82IkSRN003338%40masaka.moolenaar.net.