mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: nvim_buf_set_lines(): Avoid invalid ml_get. #6019
When the buffer that nvim_buf_set_lines() is changing is not in any vim window, fix_cursor() leads to calling ml_get_buf() with an invalid line number. The condition that fix_cursor() was called on was (buf == curbuf), but this is always true because of the call to switch_to_win_for_buf() earlier in the function. Instead this should be predicated on (save_curbuf.br_buf == NULL)
This commit is contained in:
parent
1215084676
commit
6fe677c108
@ -395,7 +395,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
|
|
||||||
changed_lines((linenr_T)start, 0, (linenr_T)end, extra);
|
changed_lines((linenr_T)start, 0, (linenr_T)end, extra);
|
||||||
|
|
||||||
if (buf == curbuf) {
|
if (save_curbuf.br_buf == NULL) {
|
||||||
fix_cursor((linenr_T)start, (linenr_T)end, extra);
|
fix_cursor((linenr_T)start, (linenr_T)end, extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,9 @@ local curbuf, curwin, eq = helpers.curbuf, helpers.curwin, helpers.eq
|
|||||||
local curbufmeths, ok = helpers.curbufmeths, helpers.ok
|
local curbufmeths, ok = helpers.curbufmeths, helpers.ok
|
||||||
local funcs = helpers.funcs
|
local funcs = helpers.funcs
|
||||||
local request = helpers.request
|
local request = helpers.request
|
||||||
|
local exc_exec = helpers.exc_exec
|
||||||
|
local execute = helpers.execute
|
||||||
|
local insert = helpers.insert
|
||||||
local NIL = helpers.NIL
|
local NIL = helpers.NIL
|
||||||
local meth_pcall = helpers.meth_pcall
|
local meth_pcall = helpers.meth_pcall
|
||||||
local command = helpers.command
|
local command = helpers.command
|
||||||
@ -242,6 +245,22 @@ describe('api/buf', function()
|
|||||||
eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true))
|
eq({'e', 'a', 'b', 'c', 'd'}, get_lines(0, -1, true))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("set_line on alternate buffer does not access invalid line (E315)", function()
|
||||||
|
execute('set hidden')
|
||||||
|
insert('Initial file')
|
||||||
|
command('enew')
|
||||||
|
insert([[
|
||||||
|
More
|
||||||
|
Lines
|
||||||
|
Than
|
||||||
|
In
|
||||||
|
The
|
||||||
|
Other
|
||||||
|
Buffer]])
|
||||||
|
execute('$')
|
||||||
|
local retval = exc_exec("call nvim_buf_set_lines(1, 0, 1, v:false, ['test'])")
|
||||||
|
eq(0, retval)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('{get,set,del}_var', function()
|
describe('{get,set,del}_var', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user