Skip to content

Commit 086fc9a

Browse files
committed
patch 8.2.1924: Vim9: crash when indexing dict with NULL key
Problem: Vim9: crash when indexing dict with NULL key. Solution: Use empty string instead of NULL. (closes #7229) Make error message more useful for empty string.
1 parent 4f6b6ed commit 086fc9a

4 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob"));
16991699
EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s"));
17001700
EXTERN char e_toofewarg[] INIT(= N_("E119: Not enough arguments for function: %s"));
17011701
EXTERN char e_func_deleted[] INIT(= N_("E933: Function was deleted: %s"));
1702-
EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s"));
1702+
EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: \"%s\""));
17031703
EXTERN char e_listreq[] INIT(= N_("E714: List required"));
17041704
EXTERN char e_listblobreq[] INIT(= N_("E897: List or Blob required"));
17051705
EXTERN char e_list_end[] INIT(= N_("E697: Missing end of List ']': %s"));

src/testdir/test_vim9_expr.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,7 @@ def Test_expr7_dict()
19171917
CheckDefExecFailure(['var x: dict<string> = #{a: "x", b: 134}'], 'E1012:', 1)
19181918

19191919
CheckDefFailure(['var x = ({'], 'E723:', 2)
1920+
CheckDefExecFailure(['{}[getftype("")]'], 'E716: Key not present in Dictionary: ""', 1)
19201921
enddef
19211922

19221923
def Test_expr7_dict_vim9script()

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+
1924,
753755
/**/
754756
1923,
755757
/**/

src/vim9execute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,6 +2607,8 @@ call_def_function(
26072607
tv = STACK_TV_BOT(-1);
26082608
// no need to check for VAR_STRING, 2STRING will check.
26092609
key = tv->vval.v_string;
2610+
if (key == NULL)
2611+
key = (char_u *)"";
26102612

26112613
if ((di = dict_find(dict, key, -1)) == NULL)
26122614
{

0 commit comments

Comments
 (0)