summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-05-22 13:45:52 +0100
committerBram Moolenaar <Bram@vim.org>2022-05-22 13:45:52 +0100
commitbce69d65dd41020ea1d727337a3baf9e95b40c35 (patch)
tree63ac7567a44b3dbe4677d781076118283893c66e
parent37233f6022b3ed16985a91d22752b3ca162e21d0 (diff)
patch 8.2.4998: Vim9: crash when using multiple funcref()v8.2.4998
Problem: Vim9: crash when using multiple funcref(). Solution: Check if varargs type is NULL. (closes #10467)
-rw-r--r--src/testdir/test_vim9_func.vim41
-rw-r--r--src/version.c2
-rw-r--r--src/vim9type.c6
3 files changed, 48 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 30ff1ef236..fcf37d5f51 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index 5ae7693c5a..b18d0a5112 100644
--- a/src/version.c
+++ b/src/version.c
@@ -735,6 +735,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4998,
+/**/
4997,
/**/
4996,
diff --git a/src/vim9type.c b/src/vim9type.c
index 180876223a..436feda514 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -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)