changeset 32661:9ae1bdff8457 v9.0.1662

patch 9.0.1662: crash when using a class member twice Commit: https://github.com/vim/vim/commit/4e2406c7a9d5f7f03faec8c42fac15c192fb59b0 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jun 24 19:22:21 2023 +0100 patch 9.0.1662: crash when using a class member twice Problem: Crash when using a class member twice. (Christian J. Robinson) Solution: Make a copy of the value.
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Jun 2023 20:30:04 +0200
parents 14298ba478dc
children bed7285e0bb3
files src/testdir/test_vim9_class.vim src/version.c src/vim9execute.c
diffstat 3 files changed, 21 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -838,6 +838,23 @@ def Test_class_member()
   END
   v9.CheckScriptSuccess(lines)
 
+  # using static class member twice
+  lines =<< trim END
+      vim9script
+
+      class HTML
+        static author: string = 'John Doe'
+
+        static def MacroSubstitute(s: string): string
+          return substitute(s, '{{author}}', author, 'gi')
+        enddef
+      endclass
+
+      assert_equal('some text', HTML.MacroSubstitute('some text'))
+      assert_equal('some text', HTML.MacroSubstitute('some text'))
+  END
+  v9.CheckScriptSuccess(lines)
+
   # access private member in lambda
   lines =<< trim END
       vim9script
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1662,
+/**/
     1661,
 /**/
     1660,
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -3967,8 +3967,8 @@ exec_instructions(ectx_T *ectx)
 		    if (GA_GROW_FAILS(&ectx->ec_stack, 1))
 			goto theend;
 		    classmember_T *cm = &iptr->isn_arg.classmember;
-		    *STACK_TV_BOT(0) =
-				    cm->cm_class->class_members_tv[cm->cm_idx];
+		    copy_tv(cm->cm_class->class_members_tv + cm->cm_idx,
+							      STACK_TV_BOT(0));
 		    ++ectx->ec_stack.ga_len;
 		}
 		break;