Patch 8.2.1201

5 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 13, 2020, 12:56:57 PM7/13/20
to vim...@googlegroups.com

Patch 8.2.1201
Problem: Vim9: crash when passing number as dict key.
Solution: Check key type to be string. (closes #6449)
Files: src/vim9compile.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.1200/src/vim9compile.c 2020-07-12 17:31:05.574115558 +0200
--- src/vim9compile.c 2020-07-13 18:26:27.106287071 +0200
***************
*** 3212,3217 ****
--- 3212,3218 ----
compile_dict(char_u **arg, cctx_T *cctx, int literal)
{
garray_T *instr = &cctx->ctx_instr;
+ garray_T *stack = &cctx->ctx_type_stack;
int count = 0;
dict_T *d = dict_alloc();
dictitem_T *item;
***************
*** 3254,3263 ****

if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
- // TODO: check type is string
isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
if (isn->isn_type == ISN_PUSHS)
key = isn->isn_arg.string;
}

// Check for duplicate keys, if using string keys.
--- 3255,3270 ----

if (compile_expr0(arg, cctx) == FAIL)
return FAIL;
isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
if (isn->isn_type == ISN_PUSHS)
key = isn->isn_arg.string;
+ else
+ {
+ type_T *keytype = ((type_T **)stack->ga_data)
+ [stack->ga_len - 1];
+ if (need_type(keytype, &t_string, -1, cctx, FALSE) == FAIL)
+ return FAIL;
+ }
}

// Check for duplicate keys, if using string keys.
*** ../vim-8.2.1200/src/testdir/test_vim9_func.vim 2020-07-12 17:31:05.574115558 +0200
--- src/testdir/test_vim9_func.vim 2020-07-13 18:53:47.669419801 +0200
***************
*** 954,959 ****
--- 954,967 ----
assert_equal(6, res)
enddef

+ def Wrong_dict_key_type(items: list<number>): list<number>
+ return filter(items, {_, val -> get({val: 1}, 'x')})
+ enddef
+
+ def Test_wrong_dict_key_type()
+ assert_fails('Wrong_dict_key_type([1, 2, 3])', 'E1029:')
+ enddef
+
def Line_continuation_in_def(dir: string = ''): string
let path: string = empty(dir)
\ ? 'empty'
*** ../vim-8.2.1200/src/version.c 2020-07-13 18:17:53.279714725 +0200
--- src/version.c 2020-07-13 18:55:02.457198044 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1201,
/**/

--
Q: What is the difference between open-source and commercial software?
A: If you have a problem with commercial software you can call a phone
number and they will tell you it might be solved in a future version.
For open-source software there isn't a phone number to call, but you
get the solution within a day.

/// Bram Moolenaar -- Br...@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 ///
Reply all
Reply to author
Forward
0 new messages