]> granicus.if.org Git - vim/commitdiff
patch 8.2.1924: Vim9: crash when indexing dict with NULL key v8.2.1924
authorBram Moolenaar <Bram@vim.org>
Fri, 30 Oct 2020 17:33:02 +0000 (18:33 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 30 Oct 2020 17:33:02 +0000 (18:33 +0100)
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.

src/globals.h
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9execute.c

index 5bdbad636fb1e2a910f88a54f633bdfa47ff1cc1..379a532fac03663c7601372a2066fd4aeb8a0b95 100644 (file)
@@ -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"));
index 568c3bf6a4a7417ff696bf9b7c9f20b93050a94a..8f691e6b47453ea97c4dadc1e20947b4d34dedae 100644 (file)
@@ -1917,6 +1917,7 @@ def Test_expr7_dict()
   CheckDefExecFailure(['var x: dict<string> = #{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()
index 52d868398466e083fffeeaec6b7e33309f6ff6ed..0da78888bd06aee56b6e25df6d7221b7b3ba3bff 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1924,
 /**/
     1923,
 /**/
index 09eb6c2210ebf515e599d11d72fe1f7cdee3808a..9c4665193819072b555f1c43bf37c7b7c095b6b3 100644 (file)
@@ -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)
                    {