From: Bram Moolenaar Date: Fri, 30 Oct 2020 17:33:02 +0000 (+0100) Subject: patch 8.2.1924: Vim9: crash when indexing dict with NULL key X-Git-Tag: v8.2.1924 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=086fc9a585afa4317046fa0a36c7b896286e5128;p=vim 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. --- diff --git a/src/globals.h b/src/globals.h index 5bdbad636..379a532fa 100644 --- a/src/globals.h +++ b/src/globals.h @@ -1699,7 +1699,7 @@ EXTERN char e_invalblob[] INIT(= N_("E978: Invalid operation for Blob")); EXTERN char e_toomanyarg[] INIT(= N_("E118: Too many arguments for function: %s")); EXTERN char e_toofewarg[] INIT(= N_("E119: Not enough arguments for function: %s")); EXTERN char e_func_deleted[] INIT(= N_("E933: Function was deleted: %s")); -EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: %s")); +EXTERN char e_dictkey[] INIT(= N_("E716: Key not present in Dictionary: \"%s\"")); EXTERN char e_listreq[] INIT(= N_("E714: List required")); EXTERN char e_listblobreq[] INIT(= N_("E897: List or Blob required")); EXTERN char e_list_end[] INIT(= N_("E697: Missing end of List ']': %s")); diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index 568c3bf6a..8f691e6b4 100644 --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -1917,6 +1917,7 @@ def Test_expr7_dict() CheckDefExecFailure(['var x: dict = #{a: "x", b: 134}'], 'E1012:', 1) CheckDefFailure(['var x = ({'], 'E723:', 2) + CheckDefExecFailure(['{}[getftype("")]'], 'E716: Key not present in Dictionary: ""', 1) enddef def Test_expr7_dict_vim9script() diff --git a/src/version.c b/src/version.c index 52d868398..0da78888b 100644 --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1924, /**/ 1923, /**/ diff --git a/src/vim9execute.c b/src/vim9execute.c index 09eb6c221..9c4665193 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2607,6 +2607,8 @@ call_def_function( tv = STACK_TV_BOT(-1); // no need to check for VAR_STRING, 2STRING will check. key = tv->vval.v_string; + if (key == NULL) + key = (char_u *)""; if ((di = dict_find(dict, key, -1)) == NULL) {