fix(inccommand): avoid crash if callback changes inccommand option (#18830)

clang: Result of operation is garbage or undefined
clang: Uninitialized argument value

Also check for == 's' instead of != 'n' as it is more straightforward.

Also fix another unrelated PVS warning:
PVS/V1071: Return value of win_comp_pos() is not always used
This commit is contained in:
zeertzjq
2022-06-02 03:48:36 +08:00
committed by GitHub
parent 209824ce2c
commit 57a296d899
4 changed files with 23 additions and 5 deletions

View File

@@ -336,4 +336,21 @@ describe("'inccommand' for user commands", function()
feed('e')
assert_alive()
end)
it('no crash if preview callback changes inccommand option', function()
command('set inccommand=nosplit')
exec_lua([[
vim.api.nvim_create_user_command('Replace', function() end, {
nargs = '*',
preview = function()
vim.api.nvim_set_option('inccommand', 'split')
return 2
end,
})
]])
feed(':R')
assert_alive()
feed('e')
assert_alive()
end)
end)