diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-07-31 14:11:58 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-07-31 14:11:58 +0200 |
commit | b54c3ff3174dbb5dfbfcabdf95200b047beaa644 (patch) | |
tree | a230032c07f9373c65ca64e4b9c237e70b4d6a54 /src/userfunc.c | |
parent | fc1f2015e833e69b89b994faf4b2c4fc1e09220f (diff) | |
download | vim-git-b54c3ff3174dbb5dfbfcabdf95200b047beaa644.tar.gz |
patch 7.4.2134v7.4.2134
Problem: No error for using function() badly.
Solution: Check for passing wrong function name. (Ken Takata)
Diffstat (limited to 'src/userfunc.c')
-rw-r--r-- | src/userfunc.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/userfunc.c b/src/userfunc.c index 0c6c613e3..3c6401f7d 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -295,7 +295,7 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate) if (ret == FAIL || **arg != '>') goto errret; - /* Set up dictionaries for checking local variables and arguments. */ + /* Set up a flag for checking local variables and arguments. */ if (evaluate) eval_lavars_used = &eval_lavars; @@ -1504,6 +1504,7 @@ list_func_head(ufunc_T *fp, int indent) * TFN_INT: internal function name OK * TFN_QUIET: be quiet * TFN_NO_AUTOLOAD: do not use script autoloading + * TFN_NO_DEREF: do not dereference a Funcref * Advances "pp" to just after the function name (if no error). */ static char_u * @@ -1618,7 +1619,7 @@ trans_function_name( if (name == lv.ll_exp_name) name = NULL; } - else + else if (!(flags & TFN_NO_DEREF)) { len = (int)(end - *pp); name = deref_func_name(*pp, &len, partial, flags & TFN_NO_AUTOLOAD); @@ -1690,7 +1691,7 @@ trans_function_name( start); goto theend; } - if (!skip && !(flags & TFN_QUIET)) + if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF)) { char_u *cp = vim_strchr(lv.ll_name, ':'); @@ -2381,16 +2382,20 @@ translated_function_exists(char_u *name) /* * Return TRUE if a function "name" exists. + * If "no_defef" is TRUE, do not dereference a Funcref. */ int -function_exists(char_u *name) +function_exists(char_u *name, int no_deref) { char_u *nm = name; char_u *p; int n = FALSE; + int flag; - p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET|TFN_NO_AUTOLOAD, - NULL, NULL); + flag = TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD; + if (no_deref) + flag |= TFN_NO_DEREF; + p = trans_function_name(&nm, FALSE, flag, NULL, NULL); nm = skipwhite(nm); /* Only accept "funcname", "funcname ", "funcname (..." and |