From a764e73d4ffc5d046807c757eaacb9b0a5408152 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 25 Jul 2021 15:57:32 +0200 Subject: patch 8.2.3221: Vim9: argument types are not checked at compile time Problem: Vim9: argument types are not checked at compile time. Solution: Add several more type checks. (Yegappan Lakshmanan, closes #8632) --- src/testing.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/testing.c') diff --git a/src/testing.c b/src/testing.c index 9f3c29422..1da1c1cab 100644 --- a/src/testing.c +++ b/src/testing.c @@ -566,12 +566,23 @@ f_assert_exception(typval_T *argvars, typval_T *rettv) void f_assert_fails(typval_T *argvars, typval_T *rettv) { - char_u *cmd = tv_get_string_chk(&argvars[0]); + char_u *cmd; garray_T ga; int save_trylevel = trylevel; int called_emsg_before = called_emsg; char *wrong_arg_msg = NULL; + if (check_for_string_or_number_arg(argvars, 0) == FAIL + || check_for_opt_string_or_list_arg(argvars, 1) == FAIL + || (argvars[1].v_type != VAR_UNKNOWN + && (argvars[2].v_type != VAR_UNKNOWN + && (check_for_opt_number_arg(argvars, 3) == FAIL + || (argvars[3].v_type != VAR_UNKNOWN + && check_for_opt_string_arg(argvars, 4) == FAIL))))) + return; + + cmd = tv_get_string_chk(&argvars[0]); + // trylevel must be zero for a ":throw" command to be considered failed trylevel = 0; suppress_errthrow = TRUE; @@ -799,6 +810,12 @@ assert_inrange(typval_T *argvars) void f_assert_inrange(typval_T *argvars, typval_T *rettv) { + if (check_for_float_or_nr_arg(argvars, 0) == FAIL + || check_for_float_or_nr_arg(argvars, 1) == FAIL + || check_for_float_or_nr_arg(argvars, 2) == FAIL + || check_for_opt_string_arg(argvars, 3) == FAIL) + return; + rettv->vval.v_number = assert_inrange(argvars); } -- cgit v1.2.1