Skip to content

Commit

Permalink
patch 9.0.1662: crash when using a class member twice
Browse files Browse the repository at this point in the history
Problem:    Crash when using a class member twice. (Christian J. Robinson)
Solution:   Make a copy of the value.
  • Loading branch information
brammool committed Jun 24, 2023
1 parent b46e0f3 commit 4e2406c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/testdir/test_vim9_class.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1662,
/**/
1661,
/**/
Expand Down
4 changes: 2 additions & 2 deletions src/vim9execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4e2406c

Please sign in to comment.