From dc466f9a63ede5e2bbddc33688c0c972abfe9a52 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 23 Jan 2024 06:51:10 +0800 Subject: vim-patch:9.1.0043: ml_get: invalid lnum when :s replaces visual selection (#27140) Problem: ml_get: invalid lnum when :s replaces visual selection (@ropery) Solution: substitute may decrement the number of lines in a buffer, so validate, that the bottom lines of the visual selection stays within the max buffer line fixes: vim/vim#13890 closes: vim/vim#13892 https://github.com/vim/vim/commit/7c71db3a58f658b4329b82ab603efa928d17bdbc Co-authored-by: Christian Brabandt --- src/nvim/regexp.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 74f3b3452b..37f672fc86 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1365,6 +1365,11 @@ static bool reg_match_visual(void) top = curbuf->b_visual.vi_end; bot = curbuf->b_visual.vi_start; } + // a substitue command may have + // removed some lines + if (bot.lnum > curbuf->b_ml.ml_line_count) { + bot.lnum = curbuf->b_ml.ml_line_count; + } mode = curbuf->b_visual.vi_mode; curswant = curbuf->b_visual.vi_curswant; } -- cgit