Skip to content

Commit ae3205a

Browse files
committed
patch 9.0.1205: crash when handling class that extends another class
Problem: Crash when handling class that extends another class with more than one object members. Solution: Correct pointer computations. (closes #11824)
1 parent 912bfee commit ae3205a

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/testdir/test_vim9_class.vim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,26 @@ def Test_class_extends()
10811081
var c = Child.new()
10821082
END
10831083
v9.CheckScriptFailure(lines, 'E1325: Method not found on class "Child": new(')
1084+
1085+
# base class with more than one object member
1086+
lines =<< trim END
1087+
vim9script
1088+
1089+
class Result
1090+
this.success: bool
1091+
this.value: any = null
1092+
endclass
1093+
1094+
class Success extends Result
1095+
def new(this.value = v:none)
1096+
this.success = true
1097+
enddef
1098+
endclass
1099+
1100+
var v = Success.new('asdf')
1101+
assert_equal("object of Success {success: true, value: 'asdf'}", string(v))
1102+
END
1103+
v9.CheckScriptSuccess(lines)
10841104
enddef
10851105

10861106
def Test_class_import()

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+
1205,
698700
/**/
699701
1204,
700702
/**/

src/vim9class.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ add_members_to_class(
182182
for (int i = 0; i < parent_count; ++i)
183183
{
184184
// parent members need to be copied
185-
*members[i] = parent_members[i];
186-
members[i]->ocm_name = vim_strsave(members[i]->ocm_name);
187-
if (members[i]->ocm_init != NULL)
188-
members[i]->ocm_init = vim_strsave(members[i]->ocm_init);
185+
ocmember_T *m = *members + i;
186+
*m = parent_members[i];
187+
m->ocm_name = vim_strsave(m->ocm_name);
188+
if (m->ocm_init != NULL)
189+
m->ocm_init = vim_strsave(m->ocm_init);
189190
}
190191
if (gap->ga_len > 0)
191192
// new members are moved

0 commit comments

Comments
 (0)