]> granicus.if.org Git - vim/commitdiff
patch 8.2.3974: Vim9: LISTAPPEND instruction does not check for a locked list v8.2.3974
authorBram Moolenaar <Bram@vim.org>
Sat, 1 Jan 2022 18:29:21 +0000 (18:29 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 1 Jan 2022 18:29:21 +0000 (18:29 +0000)
Problem:    Vim9: LISTAPPEND instruction does not check for a locked list.
Solution:   Check whether the list is locked. (closes #9452)

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

index 978ceb06851ec0fafeb7b608166d01b6c4a320b4..df9e8ec105597dd9fe01906b33783b74c6ceaf46 100644 (file)
@@ -78,6 +78,17 @@ enddef
 def Test_add()
   CheckDefAndScriptFailure(['add({}, 1)'], ['E1013: Argument 1: type mismatch, expected list<any> but got dict<unknown>', 'E1226: List or Blob required for argument 1'])
   CheckDefFailure(['add([1], "a")'], 'E1012: Type mismatch; expected number but got string')
+
+  var lines =<< trim END
+    vim9script
+    g:thelist = [1]
+    lockvar g:thelist
+    def TryChange()
+      g:thelist->add(2)
+    enddef
+    TryChange()
+  END
+  CheckScriptFailure(lines, 'E741:')
 enddef
 
 def Test_add_blob()
index 1fc6dac7249481ea3816b2bb3101fb7ac467bb58..12e236cac0149eff8bd03b64907c209a63a086b1 100644 (file)
@@ -749,6 +749,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3974,
 /**/
     3973,
 /**/
index a0b1fe417d98a9524ec3af7c669840e8e6394a5c..81f35787ce1ef1384c70195e6fd81297a3618a4a 100644 (file)
@@ -3911,12 +3911,14 @@ exec_instructions(ectx_T *ectx)
                    list_T      *l = tv1->vval.v_list;
 
                    // add an item to a list
+                   SOURCING_LNUM = iptr->isn_lnum;
                    if (l == NULL)
                    {
-                       SOURCING_LNUM = iptr->isn_lnum;
                        emsg(_(e_cannot_add_to_null_list));
                        goto on_error;
                    }
+                   if (value_check_lock(l->lv_lock, NULL, FALSE))
+                       goto on_error;
                    if (list_append_tv(l, tv2) == FAIL)
                        goto theend;
                    clear_tv(tv2);