Skip to content

Commit a364cdb

Browse files
committed
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 #6557) Solution: Correct the line number. Also reset the column.
1 parent c039441 commit a364cdb

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/ex_cmds.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4664,6 +4664,8 @@ ex_z(exarg_T *eap)
46644664

46654665
if (curs > curbuf->b_ml.ml_line_count)
46664666
curs = curbuf->b_ml.ml_line_count;
4667+
else if (curs < 1)
4668+
curs = 1;
46674669

46684670
for (i = start; i <= end; i++)
46694671
{
@@ -4686,7 +4688,11 @@ ex_z(exarg_T *eap)
46864688
}
46874689
}
46884690

4689-
curwin->w_cursor.lnum = curs;
4691+
if (curwin->w_cursor.lnum != curs)
4692+
{
4693+
curwin->w_cursor.lnum = curs;
4694+
curwin->w_cursor.col = 0;
4695+
}
46904696
ex_no_reprint = TRUE;
46914697
}
46924698

src/testdir/test_ex_z.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,18 @@ func Test_z()
6868
bw!
6969
endfunc
7070

71-
func Test_z_bug()
71+
func Test_z_overflow()
7272
" This used to access invalid memory as a result of an integer overflow
7373
" and freeze vim.
7474
normal ox
7575
normal Heat
7676
z777777776666666
7777
')
7878
endfunc
79+
80+
func Test_z_negative_lnum()
81+
new
82+
z^
83+
call assert_equal(1, line('.'))
84+
bwipe!
85+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
571,
767769
/**/
768770
570,
769771
/**/

0 commit comments

Comments
 (0)