]> granicus.if.org Git - vim/commitdiff
patch 8.2.4998: Vim9: crash when using multiple funcref() v8.2.4998
authorBram Moolenaar <Bram@vim.org>
Sun, 22 May 2022 12:45:52 +0000 (13:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 22 May 2022 12:45:52 +0000 (13:45 +0100)
Problem:    Vim9: crash when using multiple funcref().
Solution:   Check if varargs type is NULL. (closes #10467)

src/testdir/test_vim9_func.vim
src/version.c
src/vim9type.c

index 30ff1ef236e95e1584fe74fa56e21cfe9c96a608..fcf37d5f51f3e1ec2bb71e7b40613595483873b6 100644 (file)
@@ -4107,6 +4107,47 @@ func Test_lambda_allocation_failure()
   bw!
 endfunc
 
+def Test_multiple_funcref()
+  # This was using a NULL pointer
+  var lines =<< trim END
+      vim9script
+      def A(F: func, ...args: list<any>): func
+          return funcref(F, args)
+      enddef
+
+      def B(F: func): func
+          return funcref(A, [F])
+      enddef
+
+      def Test(n: number)
+      enddef
+
+      const X = B(Test)
+      X(1)
+  END
+  v9.CheckScriptSuccess(lines)
+
+  # slightly different case
+  lines =<< trim END
+      vim9script
+
+      def A(F: func, ...args: list<any>): any
+          return call(F, args)
+      enddef
+
+      def B(F: func): func
+          return funcref(A, [F])
+      enddef
+
+      def Test(n: number)
+      enddef
+
+      const X = B(Test)
+      X(1)
+  END
+  v9.CheckScriptSuccess(lines)
+enddef
+
 " The following messes up syntax highlight, keep near the end.
 if has('python3')
   def Test_python3_command()
index 5ae7693c5ae21c1ebc084d52bdc3a14aa9790519..b18d0a5112b79c29ff90b29eb808cee6b0865e7d 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4998,
 /**/
     4997,
 /**/
index 180876223a2761dcea89d42b569fd08a10285d0a..436feda514fa8777e2777a083c6b513154cab847 100644 (file)
@@ -807,7 +807,11 @@ check_argument_types(
        else
            tv = &argvars[i];
        if (varargs && i >= type->tt_argcount - 1)
-           expected = type->tt_args[type->tt_argcount - 1]->tt_member;
+       {
+           expected = type->tt_args[type->tt_argcount - 1];
+           if (expected != NULL)
+               expected = expected->tt_member;
+       }
        else
            expected = type->tt_args[i];
        if (check_typval_arg_type(expected, tv, NULL, i + 1) == FAIL)