]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1662: crash when using a class member twice v9.0.1662
authorBram Moolenaar <Bram@vim.org>
Sat, 24 Jun 2023 18:22:21 +0000 (19:22 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 24 Jun 2023 18:22:21 +0000 (19:22 +0100)
Problem:    Crash when using a class member twice. (Christian J. Robinson)
Solution:   Make a copy of the value.

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

index 00b843206e2810cff43bd4254d39fb9abfaffb72..f1acdf38efcf009f56b69cf7342dbc0d8c44fe01 100644 (file)
@@ -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
index 437da6577e2d6ff284814eed3d2c0ed6e6806d90..8840b3acc65b0f07196a3734cf058affd7330b02 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1662,
 /**/
     1661,
 /**/
index 921e2ca0539682fd62b0f9280af15eacbdfab905..eb663a1096e54ddaa6c421122159cdcaf5005dac 100644 (file)
@@ -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;