fix(inccommand): don't crash with "split" and 'n' flag

This commit is contained in:
zeertzjq 2023-12-07 15:54:05 +08:00
parent 93011add10
commit bc5b0da84e

View File

@ -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;
}
}