Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57a296d

Browse files
authored
fix(inccommand): avoid crash if callback changes inccommand option (#18830)
clang: Result of operation is garbage or undefinedclang: Uninitialized argument valueAlso 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
1 parent209824c commit57a296d

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

‎src/nvim/ex_cmds.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5872,7 +5872,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i
58725872
linenr_Thighest_num_line=0;
58735873
intcol_width=0;
58745874
// Use preview window only when inccommand=split and range is not just the current line
5875-
boolpreview= (*p_icm!='n')&& (eap->line1!=old_cusr.lnum||eap->line2!=old_cusr.lnum);
5875+
boolpreview= (*p_icm=='s')&& (eap->line1!=old_cusr.lnum||eap->line2!=old_cusr.lnum);
58765876

58775877
if (preview) {
58785878
cmdpreview_buf=buflist_findnr(cmdpreview_bufnr);

‎src/nvim/ex_getln.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,6 +2413,7 @@ static void cmdpreview_show(CommandLineState *s)
24132413
intsave_w_p_cuc=curwin->w_p_cuc;
24142414
boolsave_hls=p_hls;
24152415
varnumber_Tsave_changedtick=buf_get_changedtick(curbuf);
2416+
boolicm_split=*p_icm=='s';// inccommand=split
24162417
buf_T*cmdpreview_buf;
24172418
win_T*cmdpreview_win;
24182419
cmdmod_Tsave_cmdmod=cmdmod;
@@ -2433,7 +2434,7 @@ static void cmdpreview_show(CommandLineState *s)
24332434
cmdmod.noswapfile= true;// Disable swap for preview buffer
24342435

24352436
// Open preview buffer if inccommand=split.
2436-
if (*p_icm=='n') {
2437+
if (!icm_split) {
24372438
cmdpreview_bufnr=0;
24382439
}elseif ((cmdpreview_buf=cmdpreview_open_buf())==NULL) {
24392440
abort();
@@ -2456,7 +2457,7 @@ static void cmdpreview_show(CommandLineState *s)
24562457
}
24572458

24582459
// If inccommand=split and preview callback returns 2, open preview window.
2459-
if (*p_icm!='n'&&cmdpreview_type==2
2460+
if (icm_split&&cmdpreview_type==2
24602461
&& (cmdpreview_win=cmdpreview_open_win(cmdpreview_buf))==NULL) {
24612462
abort();
24622463
}
@@ -2470,7 +2471,7 @@ static void cmdpreview_show(CommandLineState *s)
24702471
}
24712472

24722473
// Close preview window if it's open.
2473-
if (*p_icm!='n'&&cmdpreview_type==2&&cmdpreview_win!=NULL) {
2474+
if (icm_split&&cmdpreview_type==2&&cmdpreview_win!=NULL) {
24742475
cmdpreview_close_win();
24752476
}
24762477
// Clear preview highlights.

‎src/nvim/window.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6678,7 +6678,7 @@ static bool resize_frame_for_winbar(frame_T *fr)
66786678
frame_new_height(fp,fp->fr_height-1, false, false);
66796679
win_new_height(wp,wp->w_height+1);
66806680
frame_fix_height(wp);
6681-
win_comp_pos();
6681+
(void)win_comp_pos();
66826682
}
66836683

66846684
return true;

‎test/functional/ui/inccommand_user_spec.lua‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,21 @@ describe("'inccommand' for user commands", function()
336336
feed('e')
337337
assert_alive()
338338
end)
339+
340+
it('no crash if preview callback changes inccommand option',function()
341+
command('set inccommand=nosplit')
342+
exec_lua([[
343+
vim.api.nvim_create_user_command('Replace', function() end, {
344+
nargs = '*',
345+
preview = function()
346+
vim.api.nvim_set_option('inccommand', 'split')
347+
return 2
348+
end,
349+
})
350+
]])
351+
feed(':R')
352+
assert_alive()
353+
feed('e')
354+
assert_alive()
355+
end)
339356
end)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp