# HG changeset patch # User Christian Brabandt # Date 1491250505 -7200 # Node ID 327a04a762f6cdb1923700be47cde58324b9ab35 # Parent 661647ecec533b46ec82306a94abeea7b4477043 patch 8.0.0542: getpos() can return a negative line number commit https://github.com/vim/vim/commit/a1d5fa65bc7e8a548858e9c295a192b63dcd011b Author: Bram Moolenaar Date: Mon Apr 3 22:02:55 2017 +0200 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 https://github.com/vim/vim/issues/1613) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5413,8 +5413,10 @@ line({expr}) The result is a Number, whi $ the last line in the current buffer 'x position of mark x (if the mark is not set, 0 is returned) - w0 first line visible in current window - w$ last line visible in current window + w0 first line visible in current window (one if the + display isn't updated, e.g. in silent Ex mode) + w$ last line visible in current window (this is one + less than "w0" if no lines are visible) v In Visual mode: the start of the Visual area (the cursor is the end). When not in Visual mode returns the cursor position. Differs from |'<| in diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -6120,13 +6120,16 @@ var2fpos( if (name[1] == '0') /* "w0": first visible line */ { update_topline(); - pos.lnum = curwin->w_topline; + /* In silent Ex mode topline is zero, but that's not a valid line + * number; use one instead. */ + pos.lnum = curwin->w_topline > 0 ? curwin->w_topline : 1; return &pos; } else if (name[1] == '$') /* "w$": last visible line */ { validate_botline(); - pos.lnum = curwin->w_botline - 1; + /* In silent Ex mode botline is zero, return zero then. */ + pos.lnum = curwin->w_botline > 0 ? curwin->w_botline - 1 : 0; return &pos; } } diff --git a/src/version.c b/src/version.c --- 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 */ /**/ + 542, +/**/ 541, /**/ 540,