Skip to content

Commit

Permalink
patch 8.2.4774: crash when using a number for lambda name
Browse files Browse the repository at this point in the history
Problem:    Crash when using a number for lambda name.
Solution:   Check the type of the lambda reference.
  • Loading branch information
brammool committed Apr 17, 2022
1 parent a9549c9 commit 8b91e71
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/errors.h
Expand Up @@ -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
16 changes: 10 additions & 6 deletions src/eval.c
Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions src/testdir/test_lambda.vim
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -746,6 +746,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4774,
/**/
4773,
/**/
Expand Down

0 comments on commit 8b91e71

Please sign in to comment.