changeset 32547:feb9a581eb00 v9.0.1605

patch 9.0.1605: crash when calling method on super in child constructor Commit: https://github.com/vim/vim/commit/114ec813b3a7f70d7a1c86e87226f5273e9d1def Author: Ernie Rael <errael@raelity.com> Date: Sun Jun 4 18:11:35 2023 +0100 patch 9.0.1605: crash when calling method on super in child constructor Problem: Crash when calling method on super in child constructor. (Israel Chauca Fuentes) Solution: Clear the type list. (Ernie Rael, closes #12489, closes #12471)
author Bram Moolenaar <Bram@vim.org>
date Sun, 04 Jun 2023 19:15:03 +0200
parents 3f3e8b7ec2d5
children f9fe29a477a2
files src/testdir/test_vim9_class.vim src/userfunc.c src/version.c src/vim9class.c
diffstat 4 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_class.vim
+++ b/src/testdir/test_vim9_class.vim
@@ -1636,6 +1636,28 @@ def Test_using_base_class()
   END
   v9.CheckScriptSuccess(lines)
   unlet g:result
+
+  # Using super, Child invokes Base method which has optional arg. #12471
+  lines =<< trim END
+    vim9script
+
+    class Base
+        this.success: bool = false
+        def Method(arg = 0)
+            this.success = true
+        enddef
+    endclass
+
+    class Child extends Base
+        def new()
+            super.Method()
+        enddef
+    endclass
+
+    var obj = Child.new()
+    assert_equal(true, obj.success)
+  END
+  v9.CheckScriptSuccess(lines)
 enddef
 
 
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -5651,8 +5651,8 @@ copy_function(ufunc_T *fp)
     //    type_T	**uf_arg_types;
     //    type_T	*uf_ret_type;
 
-    ufunc->uf_type_list.ga_len = 0;
-    ufunc->uf_type_list.ga_data = NULL;
+    // make uf_type_list empty
+    ga_init(&ufunc->uf_type_list);
 
     // TODO:   partial_T	*uf_partial;
 
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1605,
+/**/
     1604,
 /**/
     1603,
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -1025,7 +1025,9 @@ early_ret:
 	    if (*fup == NULL)
 		goto cleanup;
 
-	    mch_memmove(*fup, gap->ga_data, sizeof(ufunc_T *) * gap->ga_len);
+	    if (gap->ga_len != 0)
+		mch_memmove(*fup, gap->ga_data,
+					      sizeof(ufunc_T *) * gap->ga_len);
 	    vim_free(gap->ga_data);
 	    if (loop == 1)
 		cl->class_class_function_count_child = gap->ga_len;