diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-09-12 15:29:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-12 15:29:39 +0800 |
commit | 738c204523e4da07468268ae89741f2c86887031 (patch) | |
tree | e1acc84917bf6d932cff455c141c0eba4d4c9c1a /src/nvim/eval/typval.c | |
parent | f98cff9575e75a050d2bde01ad950c0c72bcfc3e (diff) | |
parent | 49aa9e17fa6f9b22550bff8f468c375ddf03fece (diff) | |
download | rneovim-738c204523e4da07468268ae89741f2c86887031.tar.gz rneovim-738c204523e4da07468268ae89741f2c86887031.tar.bz2 rneovim-738c204523e4da07468268ae89741f2c86887031.zip |
Merge pull request #20160 from zeertzjq/vim-8.2.2646
vim-patch:8.2.{2646,2664}: string argument type check
Diffstat (limited to 'src/nvim/eval/typval.c')
-rw-r--r-- | src/nvim/eval/typval.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index caba722e5b..c75d16e4fc 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -40,6 +40,11 @@ # include "eval/typval.c.generated.h" #endif +static char e_string_required_for_argument_nr[] + = N_("E1174: String required for argument %d"); +static char e_non_empty_string_required_for_argument_nr[] + = N_("E1142: Non-empty string required for argument %d"); + bool tv_in_free_unref_items = false; // TODO(ZyX-I): Remove DICT_MAXNEST, make users be non-recursive instead @@ -3800,26 +3805,26 @@ float_T tv_get_float(const typval_T *const tv) return 0; } -// Give an error and return FAIL unless "tv" is a string. -int tv_check_for_string(const typval_T *const tv) +/// Give an error and return FAIL unless "args[idx]" is a string. +int tv_check_for_string_arg(const typval_T *const args, const int idx) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { - if (tv->v_type != VAR_STRING) { - emsg(_(e_stringreq)); + if (args[idx].v_type != VAR_STRING) { + semsg(_(e_string_required_for_argument_nr), idx + 1); return FAIL; } return OK; } -// Give an error and return FAIL unless "tv" is a non-empty string. -int tv_check_for_nonempty_string(const typval_T *const tv) +/// Give an error and return FAIL unless "args[idx]" is a non-empty string. +int tv_check_for_nonempty_string_arg(const typval_T *const args, const int idx) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { - if (tv_check_for_string(tv) == FAIL) { + if (tv_check_for_string_arg(args, idx) == FAIL) { return FAIL; } - if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) { - emsg(_(e_non_empty_string_required)); + if (args[idx].vval.v_string == NULL || *args[idx].vval.v_string == NUL) { + semsg(_(e_non_empty_string_required_for_argument_nr), idx + 1); return FAIL; } return OK; |