]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1605: crash when calling method on super in child constructor v9.0.1605
authorErnie Rael <errael@raelity.com>
Sun, 4 Jun 2023 17:11:35 +0000 (18:11 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 4 Jun 2023 17:11:35 +0000 (18:11 +0100)
Problem:    Crash when calling method on super in child constructor. (Israel
            Chauca Fuentes)
Solution:   Clear the type list. (Ernie Rael, closes #12489, closes #12471)

src/testdir/test_vim9_class.vim
src/userfunc.c
src/version.c
src/vim9class.c

index d89b14ea7423357acee08e90ab42b0470055f55d..52812eac73896b2c1639391afb0dd1102ca86593 100644 (file)
@@ -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
 
 
index c30c3524bd68fca99113dd10162b7a161deec65a..8facd2fdfd238e943479726d378d95297cfa69d7 100644 (file)
@@ -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;
 
index c9a4febe014de9c29411e7e944a8aedb6282f494..335e3bd705b2f67759986a40ca1a529f18d2ff1d 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1605,
 /**/
     1604,
 /**/
index 062de8fad4fc2db3087468039e61e0a459a5af4a..734967a8029383f7562b248b57cece4d4b336827 100644 (file)
@@ -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;