aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-12-07 16:39:30 +0800
committerGitHub <noreply@github.com>2023-12-07 16:39:30 +0800
commit4fc31cb69fab9dff66e779a2780aaf16fcc8bb13 (patch)
treeaaa5089eda131b04de35d5e74a66431f538229c9 /src
parent1dba570e63edcc69d6661bdcb9857def8bb18039 (diff)
parentbc5b0da84ec4d8ba01d17fc4e0f616fd3fe46f8e (diff)
downloadrneovim-4fc31cb69fab9dff66e779a2780aaf16fcc8bb13.tar.gz
rneovim-4fc31cb69fab9dff66e779a2780aaf16fcc8bb13.tar.bz2
rneovim-4fc31cb69fab9dff66e779a2780aaf16fcc8bb13.zip
Merge pull request #26445 from zeertzjq/inccommand
fix(inccommand): don't crash with "split" and 'n' flag
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_cmds.c8
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;
}
}