From 38059b4f31d8c9374002e209bc9ee2df28ac17fa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 14:03:32 +0800 Subject: vim-patch:8.2.2646: Vim9: error for not using string doesn't mention argument Problem: Vim9: error for not using string doesn't mention argument. Solution: Add argument number. https://github.com/vim/vim/commit/f28f2ac425600b88da0bdcc12a82cd620f575681 --- src/nvim/eval/funcs.c | 4 ++-- src/nvim/eval/typval.c | 27 ++++++++++++++++++++------- src/nvim/mbyte.c | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index b59caab34f..99dfa13d88 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1772,7 +1772,7 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv, EvalFuncData fptr /// "executable()" function static void f_executable(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (tv_check_for_string(&argvars[0]) == FAIL) { + if (tv_check_for_string(&argvars[0], 1) == FAIL) { return; } @@ -1901,7 +1901,7 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "exepath()" function static void f_exepath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (tv_check_for_nonempty_string(&argvars[0]) == FAIL) { + if (tv_check_for_nonempty_string(&argvars[0], 1) == FAIL) { return; } diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index caba722e5b..3bc3cdbd6b 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,34 @@ 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 "tv" is a string. +int tv_check_for_string(const typval_T *const tv, const int arg) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { if (tv->v_type != VAR_STRING) { - emsg(_(e_stringreq)); + if (arg > 0) { + semsg(_(e_string_required_for_argument_nr), arg); + } else { + emsg(_(e_stringreq)); + } 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 "tv" is a non-empty string. +int tv_check_for_nonempty_string(const typval_T *const tv, const int arg) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE { - if (tv_check_for_string(tv) == FAIL) { + if (tv_check_for_string(tv, arg) == FAIL) { return FAIL; } if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) { - emsg(_(e_non_empty_string_required)); + if (arg > 0) { + semsg(_(e_non_empty_string_required_for_argument_nr), arg); + } else { + emsg(_(e_non_empty_string_required)); + } return FAIL; } return OK; diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index dc74e23874..ebb5e2317b 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -2793,7 +2793,7 @@ void f_setcellwidths(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) void f_charclass(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (tv_check_for_string(&argvars[0]) == FAIL + if (tv_check_for_string(&argvars[0], 1) == FAIL || argvars[0].vval.v_string == NULL) { return; } -- cgit From 49aa9e17fa6f9b22550bff8f468c375ddf03fece Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 12 Sep 2022 14:08:51 +0800 Subject: vim-patch:8.2.2664: Vim9: not enough function arguments checked for string Problem: Vim9: not enough function arguments checked for string. Solution: Check in balloon functions. Refactor function arguments. https://github.com/vim/vim/commit/32105ae88f3aa6a6af30336f0bc9f8eb81292cd7 Cherry-pick removal of useless check from patch 8.2.3840. vim-patch:8.2.3083: crash when passing null string to charclass() Problem: Crash when passing null string to charclass(). Solution: Bail out when string pointer is NULL. (Christian Brabandt, closes vim/vim#8498, closes vim/vim#8260) https://github.com/vim/vim/commit/72463f883cdfd08e29ab0018ef3889284848d5f1 --- src/nvim/eval/funcs.c | 4 ++-- src/nvim/eval/typval.c | 26 +++++++++----------------- src/nvim/mbyte.c | 2 +- 3 files changed, 12 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 99dfa13d88..bff4361dcb 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -1772,7 +1772,7 @@ static void f_eventhandler(typval_T *argvars, typval_T *rettv, EvalFuncData fptr /// "executable()" function static void f_executable(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (tv_check_for_string(&argvars[0], 1) == FAIL) { + if (tv_check_for_string_arg(argvars, 0) == FAIL) { return; } @@ -1901,7 +1901,7 @@ static void f_win_execute(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "exepath()" function static void f_exepath(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (tv_check_for_nonempty_string(&argvars[0], 1) == FAIL) { + if (tv_check_for_nonempty_string_arg(argvars, 0) == FAIL) { return; } diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 3bc3cdbd6b..c75d16e4fc 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -3805,34 +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, const int arg) +/// 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) { - if (arg > 0) { - semsg(_(e_string_required_for_argument_nr), arg); - } else { - 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, const int arg) +/// 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, arg) == FAIL) { + if (tv_check_for_string_arg(args, idx) == FAIL) { return FAIL; } - if (tv->vval.v_string == NULL || *tv->vval.v_string == NUL) { - if (arg > 0) { - semsg(_(e_non_empty_string_required_for_argument_nr), arg); - } else { - 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; diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index ebb5e2317b..310ad05196 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -2793,7 +2793,7 @@ void f_setcellwidths(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) void f_charclass(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - if (tv_check_for_string(&argvars[0], 1) == FAIL + if (tv_check_for_string_arg(argvars, 0) == FAIL || argvars[0].vval.v_string == NULL) { return; } -- cgit