mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix: check for valid buffer handles in modify_keymap (#13543)
Fixes #13541 Neovim would crash when trying to map a key on non existant buffer
This commit is contained in:
parent
ae63dc264a
commit
fd960a33e4
@ -820,6 +820,10 @@ void modify_keymap(Buffer buffer, bool is_unmap, String mode, String lhs,
|
|||||||
}
|
}
|
||||||
buf_T *target_buf = find_buffer_by_handle(buffer, err);
|
buf_T *target_buf = find_buffer_by_handle(buffer, err);
|
||||||
|
|
||||||
|
if (!target_buf) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
MapArguments parsed_args;
|
MapArguments parsed_args;
|
||||||
memset(&parsed_args, 0, sizeof(parsed_args));
|
memset(&parsed_args, 0, sizeof(parsed_args));
|
||||||
if (parse_keymap_opts(opts, &parsed_args, err)) {
|
if (parse_keymap_opts(opts, &parsed_args, err)) {
|
||||||
|
@ -809,4 +809,9 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
|
|||||||
command('normal lhs')
|
command('normal lhs')
|
||||||
eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1))
|
eq({'rhs'}, bufmeths.get_lines(0, 0, 1, 1))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("does not crash when setting keymap in a non-existing buffer #13541", function()
|
||||||
|
pcall_err(bufmeths.set_keymap, 100, '', 'lsh', 'irhs<Esc>', {})
|
||||||
|
helpers.assert_alive()
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user