Skip to content

Commit

Permalink
patch 8.2.3415: Vim9: not all function argument types are properly ch…
Browse files Browse the repository at this point in the history
…ecked

Problem:    Vim9: Not all function argument types are properly checked.
Solution:   Add and improve argument type checks. (Yegappan Lakshmanan,
            closes #8839)
  • Loading branch information
yegappan authored and brammool committed Sep 8, 2021
1 parent 80c88ea commit fc3b775
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/channel.c
Expand Up @@ -1309,7 +1309,7 @@ channel_open_func(typval_T *argvars)

if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_dict_arg(argvars, 1) == FAIL))
|| check_for_opt_dict_arg(argvars, 1) == FAIL))
return NULL;

address = tv_get_string(&argvars[0]);
Expand Down
4 changes: 2 additions & 2 deletions src/digraph.c
Expand Up @@ -2443,7 +2443,7 @@ f_digraph_getlist(typval_T *argvars, typval_T *rettv)
# ifdef FEAT_DIGRAPHS
int flag_list_all;

if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL)
if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL)
return;

if (argvars[0].v_type == VAR_UNKNOWN)
Expand Down Expand Up @@ -2475,7 +2475,7 @@ f_digraph_set(typval_T *argvars, typval_T *rettv)

if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_number_arg(argvars, 1) == FAIL))
|| check_for_string_arg(argvars, 1) == FAIL))
return;

if (!digraph_set_common(&argvars[0], &argvars[1]))
Expand Down
8 changes: 2 additions & 6 deletions src/evalfunc.c
Expand Up @@ -1305,9 +1305,9 @@ static funcentry_T global_functions[] =
ret_number, f_diff_hlID},
{"digraph_get", 1, 1, FEARG_1, arg1_string,
ret_string, f_digraph_get},
{"digraph_getlist",0, 1, FEARG_1, arg1_number,
{"digraph_getlist",0, 1, FEARG_1, arg1_bool,
ret_list_string_items, f_digraph_getlist},
{"digraph_set", 2, 2, FEARG_1, arg2_string_number,
{"digraph_set", 2, 2, FEARG_1, arg2_string,
ret_bool, f_digraph_set},
{"digraph_setlist",1, 1, FEARG_1, arg1_list_string,
ret_bool, f_digraph_setlist},
Expand Down Expand Up @@ -2954,8 +2954,6 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
error = TRUE;
if (argvars[1].v_type != VAR_UNKNOWN)
{
if (in_vim9script() && check_for_string_arg(argvars, 1) == FAIL)
return;
buttons = tv_get_string_buf_chk(&argvars[1], buf);
if (buttons == NULL)
error = TRUE;
Expand All @@ -2964,8 +2962,6 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
def = (int)tv_get_number_chk(&argvars[2], &error);
if (argvars[3].v_type != VAR_UNKNOWN)
{
if (in_vim9script() && check_for_string_arg(argvars, 3) == FAIL)
return;
typestr = tv_get_string_buf_chk(&argvars[3], buf2);
if (typestr == NULL)
error = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion src/terminal.c
Expand Up @@ -5663,7 +5663,7 @@ f_term_dumpload(typval_T *argvars, typval_T *rettv)
{
if (in_vim9script()
&& (check_for_string_arg(argvars, 0) == FAIL
|| check_for_dict_arg(argvars, 1) == FAIL))
|| check_for_opt_dict_arg(argvars, 1) == FAIL))
return;

term_load_dump(argvars, rettv, FALSE);
Expand Down
12 changes: 11 additions & 1 deletion src/testdir/test_digraph.vim
Expand Up @@ -536,6 +536,8 @@ func Test_digraph_set_function()
call assert_fails('call digraph_set("あ", "あ")', 'E1214: Digraph must be just two characters: あ')
call assert_fails('call digraph_set("aa", "ああ")', 'E1215: Digraph must be one character: ああ')
call assert_fails('call digraph_set("aa", "か" .. nr2char(0x3099))', 'E1215: Digraph must be one character: か' .. nr2char(0x3099))
call assert_fails('call digraph_set(test_null_string(), "い")', 'E1214: Digraph must be just two characters')
call assert_fails('call digraph_set("aa", 0z10)', 'E976: Using a Blob as a String')
bwipe!
endfunc

Expand All @@ -553,6 +555,8 @@ func Test_digraph_get_function()
call assert_equal('', digraph_get(' '))
call assert_fails('call digraph_get("aaa")', 'E1214: Digraph must be just two characters: aaa')
call assert_fails('call digraph_get("b")', 'E1214: Digraph must be just two characters: b')
call assert_fails('call digraph_get(test_null_string())', 'E1214: Digraph must be just two characters:')
call assert_fails('call digraph_get(0z10)', 'E976: Using a Blob as a String')
endfunc

func Test_digraph_get_function_encode()
Expand All @@ -576,8 +580,12 @@ func Test_digraph_setlist_function()
call assert_equal('', digraph_get('bb'))

call assert_fails('call digraph_setlist([[]])', 'E1216:')
call assert_fails('call digraph_setlist([["aa", "b", "cc"]])', '1216:')
call assert_fails('call digraph_setlist([["aa", "b", "cc"]])', 'E1216:')
call assert_fails('call digraph_setlist([["あ", "あ"]])', 'E1214: Digraph must be just two characters: あ')
call assert_fails('call digraph_setlist([test_null_list()])', 'E1216:')
call assert_fails('call digraph_setlist({})', 'E1216:')
call assert_fails('call digraph_setlist([{}])', 'E1216:')
call assert_true(digraph_setlist(test_null_list()))
endfunc

func Test_digraph_getlist_function()
Expand All @@ -592,6 +600,8 @@ func Test_digraph_getlist_function()
" of digraphs returned.
call assert_equal(digraph_getlist()->len(), digraph_getlist(0)->len())
call assert_notequal((digraph_getlist()->len()), digraph_getlist(1)->len())

call assert_fails('call digraph_getlist(0z12)', 'E974: Using a Blob as a Number')
endfunc


Expand Down

0 comments on commit fc3b775

Please sign in to comment.