]> granicus.if.org Git - vim/commitdiff
patch 8.0.0571: negative line number when using :z^ in an empty buffer v8.0.0571
authorBram Moolenaar <Bram@vim.org>
Thu, 20 Apr 2017 19:12:30 +0000 (21:12 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 20 Apr 2017 19:12:30 +0000 (21:12 +0200)
Problem:    The cursor line number becomes negative when using :z^ in an empty
            buffer. (neovim #6557)
Solution:   Correct the line number.  Also reset the column.

src/ex_cmds.c
src/testdir/test_ex_z.vim
src/version.c

index 4b0bdef59cac8337477ad45919bcbd2b6b262b11..309474ce048a1700af69725678b793c5d2515e17 100644 (file)
@@ -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;
 }
 
index 608a36c4904ef81d499782f820339a4e8e28afbf..6e03b0bff9b4d508cc9683e7559d4dd742d9ac91 100644 (file)
@@ -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
index c169765849154339dfe4962126d73f970a5a1660..81b98c11fc6d27cb611cf8213f8d3fa0c3895fd4 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    571,
 /**/
     570,
 /**/