Skip to content

Commit a1d5fa6

Browse files
committed
patch 8.0.0542: getpos() can return a negative line number
Problem: getpos() can return a negative line number. (haya14busa) Solution: Handle a zero topline and botline. (closes #1613)
1 parent 0400056 commit a1d5fa6

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

runtime/doc/eval.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5413,8 +5413,10 @@ line({expr}) The result is a Number, which is the line number of the file
54135413
$ the last line in the current buffer
54145414
'x position of mark x (if the mark is not set, 0 is
54155415
returned)
5416-
w0 first line visible in current window
5417-
w$ last line visible in current window
5416+
w0 first line visible in current window (one if the
5417+
display isn't updated, e.g. in silent Ex mode)
5418+
w$ last line visible in current window (this is one
5419+
less than "w0" if no lines are visible)
54185420
v In Visual mode: the start of the Visual area (the
54195421
cursor is the end). When not in Visual mode
54205422
returns the cursor position. Differs from |'<| in

src/eval.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6120,13 +6120,16 @@ var2fpos(
61206120
if (name[1] == '0') /* "w0": first visible line */
61216121
{
61226122
update_topline();
6123-
pos.lnum = curwin->w_topline;
6123+
/* In silent Ex mode topline is zero, but that's not a valid line
6124+
* number; use one instead. */
6125+
pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1;
61246126
return &pos;
61256127
}
61266128
else if (name[1] == '$') /* "w$": last visible line */
61276129
{
61286130
validate_botline();
6129-
pos.lnum = curwin->w_botline - 1;
6131+
/* In silent Ex mode botline is zero, return zero then. */
6132+
pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0;
61306133
return &pos;
61316134
}
61326135
}

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+
542,
767769
/**/
768770
541,
769771
/**/

0 commit comments

Comments
 (0)