diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-12-07 15:54:05 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-12-07 15:57:21 +0800 |
commit | bc5b0da84ec4d8ba01d17fc4e0f616fd3fe46f8e (patch) | |
tree | aaa5089eda131b04de35d5e74a66431f538229c9 | |
parent | 93011add10946d5f3b4695b29897af7237261768 (diff) | |
download | rneovim-bc5b0da84ec4d8ba01d17fc4e0f616fd3fe46f8e.tar.gz rneovim-bc5b0da84ec4d8ba01d17fc4e0f616fd3fe46f8e.tar.bz2 rneovim-bc5b0da84ec4d8ba01d17fc4e0f616fd3fe46f8e.zip |
fix(inccommand): don't crash with "split" and 'n' flag
-rw-r--r-- | src/nvim/ex_cmds.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 0711d82fe5..68c316fde0 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -4580,7 +4580,6 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i } // Width of the "| lnum|..." column which displays the line numbers. - linenr_T highest_num_line = 0; int col_width = 0; // Use preview window only when inccommand=split and range is not just the current line bool preview = (*p_icm == 's') && (eap->line1 != old_cusr.lnum || eap->line2 != old_cusr.lnum); @@ -4590,8 +4589,11 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i assert(cmdpreview_buf != NULL); if (lines.subresults.size > 0) { - highest_num_line = kv_last(lines.subresults).end.lnum; - col_width = (int)log10(highest_num_line) + 1 + 3; + SubResult last_match = kv_last(lines.subresults); + // `last_match.end.lnum` may be 0 when using 'n' flag. + linenr_T highest_lnum = MAX(last_match.start.lnum, last_match.end.lnum); + assert(highest_lnum > 0); + col_width = (int)log10(highest_lnum) + 1 + 3; } } |