]> granicus.if.org Git - vim/commitdiff
patch 8.2.2549: crash after using "g:" in a for loop v8.2.2549
authorBram Moolenaar <Bram@vim.org>
Wed, 24 Feb 2021 11:27:31 +0000 (12:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 24 Feb 2021 11:27:31 +0000 (12:27 +0100)
Problem:    Crash after using "g:" in a for loop.
Solution:   Increment the reference count. (closes #7892)

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

index 3e69a0dd460a60eade2cdf953d43f1e8e10ac456..cda1ffdb4f58b13a170c0df9657093178de39715 100644 (file)
@@ -2545,6 +2545,12 @@ def Test_expr7_namespace()
   assert_equal('some', get(t:, 'some_var', 'xxx'))
   assert_equal('xxx', get(t:, 'no_var', 'xxx'))
   unlet t:some_var
+
+  # check using g: in a for loop more than DO_NOT_FREE_CNT times
+  for i in range(100000)
+    if has_key(g:, 'does-not-exist')
+    endif
+  endfor
 enddef
 
 def Test_expr7_parens()
index 3d52e4967c8d7b28f94a3596f4071a2b9d6b785b..ff82645516f5047d4a33bb6953f6c7190699cb9e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2549,
 /**/
     2548,
 /**/
index 232f0471ea50b227046f1324b31b3dbfd9c1f3d3..e20c71105d53fd583aa1f7f691542ff3316c8afc 100644 (file)
@@ -1771,6 +1771,7 @@ call_def_function(
                    tv->v_type = VAR_DICT;
                    tv->v_lock = 0;
                    tv->vval.v_dict = d;
+                   ++d->dv_refcount;
                    ++ectx.ec_stack.ga_len;
                }
                break;