mirror of
https://github.com/neovim/neovim.git
synced 2026-09-09 07:25:51 +00:00
fix(multicursor): prevent clipboard crash after cursor jump #41698
Problem: Changing from an empty-line cursor after a multicursor jump can crash while flushing a deferred clipboard update. Exact context restore can leave an omitted register with a null array and stale non-zero size. Solution: Make free_register() fully reset the register after freeing its contents, so it always leaves a valid empty register. Add a regression test. Signed-off-by: sami <samiulsami7786@gmail.com>
This commit is contained in:
@@ -986,14 +986,13 @@ void free_register(yankreg_T *reg)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
XFREE_CLEAR(reg->additional_data);
|
||||
if (reg->y_array == NULL) {
|
||||
return;
|
||||
if (reg->y_array != NULL) {
|
||||
for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included
|
||||
API_CLEAR_STRING(reg->y_array[i]);
|
||||
}
|
||||
XFREE_CLEAR(reg->y_array);
|
||||
}
|
||||
|
||||
for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included
|
||||
API_CLEAR_STRING(reg->y_array[i]);
|
||||
}
|
||||
XFREE_CLEAR(reg->y_array);
|
||||
*reg = (yankreg_T){ 0 };
|
||||
}
|
||||
|
||||
/// Copy a block range into a register.
|
||||
|
||||
@@ -2628,6 +2628,32 @@ describe('multicursor', function()
|
||||
end)
|
||||
|
||||
describe('clipboard', function()
|
||||
it("does not crash after jumping to an empty line with 'clipboard'", function()
|
||||
n.exec_lua([[
|
||||
_G.content = {}
|
||||
vim.g.clipboard = {
|
||||
name = 'test',
|
||||
copy = {
|
||||
['+'] = function(lines)
|
||||
_G.content = lines
|
||||
end,
|
||||
},
|
||||
paste = {
|
||||
['+'] = function()
|
||||
return _G.content
|
||||
end,
|
||||
},
|
||||
}
|
||||
vim.o.clipboard = 'unnamedplus'
|
||||
]])
|
||||
cursors({ '', 'aa' }, 'Qj') -- Cursor on the empty line, primary on the non-empty line.
|
||||
feed(']C') -- Make the empty-line cursor primary.
|
||||
feed('C')
|
||||
n.assert_alive()
|
||||
feed('<Esc>')
|
||||
eq({ '', '' }, get_lines())
|
||||
end)
|
||||
|
||||
it("perf: provider syncs once per cascade with 'clipboard'", function()
|
||||
n.exec_lua([[
|
||||
_G.copies = 0
|
||||
|
||||
Reference in New Issue
Block a user