summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-04-17 15:06:35 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-17 15:06:35 +0100
commit8b91e71441069b1dde9ac9ff9d9a829b1b4aecca (patch)
tree9b020a9e9ae446c5b11fb14399002fbcb5e99458
parenta9549c9e8f368a7fa1dcbe14ec23e82c6a0b8715 (diff)
downloadvim-git-8b91e71441069b1dde9ac9ff9d9a829b1b4aecca.tar.gz
patch 8.2.4774: crash when using a number for lambda namev8.2.4774
Problem: Crash when using a number for lambda name. Solution: Check the type of the lambda reference.
-rw-r--r--src/errors.h4
-rw-r--r--src/eval.c16
-rw-r--r--src/testdir/test_lambda.vim4
-rw-r--r--src/version.c2
4 files changed, 20 insertions, 6 deletions
diff --git a/src/errors.h b/src/errors.h
index b95644a10..0c6134034 100644
--- a/src/errors.h
+++ b/src/errors.h
@@ -3259,3 +3259,7 @@ EXTERN char e_nfa_regexp_missing_value_in_chr[]
INIT(= N_("E1273: (NFA regexp) missing value in '\\%%%c'"));
EXTERN char e_no_script_file_name_to_substitute_for_script[]
INIT(= N_("E1274: No script file name to substitute for \"<script>\""));
+#ifdef FEAT_EVAL
+EXTERN char e_string_or_function_required_for_arrow_parens_expr[]
+ INIT(= N_("E1275: String or function required for ->(expr)"));
+#endif
diff --git a/src/eval.c b/src/eval.c
index cad688775..61b09fb6b 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -4102,19 +4102,23 @@ eval_lambda(
++*arg;
ret = eval1(arg, rettv, evalarg);
*arg = skipwhite_and_linebreak(*arg, evalarg);
- if (**arg == ')')
+ if (**arg != ')')
{
- ++*arg;
+ emsg(_(e_missing_closing_paren));
+ return FAIL;
}
- else
+ if (rettv->v_type != VAR_STRING && rettv->v_type != VAR_FUNC
+ && rettv->v_type != VAR_PARTIAL)
{
- emsg(_(e_missing_closing_paren));
- ret = FAIL;
+ emsg(_(e_string_or_function_required_for_arrow_parens_expr));
+ return FAIL;
}
+ ++*arg;
}
if (ret != OK)
return FAIL;
- else if (**arg != '(')
+
+ if (**arg != '(')
{
if (verbose)
{
diff --git a/src/testdir/test_lambda.vim b/src/testdir/test_lambda.vim
index e6dcb6774..8d06e5973 100644
--- a/src/testdir/test_lambda.vim
+++ b/src/testdir/test_lambda.vim
@@ -66,6 +66,10 @@ function Test_lambda_fails()
echo assert_fails('echo 10->{a -> a + 2}', 'E107:')
call assert_fails('eval 0->(', "E110: Missing ')'")
+ call assert_fails('eval 0->(3)()', "E1275:")
+ call assert_fails('eval 0->([3])()', "E1275:")
+ call assert_fails('eval 0->({"a": 3})()', "E1275:")
+ call assert_fails('eval 0->(xxx)()', "E121:")
endfunc
func Test_not_lamda()
diff --git a/src/version.c b/src/version.c
index bdefc25f3..43e85e7a7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4774,
+/**/
4773,
/**/
4772,