Skip to content

Commit 4e2406c

Browse files
committed
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.
1 parent b46e0f3 commit 4e2406c

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/testdir/test_vim9_class.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,23 @@ def Test_class_member()
838838
END
839839
v9.CheckScriptSuccess(lines)
840840

841+
# using static class member twice
842+
lines =<< trim END
843+
vim9script
844+
845+
class HTML
846+
static author: string = 'John Doe'
847+
848+
static def MacroSubstitute(s: string): string
849+
return substitute(s, '{{author}}', author, 'gi')
850+
enddef
851+
endclass
852+
853+
assert_equal('some text', HTML.MacroSubstitute('some text'))
854+
assert_equal('some text', HTML.MacroSubstitute('some text'))
855+
END
856+
v9.CheckScriptSuccess(lines)
857+
841858
# access private member in lambda
842859
lines =<< trim END
843860
vim9script

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1662,
698700
/**/
699701
1661,
700702
/**/

src/vim9execute.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3967,8 +3967,8 @@ exec_instructions(ectx_T *ectx)
39673967
if (GA_GROW_FAILS(&ectx->ec_stack, 1))
39683968
goto theend;
39693969
classmember_T *cm = &iptr->isn_arg.classmember;
3970-
*STACK_TV_BOT(0) =
3971-
cm->cm_class->class_members_tv[cm->cm_idx];
3970+
copy_tv(cm->cm_class->class_members_tv + cm->cm_idx,
3971+
STACK_TV_BOT(0));
39723972
++ectx->ec_stack.ga_len;
39733973
}
39743974
break;

0 commit comments

Comments
 (0)