changeset 11372:1074f58e1673 v8.0.0571

patch 8.0.0571: negative line number when using :z^ in an empty buffer commit https://github.com/vim/vim/commit/a364cdb648ae009fa7aa05382f5659335683d349 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 20 21:12:30 2017 +0200 patch 8.0.0571: negative line number when using :z^ in an empty buffer Problem: The cursor line number becomes negative when using :z^ in an empty buffer. (neovim https://github.com/vim/vim/issues/6557) Solution: Correct the line number. Also reset the column.
author Christian Brabandt <cb@256bit.org>
date Thu, 20 Apr 2017 21:15:04 +0200
parents a945e33a8879
children 600a8ca3cc40
files src/ex_cmds.c src/testdir/test_ex_z.vim src/version.c
diffstat 3 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -4664,6 +4664,8 @@ ex_z(exarg_T *eap)
 
     if (curs > curbuf->b_ml.ml_line_count)
 	curs = curbuf->b_ml.ml_line_count;
+    else if (curs < 1)
+	curs = 1;
 
     for (i = start; i <= end; i++)
     {
@@ -4686,7 +4688,11 @@ ex_z(exarg_T *eap)
 	}
     }
 
-    curwin->w_cursor.lnum = curs;
+    if (curwin->w_cursor.lnum != curs)
+    {
+	curwin->w_cursor.lnum = curs;
+	curwin->w_cursor.col = 0;
+    }
     ex_no_reprint = TRUE;
 }
 
--- a/src/testdir/test_ex_z.vim
+++ b/src/testdir/test_ex_z.vim
@@ -68,7 +68,7 @@ func Test_z()
   bw!
 endfunc
 
-func Test_z_bug()
+func Test_z_overflow()
   " This used to access invalid memory as a result of an integer overflow
   " and freeze vim.
   normal ox
@@ -76,3 +76,10 @@ func Test_z_bug()
   z777777776666666
   ')
 endfunc
+
+func Test_z_negative_lnum()
+  new
+  z^
+  call assert_equal(1, line('.'))
+  bwipe!
+endfunc
--- a/src/version.c
+++ b/src/version.c
@@ -765,6 +765,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    571,
+/**/
     570,
 /**/
     569,