Merge pull request #29691 from zeertzjq/vim-9.1.0577

vim-patch:8.2.{3716,4065},9.1.{0577,0579}
This commit is contained in:
zeertzjq
2024-07-14 06:37:15 +08:00
committed by GitHub
6 changed files with 54 additions and 117 deletions

View File

@@ -1411,7 +1411,11 @@ void set_cmd_count(exarg_T *eap, linenr_T count, bool validate)
}
} else {
eap->line1 = eap->line2;
eap->line2 += count - 1;
if (eap->line2 >= INT32_MAX - (count - 1)) {
eap->line2 = INT32_MAX;
} else {
eap->line2 += count - 1;
}
eap->addr_count++;
// Be vi compatible: no error message for out of range.
if (validate && eap->line2 > curbuf->b_ml.ml_line_count) {
@@ -1429,7 +1433,7 @@ static int parse_count(exarg_T *eap, const char **errormsg, bool validate)
if ((eap->argt & EX_COUNT) && ascii_isdigit(*eap->arg)
&& (!(eap->argt & EX_BUFNAME) || *(p = skipdigits(eap->arg + 1)) == NUL
|| ascii_iswhite(*p))) {
linenr_T n = getdigits_int32(&eap->arg, false, -1);
linenr_T n = getdigits_int32(&eap->arg, false, INT32_MAX);
eap->arg = skipwhite(eap->arg);
if (eap->args != NULL) {
@@ -2075,29 +2079,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
if (ea.skip) { // skip this if inside :if
goto doend;
}
if (*ea.cmd == '|' || (exmode_active && ea.line1 != ea.line2)) {
ea.cmdidx = CMD_print;
ea.argt = EX_RANGE | EX_COUNT | EX_TRLBAR;
if ((errormsg = invalid_range(&ea)) == NULL) {
correct_range(&ea);
ex_print(&ea);
}
} else if (ea.addr_count != 0) {
if (ea.line2 > curbuf->b_ml.ml_line_count) {
ea.line2 = curbuf->b_ml.ml_line_count;
}
if (ea.line2 < 0) {
errormsg = _(e_invrange);
} else {
if (ea.line2 == 0) {
curwin->w_cursor.lnum = 1;
} else {
curwin->w_cursor.lnum = ea.line2;
}
beginline(BL_SOL | BL_FIX);
}
}
errormsg = ex_range_without_command(&ea);
goto doend;
}
@@ -2443,6 +2425,38 @@ char *ex_errmsg(const char *const msg, const char *const arg)
return ex_error_buf;
}
/// Handle a range without a command.
/// Returns an error message on failure.
static char *ex_range_without_command(exarg_T *eap)
{
char *errormsg = NULL;
if (*eap->cmd == '|' || (exmode_active && eap->line1 != eap->line2)) {
eap->cmdidx = CMD_print;
eap->argt = EX_RANGE | EX_COUNT | EX_TRLBAR;
if ((errormsg = invalid_range(eap)) == NULL) {
correct_range(eap);
ex_print(eap);
}
} else if (eap->addr_count != 0) {
if (eap->line2 > curbuf->b_ml.ml_line_count) {
eap->line2 = curbuf->b_ml.ml_line_count;
}
if (eap->line2 < 0) {
errormsg = _(e_invrange);
} else {
if (eap->line2 == 0) {
curwin->w_cursor.lnum = 1;
} else {
curwin->w_cursor.lnum = eap->line2;
}
beginline(BL_SOL | BL_FIX);
}
}
return errormsg;
}
/// Parse and skip over command modifiers:
/// - update eap->cmd
/// - store flags in "cmod".
@@ -3615,6 +3629,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, bool
n = getdigits_int32(&cmd, false, MAXLNUM);
if (n == MAXLNUM) {
*errormsg = _(e_line_number_out_of_range);
cmd = NULL;
goto error;
}
}
@@ -3637,6 +3652,7 @@ static linenr_T get_address(exarg_T *eap, char **ptr, cmd_addr_T addr_type, bool
} else {
if (lnum >= 0 && n >= INT32_MAX - lnum) {
*errormsg = _(e_line_number_out_of_range);
cmd = NULL;
goto error;
}
lnum += n;

View File

@@ -29,13 +29,13 @@ describe('Ex cmds', function()
':tabnext 9999999999999999999999999999999999999999',
'Vim(tabnext):E475: Invalid argument: 9999999999999999999999999999999999999999'
)
check_excmd_err(
':N 9999999999999999999999999999999999999999',
'Vim(Next):E939: Positive count required'
eq(
'Vim(Next):E163: There is only one file to edit',
pcall_err(command, ':N 9999999999999999999999999999999999999999')
)
check_excmd_err(
':bdelete 9999999999999999999999999999999999999999',
'Vim(bdelete):E939: Positive count required'
'Vim(bdelete):E516: No buffers were deleted'
)
eq(
'Vim(menu):E329: No menu "9999999999999999999999999999999999999999"',

View File

@@ -5,45 +5,14 @@ local Screen = require('test.functional.ui.screen')
local clear = n.clear
local command = n.command
local exec = n.exec
local exec_lua = n.exec_lua
local expect_exit = n.expect_exit
local feed = n.feed
local fn = n.fn
local api = n.api
local read_file = t.read_file
local source = n.source
local eq = t.eq
local write_file = t.write_file
local is_os = t.is_os
local function sizeoflong()
if not exec_lua('return pcall(require, "ffi")') then
pending('missing LuaJIT FFI')
end
return exec_lua('return require("ffi").sizeof(require("ffi").typeof("long"))')
end
describe('Ex command', function()
before_each(clear)
after_each(function()
eq({}, api.nvim_get_vvar('errors'))
end)
it('checks for address line overflow', function()
if sizeoflong() < 8 then
pending('Skipped: only works with 64 bit long ints')
end
source [[
new
call setline(1, 'text')
call assert_fails('|.44444444444444444444444', 'E1247:')
call assert_fails('|.9223372036854775806', 'E1247:')
bwipe!
]]
end)
end)
describe(':confirm command dialog', function()
local screen

View File

@@ -1,52 +1,11 @@
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local clear = n.clear
local exec_lua = n.exec_lua
local api = n.api
local source = n.source
local eq = t.eq
local function sizeoflong()
if not exec_lua('return pcall(require, "ffi")') then
pending('missing LuaJIT FFI')
end
return exec_lua('return require("ffi").sizeof(require("ffi").typeof("long"))')
end
describe('put', function()
before_each(clear)
after_each(function()
eq({}, api.nvim_get_vvar('errors'))
end)
it('very large count 64-bit', function()
if sizeoflong() < 8 then
pending('Skipped: only works with 64 bit long ints')
end
source [[
new
let @" = repeat('x', 100)
call assert_fails('norm 999999999p', 'E1240:')
bwipe!
]]
end)
it('very large count (visual block) 64-bit', function()
if sizeoflong() < 8 then
pending('Skipped: only works with 64 bit long ints')
end
source [[
new
call setline(1, repeat('x', 100))
exe "norm \<C-V>$y"
call assert_fails('norm 999999999p', 'E1240:')
bwipe!
]]
end)
-- oldtest: Test_put_other_window()
it('above topline in buffer in two splits', function()

View File

@@ -718,15 +718,20 @@ func Test_not_break_expression_register()
endfunc
func Test_address_line_overflow()
throw 'Skipped: v:sizeoflong is N/A' " use legacy/excmd_spec.lua instead
if v:sizeoflong < 8
if !has('nvim') && v:sizeoflong < 8
throw 'Skipped: only works with 64 bit long ints'
endif
new
call setline(1, 'text')
call setline(1, range(100))
call assert_fails('|.44444444444444444444444', 'E1247:')
call assert_fails('|.9223372036854775806', 'E1247:')
call assert_fails('.44444444444444444444444d', 'E1247:')
call assert_equal(range(100)->map('string(v:val)'), getline(1, '$'))
$
yank 77777777777777777777
call assert_equal("99\n", @")
bwipe!
endfunc

View File

@@ -168,12 +168,6 @@ func Test_very_large_count()
endfunc
func Test_very_large_count_64bit()
throw 'Skipped: v:sizeoflong is N/A' " use legacy/put_spec.lua instead
if v:sizeoflong < 8
throw 'Skipped: only works with 64 bit long ints'
endif
new
let @" = repeat('x', 100)
call assert_fails('norm 999999999p', 'E1240:')
@@ -190,12 +184,6 @@ func Test_very_large_count_block()
endfunc
func Test_very_large_count_block_64bit()
throw 'Skipped: v:sizeoflong is N/A' " use legacy/put_spec.lua instead
if v:sizeoflong < 8
throw 'Skipped: only works with 64 bit long ints'
endif
new
call setline(1, repeat('x', 100))
exe "norm \<C-V>$y"