]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0043: ml_get: invalid lnum when :s replaces visual selection v9.1.0043
authorChristian Brabandt <cb@256bit.org>
Mon, 22 Jan 2024 19:12:34 +0000 (20:12 +0100)
committerChristian Brabandt <cb@256bit.org>
Mon, 22 Jan 2024 19:12:34 +0000 (20:12 +0100)
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: #13890
closes: #13892

Signed-off-by: Christian Brabandt <cb@256bit.org>
src/regexp.c
src/testdir/test_visual.vim
src/version.c

index c3bc4966c7538f4837af77a4b85483ebf2d66ebd..73552015e99993fb3a39ce6d7b6e7ce733e2e1c8 100644 (file)
@@ -1318,6 +1318,10 @@ 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;
     }
index 401a3504ae0473bad6bdc64addc1c8dd8c42ff77..f0d8edcf848ebae84a45c2dcd1dbe1372be50429 100644 (file)
@@ -1622,4 +1622,12 @@ func Test_visual_drag_out_of_window()
   bwipe!
 endfunc
 
+func Test_visual_substitute_visual()
+  new
+  call setline(1, ['one', 'two', 'three'])
+  call feedkeys("Gk\<C-V>j$:s/\\%V\\_.*\\%V/foobar\<CR>", 'tx')
+  call assert_equal(['one', 'foobar'], getline(1, '$'))
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 094658c3a4321c91cc20b42884b90d0b55dcf76a..783e2ba1b5102881fbe10284e7031d86c67a0f55 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    43,
 /**/
     42,
 /**/