0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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.
This commit is contained in:
Bram Moolenaar
2023-06-24 19:22:21 +01:00
parent b46e0f3263
commit 4e2406c7a9
3 changed files with 21 additions and 2 deletions

View File

@@ -838,6 +838,23 @@ def Test_class_member()
END END
v9.CheckScriptSuccess(lines) 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 # access private member in lambda
lines =<< trim END lines =<< trim END
vim9script vim9script

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1662,
/**/ /**/
1661, 1661,
/**/ /**/

View File

@@ -3967,8 +3967,8 @@ exec_instructions(ectx_T *ectx)
if (GA_GROW_FAILS(&ectx->ec_stack, 1)) if (GA_GROW_FAILS(&ectx->ec_stack, 1))
goto theend; goto theend;
classmember_T *cm = &iptr->isn_arg.classmember; classmember_T *cm = &iptr->isn_arg.classmember;
*STACK_TV_BOT(0) = copy_tv(cm->cm_class->class_members_tv + cm->cm_idx,
cm->cm_class->class_members_tv[cm->cm_idx]; STACK_TV_BOT(0));
++ectx->ec_stack.ga_len; ++ectx->ec_stack.ga_len;
} }
break; break;