changeset 25911:d6d31972c76d v8.2.3489

patch 8.2.3489: ml_get error after search with range Commit: https://github.com/vim/vim/commit/35a319b77f897744eec1155b736e9372c9c5575f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 9 13:58:55 2021 +0100 patch 8.2.3489: ml_get error after search with range Problem: ml_get error after search with range. Solution: Limit the line number to the buffer line count.
author Bram Moolenaar <Bram@vim.org>
date Sat, 09 Oct 2021 15:00:03 +0200
parents d95774ab4307
children 102e3e860b52
files src/ex_docmd.c src/testdir/test_search.vim src/version.c
diffstat 3 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -4229,8 +4229,10 @@ get_address(
 
 		    // When '/' or '?' follows another address, start from
 		    // there.
-		    if (lnum != MAXLNUM)
-			curwin->w_cursor.lnum = lnum;
+		    if (lnum > 0 && lnum != MAXLNUM)
+			curwin->w_cursor.lnum =
+				lnum > curbuf->b_ml.ml_line_count
+					   ? curbuf->b_ml.ml_line_count : lnum;
 
 		    // Start a forward search at the end of the line (unless
 		    // before the first line).
--- a/src/testdir/test_search.vim
+++ b/src/testdir/test_search.vim
@@ -1989,5 +1989,19 @@ func Test_no_last_search_pattern()
   call feedkeys("??\<C-T>", 'xt')
 endfunc
 
+func Test_search_with_invalid_range()
+  new
+  let lines =<< trim END
+    /\%.v
+    5/
+    c
+  END
+  call writefile(lines, 'Xrangesearch')
+  source Xrangesearch
+
+  bwipe!
+  call delete('Xrangesearch')
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    3489,
+/**/
     3488,
 /**/
     3487,