Skip to content

Commit

Permalink
patch 9.0.1205: crash when handling class that extends another class
Browse files Browse the repository at this point in the history
Problem:    Crash when handling class that extends another class with more
            than one object members.
Solution:   Correct pointer computations. (closes vim#11824)
  • Loading branch information
brammool committed Jan 15, 2023
1 parent 912bfee commit ae3205a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
20 changes: 20 additions & 0 deletions src/testdir/test_vim9_class.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,26 @@ def Test_class_extends()
var c = Child.new()
END
v9.CheckScriptFailure(lines, 'E1325: Method not found on class "Child": new(')

# base class with more than one object member
lines =<< trim END
vim9script

class Result
this.success: bool
this.value: any = null
endclass

class Success extends Result
def new(this.value = v:none)
this.success = true
enddef
endclass

var v = Success.new('asdf')
assert_equal("object of Success {success: true, value: 'asdf'}", string(v))
END
v9.CheckScriptSuccess(lines)
enddef

def Test_class_import()
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 */
/**/
1205,
/**/
1204,
/**/
Expand Down
9 changes: 5 additions & 4 deletions src/vim9class.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ add_members_to_class(
for (int i = 0; i < parent_count; ++i)
{
// parent members need to be copied
*members[i] = parent_members[i];
members[i]->ocm_name = vim_strsave(members[i]->ocm_name);
if (members[i]->ocm_init != NULL)
members[i]->ocm_init = vim_strsave(members[i]->ocm_init);
ocmember_T *m = *members + i;
*m = parent_members[i];
m->ocm_name = vim_strsave(m->ocm_name);
if (m->ocm_init != NULL)
m->ocm_init = vim_strsave(m->ocm_init);
}
if (gap->ga_len > 0)
// new members are moved
Expand Down

0 comments on commit ae3205a

Please sign in to comment.