diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-04-17 09:08:25 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-04-17 09:38:09 +0800 |
commit | 7a3f86481e96e5c30db5af74760e475bac8cc403 (patch) | |
tree | 32a6104e5d40df885d884bd72d20a0c9a54e1390 /src/nvim/eval/funcs.c | |
parent | 6bfba3660c5fbb22104cd87bd66a1381007fca22 (diff) | |
download | rneovim-7a3f86481e96e5c30db5af74760e475bac8cc403.tar.gz rneovim-7a3f86481e96e5c30db5af74760e475bac8cc403.tar.bz2 rneovim-7a3f86481e96e5c30db5af74760e475bac8cc403.zip |
vim-patch:9.0.0419: the :defer command does not check the function arguments
Problem: The :defer command does not check the function argument count and
types.
Solution: Check the function arguments when adding a deferred function.
https://github.com/vim/vim/commit/169003289fb4b2ad18fd7f5807e0d05efff0be85
Cherry-pick check_internal_func() from Vim, but use EvalFuncDef pointer
as first argument.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index f53b283c79..b064379210 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -228,6 +228,31 @@ const EvalFuncDef *find_internal_func(const char *const name) return index >= 0 ? &functions[index] : NULL; } +/// Check the argument count to use for internal function "fdef". +/// @return -1 for failure, 0 if no method base accepted, 1 if method base is +/// first argument, 2 if method base is second argument, etc. +int check_internal_func(const EvalFuncDef *const fdef, const int argcount) + FUNC_ATTR_NONNULL_ALL +{ + int res; + + if (argcount < fdef->min_argc) { + res = FCERR_TOOFEW; + } else if (argcount > fdef->max_argc) { + res = FCERR_TOOMANY; + } else { + return fdef->base_arg; + } + + const char *const name = fdef->name; + if (res == FCERR_TOOMANY) { + semsg(_(e_toomanyarg), name); + } else { + semsg(_(e_toofewarg), name); + } + return -1; +} + int call_internal_func(const char *const fname, const int argcount, typval_T *const argvars, typval_T *const rettv) FUNC_ATTR_NONNULL_ALL |