# HG changeset patch # User Bram Moolenaar # Date 1604493905 -3600 # Node ID 96dbb61a54c2b0a29fa0c5061003927fb0fb47d2 # Parent 606ff2127ead3a9f30ed993ddee49e78f64e4e99 patch 8.2.1952: Vim9: crash when using a NULL dict key Commit: https://github.com/vim/vim/commit/c7f7f6db3e9d3b6b723ed17d5244c83859583832 Author: Bram Moolenaar Date: Wed Nov 4 13:38:28 2020 +0100 patch 8.2.1952: Vim9: crash when using a NULL dict key Problem: Vim9: crash when using a NULL dict key. Solution: Use a NULL dict key like an empty string. (closes https://github.com/vim/vim/issues/7249) diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -1902,6 +1902,8 @@ def Test_expr7_dict() var dictdict: dict> = #{one: #{a: 'text'}, two: #{}} dictdict = #{one: #{}, two: #{a: 'text'}} dictdict = #{one: #{}, two: #{}} + + assert_equal({'': 0}, {matchstr('string', 'wont match'): 0}) CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1) CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1952, +/**/ 1951, /**/ 1950, diff --git a/src/vim9execute.c b/src/vim9execute.c --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -1738,6 +1738,7 @@ call_def_function( int count = iptr->isn_arg.number; dict_T *dict = dict_alloc(); dictitem_T *item; + char_u *key; if (dict == NULL) goto failed; @@ -1746,15 +1747,17 @@ call_def_function( // have already checked key type is VAR_STRING tv = STACK_TV_BOT(2 * (idx - count)); // check key is unique - item = dict_find(dict, tv->vval.v_string, -1); + key = tv->vval.v_string == NULL + ? (char_u *)"" : tv->vval.v_string; + item = dict_find(dict, key, -1); if (item != NULL) { SOURCING_LNUM = iptr->isn_lnum; - semsg(_(e_duplicate_key), tv->vval.v_string); + semsg(_(e_duplicate_key), key); dict_unref(dict); goto on_error; } - item = dictitem_alloc(tv->vval.v_string); + item = dictitem_alloc(key); clear_tv(tv); if (item == NULL) {