Skip to content

Commit

Permalink
patch 9.0.1701: vim9 crash when class member overridden
Browse files Browse the repository at this point in the history
Problem: vim9 crash when class member overridden
Solution: Use method_count field instead

closes: #12676
closes: #12677

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
  • Loading branch information
yegappan authored and chrisbra committed Aug 13, 2023
1 parent 32f586e commit 57a02cc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
38 changes: 38 additions & 0 deletions src/testdir/test_vim9_class.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1874,5 +1874,43 @@ def Test_defer_with_object()
unlet g:result
enddef

" The following test used to crash Vim (Github issue #12676)
def Test_extends_method_crashes_vim()
var lines =<< trim END
vim9script

class Observer
endclass

class Property
this.value: any

def Set(v: any)
if v != this.value
this.value = v
endif
enddef

def Register(observer: Observer)
enddef
endclass

class Bool extends Property
this.value: bool
endclass

def Observe(obj: Property, who: Observer)
obj.Register(who)
enddef

var p = Bool.new(false)
var myObserver = Observer.new()

Observe(p, myObserver)

p.Set(true)
END
v9.CheckScriptSuccess(lines)
enddef

" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
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 */
/**/
1701,
/**/
1700,
/**/
Expand Down
2 changes: 1 addition & 1 deletion src/vim9class.c
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ ex_class(exarg_T *eap)
if (!done && extends_cl != NULL)
{
for (int cl_i = 0;
cl_i < extends_cl->class_obj_member_count; ++cl_i)
cl_i < extends_cl->class_obj_method_count; ++cl_i)
{
if (STRCMP(ifcl->class_obj_methods[if_i]->uf_name,
extends_cl->class_obj_methods[cl_i]->uf_name)
Expand Down

0 comments on commit 57a02cc

Please sign in to comment.