]> granicus.if.org Git - vim/commitdiff
patch 8.2.1952: Vim9: crash when using a NULL dict key v8.2.1952
authorBram Moolenaar <Bram@vim.org>
Wed, 4 Nov 2020 12:38:28 +0000 (13:38 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 4 Nov 2020 12:38:28 +0000 (13:38 +0100)
Problem:    Vim9: crash when using a NULL dict key.
Solution:   Use a NULL dict key like an empty string. (closes #7249)

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

index 656718c49c4feafeda5b0521f85e1b89ded86a2f..2d741e495d5cbe2e98cca0da6870d233796177d6 100644 (file)
@@ -1902,6 +1902,8 @@ def Test_expr7_dict()
   var dictdict: dict<dict<string>> = #{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)
index d677744eed639dcb566043fa91a4b384914867e2..98a3ab1530e09857f45db30262917adc3d8b9b33 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1952,
 /**/
     1951,
 /**/
index 33027871a0be49a7d58a2583f59d83e1ef89aa5b..eb0e1db638822d5b8b816cd5f287a7c71bacaa28 100644 (file)
@@ -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)
                        {