diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-05-08 22:49:53 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-05-08 22:53:43 +0800 |
commit | 625926f729137658d0a8a73a55aeefc5583488c3 (patch) | |
tree | 423d42842b90afa924266ba1a037fd91102fcce4 | |
parent | d745433817499c34ccf230469417fb0ea29b7ab9 (diff) | |
download | rneovim-625926f729137658d0a8a73a55aeefc5583488c3.tar.gz rneovim-625926f729137658d0a8a73a55aeefc5583488c3.tar.bz2 rneovim-625926f729137658d0a8a73a55aeefc5583488c3.zip |
vim-patch:9.0.1524: passing -1 for bool is not always rejected
Problem: Passing -1 for bool is not always rejected.
Solution: Check for error in a better way. (closes vim/vim#12358)
https://github.com/vim/vim/commit/8cf51376b842e0060edf08bd2e5bd9933c552ecf
-rw-r--r-- | src/nvim/strings.c | 36 | ||||
-rw-r--r-- | test/old/testdir/test_expr.vim | 3 | ||||
-rw-r--r-- | test/old/testdir/test_functions.vim | 3 | ||||
-rw-r--r-- | test/old/testdir/test_utf8.vim | 6 |
4 files changed, 29 insertions, 19 deletions
diff --git a/src/nvim/strings.c b/src/nvim/strings.c index acbff51e49..4e521b14f7 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1515,11 +1515,13 @@ static void byteidx_common(typval_T *argvars, typval_T *rettv, int comp) varnumber_T utf16idx = false; if (argvars[2].v_type != VAR_UNKNOWN) { - utf16idx = tv_get_bool(&argvars[2]); + bool error = false; + utf16idx = tv_get_bool_chk(&argvars[2], &error); + if (error) { + return; + } if (utf16idx < 0 || utf16idx > 1) { - if (utf16idx != -1) { - semsg(_(e_using_number_as_bool_nr), utf16idx); - } + semsg(_(e_using_number_as_bool_nr), utf16idx); return; } } @@ -1767,18 +1769,21 @@ void f_strcharlen(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) /// "strchars()" function void f_strchars(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) { - int skipcc = false; + varnumber_T skipcc = false; if (argvars[1].v_type != VAR_UNKNOWN) { - skipcc = (int)tv_get_bool(&argvars[1]); - } - if (skipcc < 0 || skipcc > 1) { - if (skipcc != -1) { + bool error = false; + skipcc = tv_get_bool_chk(&argvars[1], &error); + if (error) { + return; + } + if (skipcc < 0 || skipcc > 1) { semsg(_(e_using_number_as_bool_nr), skipcc); + return; } - } else { - strchar_common(argvars, rettv, skipcc); } + + strchar_common(argvars, rettv, skipcc); } /// "strutf16len()" function @@ -1845,11 +1850,12 @@ void f_strcharpart(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) if (!error) { if (argvars[2].v_type != VAR_UNKNOWN && argvars[3].v_type != VAR_UNKNOWN) { - skipcc = tv_get_bool(&argvars[3]); + skipcc = tv_get_bool_chk(&argvars[3], &error); + if (error) { + return; + } if (skipcc < 0 || skipcc > 1) { - if (skipcc != -1) { - semsg(_(e_using_number_as_bool_nr), skipcc); - } + semsg(_(e_using_number_as_bool_nr), skipcc); return; } } diff --git a/test/old/testdir/test_expr.vim b/test/old/testdir/test_expr.vim index d771234983..4cb8da8c74 100644 --- a/test/old/testdir/test_expr.vim +++ b/test/old/testdir/test_expr.vim @@ -155,7 +155,8 @@ func Test_strcharpart() END call CheckLegacyAndVim9Success(lines) - call assert_fails('echo strcharpart("", 0, 0, {})', ['E728:', 'E728:']) + call assert_fails('call strcharpart("", 0, 0, {})', ['E728:', 'E728:']) + call assert_fails('call strcharpart("", 0, 0, -1)', ['E1023:', 'E1023:']) endfunc func Test_getreg_empty_list() diff --git a/test/old/testdir/test_functions.vim b/test/old/testdir/test_functions.vim index 6ff21bc859..41a8610893 100644 --- a/test/old/testdir/test_functions.vim +++ b/test/old/testdir/test_functions.vim @@ -1097,6 +1097,7 @@ func Test_byteidx() call assert_fails("call byteidx([], 0)", 'E730:') call assert_fails("call byteidx('abc', [])", 'E745:') call assert_fails("call byteidx('abc', 0, {})", ['E728:', 'E728:']) + call assert_fails("call byteidx('abc', 0, -1)", ['E1023:', 'E1023:']) endfunc " Test for byteidxcomp() using a character index @@ -1137,6 +1138,7 @@ func Test_byteidxcomp() call assert_fails("call byteidxcomp([], 0)", 'E730:') call assert_fails("call byteidxcomp('abc', [])", 'E745:') call assert_fails("call byteidxcomp('abc', 0, {})", ['E728:', 'E728:']) + call assert_fails("call byteidxcomp('abc', 0, -1)", ['E1023:', 'E1023:']) endfunc " Test for byteidx() using a UTF-16 index @@ -1497,7 +1499,6 @@ func Test_utf16idx_from_charidx() " error cases call assert_equal(-1, utf16idx(v:_null_string, 0, v:true, v:true)) call assert_fails('let l = utf16idx("ab", 0, v:false, [])', 'E1212:') - call assert_fails('echo strchars("", {})', ['E728:', 'E728:']) endfunc " Test for strutf16len() diff --git a/test/old/testdir/test_utf8.vim b/test/old/testdir/test_utf8.vim index e5f6d68720..00b060a9e2 100644 --- a/test/old/testdir/test_utf8.vim +++ b/test/old/testdir/test_utf8.vim @@ -29,8 +29,10 @@ func Test_strchars() call assert_equal(exp[i], strcharlen(inp[i])) endfor - call assert_fails("let v=strchars('abc', [])", 'E745:') - call assert_fails("let v=strchars('abc', 2)", 'E1023:') + call assert_fails("call strchars('abc', 2)", ['E1023:', 'E1023:']) + call assert_fails("call strchars('abc', -1)", ['E1023:', 'E1023:']) + call assert_fails("call strchars('abc', {})", ['E728:', 'E728:']) + call assert_fails("call strchars('abc', [])", ['E745:', 'E745:']) endfunc " Test for customlist completion |