Patch 9.0.1524
Problem: Passing -1 for bool is not always rejected.
Solution: Check for error in a better way. (closes #12358)
Files: src/strings.c, src/testdir/test_expr.vim,
src/testdir/test_functions.vim, src/testdir/test_utf8.vim
*** ../vim-9.0.1523/src/strings.c 2023-05-07 18:53:45.780170928 +0100
--- src/strings.c 2023-05-08 15:28:58.311528624 +0100
***************
*** 1065,1075 ****
varnumber_T utf16idx = FALSE;
if (argvars[2].v_type != VAR_UNKNOWN)
{
! utf16idx = tv_get_bool(&argvars[2]);
if (utf16idx < 0 || utf16idx > 1)
{
! if (utf16idx != -1)
! semsg(_(e_using_number_as_bool_nr), utf16idx);
return;
}
}
--- 1065,1077 ----
varnumber_T utf16idx = FALSE;
if (argvars[2].v_type != VAR_UNKNOWN)
{
! int error = FALSE;
! utf16idx = tv_get_bool_chk(&argvars[2], &error);
! if (error)
! return;
if (utf16idx < 0 || utf16idx > 1)
{
! semsg(_(e_using_number_as_bool_nr), utf16idx);
return;
}
}
***************
*** 1421,1434 ****
return;
if (argvars[1].v_type != VAR_UNKNOWN)
- skipcc = tv_get_bool(&argvars[1]);
- if (skipcc < 0 || skipcc > 1)
{
! if (skipcc != -1)
semsg(_(e_using_number_as_bool_nr), skipcc);
}
! else
! strchar_common(argvars, rettv, skipcc);
}
/*
--- 1423,1441 ----
return;
if (argvars[1].v_type != VAR_UNKNOWN)
{
! int 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;
+ }
}
!
! strchar_common(argvars, rettv, skipcc);
}
/*
***************
*** 1533,1543 ****
if (argvars[2].v_type != VAR_UNKNOWN
&& argvars[3].v_type != VAR_UNKNOWN)
{
! skipcc = tv_get_bool(&argvars[3]);
if (skipcc < 0 || skipcc > 1)
{
! if (skipcc != -1)
! semsg(_(e_using_number_as_bool_nr), skipcc);
return;
}
}
--- 1540,1551 ----
if (argvars[2].v_type != VAR_UNKNOWN
&& argvars[3].v_type != VAR_UNKNOWN)
{
! skipcc = tv_get_bool_chk(&argvars[3], &error);
! if (error)
! return;
if (skipcc < 0 || skipcc > 1)
{
! semsg(_(e_using_number_as_bool_nr), skipcc);
return;
}
}
*** ../vim-9.0.1523/src/testdir/test_expr.vim 2023-05-07 18:53:45.780170928
+0100
--- src/testdir/test_expr.vim 2023-05-08 15:28:58.311528624 +0100
***************
*** 161,167 ****
END
call v9.CheckLegacyAndVim9Success(lines)
! call assert_fails('echo strcharpart("", 0, 0, {})', ['E728:', 'E728:'])
endfunc
func Test_getreg_empty_list()
--- 161,168 ----
END
call v9.CheckLegacyAndVim9Success(lines)
! 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()
*** ../vim-9.0.1523/src/testdir/test_functions.vim 2023-05-07
18:53:45.780170928 +0100
--- src/testdir/test_functions.vim 2023-05-08 15:28:58.311528624 +0100
***************
*** 1225,1230 ****
--- 1225,1231 ----
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
***************
*** 1265,1270 ****
--- 1266,1272 ----
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
***************
*** 1625,1631 ****
" error cases
call assert_equal(-1, utf16idx(test_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()
--- 1627,1632 ----
*** ../vim-9.0.1523/src/testdir/test_utf8.vim 2023-01-28 19:18:56.737720609
+0000
--- src/testdir/test_utf8.vim 2023-05-08 15:28:58.311528624 +0100
***************
*** 29,36 ****
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:')
endfunc
" Test for customlist completion
--- 29,38 ----
call assert_equal(exp[i], strcharlen(inp[i]))
endfor
! 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
*** ../vim-9.0.1523/src/version.c 2023-05-07 21:59:28.540096431 +0100
--- src/version.c 2023-05-08 15:30:58.619542384 +0100
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1524,
/**/
--
hundred-and-one symptoms of being an internet addict:
17. You turn on your intercom when leaving the room so you can hear if new
e-mail arrives.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20230508143221.3DA491C1B21%40moolenaar.net.