Skip to content

Commit fc3b775

Browse files
yegappanbrammool
authored andcommitted
patch 8.2.3415: Vim9: not all function argument types are properly checked
Problem: Vim9: Not all function argument types are properly checked. Solution: Add and improve argument type checks. (Yegappan Lakshmanan, closes #8839)
1 parent 80c88ea commit fc3b775

File tree

7 files changed

+115
-13
lines changed

7 files changed

+115
-13
lines changed

src/channel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ channel_open_func(typval_T *argvars)
13091309

13101310
if (in_vim9script()
13111311
&& (check_for_string_arg(argvars, 0) == FAIL
1312-
|| check_for_dict_arg(argvars, 1) == FAIL))
1312+
|| check_for_opt_dict_arg(argvars, 1) == FAIL))
13131313
return NULL;
13141314

13151315
address = tv_get_string(&argvars[0]);

src/digraph.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ f_digraph_getlist(typval_T *argvars, typval_T *rettv)
24432443
# ifdef FEAT_DIGRAPHS
24442444
int flag_list_all;
24452445

2446-
if (in_vim9script() && check_for_opt_number_arg(argvars, 0) == FAIL)
2446+
if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL)
24472447
return;
24482448

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

24762476
if (in_vim9script()
24772477
&& (check_for_string_arg(argvars, 0) == FAIL
2478-
|| check_for_number_arg(argvars, 1) == FAIL))
2478+
|| check_for_string_arg(argvars, 1) == FAIL))
24792479
return;
24802480

24812481
if (!digraph_set_common(&argvars[0], &argvars[1]))

src/evalfunc.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,9 @@ static funcentry_T global_functions[] =
13051305
ret_number, f_diff_hlID},
13061306
{"digraph_get", 1, 1, FEARG_1, arg1_string,
13071307
ret_string, f_digraph_get},
1308-
{"digraph_getlist",0, 1, FEARG_1, arg1_number,
1308+
{"digraph_getlist",0, 1, FEARG_1, arg1_bool,
13091309
ret_list_string_items, f_digraph_getlist},
1310-
{"digraph_set", 2, 2, FEARG_1, arg2_string_number,
1310+
{"digraph_set", 2, 2, FEARG_1, arg2_string,
13111311
ret_bool, f_digraph_set},
13121312
{"digraph_setlist",1, 1, FEARG_1, arg1_list_string,
13131313
ret_bool, f_digraph_setlist},
@@ -2954,8 +2954,6 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
29542954
error = TRUE;
29552955
if (argvars[1].v_type != VAR_UNKNOWN)
29562956
{
2957-
if (in_vim9script() && check_for_string_arg(argvars, 1) == FAIL)
2958-
return;
29592957
buttons = tv_get_string_buf_chk(&argvars[1], buf);
29602958
if (buttons == NULL)
29612959
error = TRUE;
@@ -2964,8 +2962,6 @@ f_confirm(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
29642962
def = (int)tv_get_number_chk(&argvars[2], &error);
29652963
if (argvars[3].v_type != VAR_UNKNOWN)
29662964
{
2967-
if (in_vim9script() && check_for_string_arg(argvars, 3) == FAIL)
2968-
return;
29692965
typestr = tv_get_string_buf_chk(&argvars[3], buf2);
29702966
if (typestr == NULL)
29712967
error = TRUE;

src/terminal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5663,7 +5663,7 @@ f_term_dumpload(typval_T *argvars, typval_T *rettv)
56635663
{
56645664
if (in_vim9script()
56655665
&& (check_for_string_arg(argvars, 0) == FAIL
5666-
|| check_for_dict_arg(argvars, 1) == FAIL))
5666+
|| check_for_opt_dict_arg(argvars, 1) == FAIL))
56675667
return;
56685668

56695669
term_load_dump(argvars, rettv, FALSE);

src/testdir/test_digraph.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ func Test_digraph_set_function()
536536
call assert_fails('call digraph_set("あ", "あ")', 'E1214: Digraph must be just two characters: あ')
537537
call assert_fails('call digraph_set("aa", "ああ")', 'E1215: Digraph must be one character: ああ')
538538
call assert_fails('call digraph_set("aa", "か" .. nr2char(0x3099))', 'E1215: Digraph must be one character: か' .. nr2char(0x3099))
539+
call assert_fails('call digraph_set(test_null_string(), "い")', 'E1214: Digraph must be just two characters')
540+
call assert_fails('call digraph_set("aa", 0z10)', 'E976: Using a Blob as a String')
539541
bwipe!
540542
endfunc
541543

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

558562
func Test_digraph_get_function_encode()
@@ -576,8 +580,12 @@ func Test_digraph_setlist_function()
576580
call assert_equal('', digraph_get('bb'))
577581

578582
call assert_fails('call digraph_setlist([[]])', 'E1216:')
579-
call assert_fails('call digraph_setlist([["aa", "b", "cc"]])', '1216:')
583+
call assert_fails('call digraph_setlist([["aa", "b", "cc"]])', 'E1216:')
580584
call assert_fails('call digraph_setlist([["あ", "あ"]])', 'E1214: Digraph must be just two characters: あ')
585+
call assert_fails('call digraph_setlist([test_null_list()])', 'E1216:')
586+
call assert_fails('call digraph_setlist({})', 'E1216:')
587+
call assert_fails('call digraph_setlist([{}])', 'E1216:')
588+
call assert_true(digraph_setlist(test_null_list()))
581589
endfunc
582590

583591
func Test_digraph_getlist_function()
@@ -592,6 +600,8 @@ func Test_digraph_getlist_function()
592600
" of digraphs returned.
593601
call assert_equal(digraph_getlist()->len(), digraph_getlist(0)->len())
594602
call assert_notequal((digraph_getlist()->len()), digraph_getlist(1)->len())
603+
604+
call assert_fails('call digraph_getlist(0z12)', 'E974: Using a Blob as a Number')
595605
endfunc
596606

597607

0 commit comments

Comments
 (0)