Skip to content

Commit c7f7f6d

Browse files
committed
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 #7249)
1 parent 64ffa9b commit c7f7f6d

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/testdir/test_vim9_expr.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,8 @@ def Test_expr7_dict()
19021902
var dictdict: dict<dict<string>> = #{one: #{a: 'text'}, two: #{}}
19031903
dictdict = #{one: #{}, two: #{a: 'text'}}
19041904
dictdict = #{one: #{}, two: #{}}
1905+
1906+
assert_equal({'': 0}, {matchstr('string', 'wont match'): 0})
19051907

19061908
CheckDefFailure(["var x = #{a:8}"], 'E1069:', 1)
19071909
CheckDefFailure(["var x = #{a : 8}"], 'E1068:', 1)

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
1952,
753755
/**/
754756
1951,
755757
/**/

src/vim9execute.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,7 @@ call_def_function(
17381738
int count = iptr->isn_arg.number;
17391739
dict_T *dict = dict_alloc();
17401740
dictitem_T *item;
1741+
char_u *key;
17411742

17421743
if (dict == NULL)
17431744
goto failed;
@@ -1746,15 +1747,17 @@ call_def_function(
17461747
// have already checked key type is VAR_STRING
17471748
tv = STACK_TV_BOT(2 * (idx - count));
17481749
// check key is unique
1749-
item = dict_find(dict, tv->vval.v_string, -1);
1750+
key = tv->vval.v_string == NULL
1751+
? (char_u *)"" : tv->vval.v_string;
1752+
item = dict_find(dict, key, -1);
17501753
if (item != NULL)
17511754
{
17521755
SOURCING_LNUM = iptr->isn_lnum;
1753-
semsg(_(e_duplicate_key), tv->vval.v_string);
1756+
semsg(_(e_duplicate_key), key);
17541757
dict_unref(dict);
17551758
goto on_error;
17561759
}
1757-
item = dictitem_alloc(tv->vval.v_string);
1760+
item = dictitem_alloc(key);
17581761
clear_tv(tv);
17591762
if (item == NULL)
17601763
{

0 commit comments

Comments
 (0)