# HG changeset patch # User Bram Moolenaar # Date 1640878204 -3600 # Node ID 1e3c49c0926083fca40e636d0729b50eb43a5cb9 # Parent df509756e36dffdd2cb25984210800cd330e0187 patch 8.2.3950: going beyond the end of the line with /%V Commit: https://github.com/vim/vim/commit/94f3192b03ed27474db80b4d3a409e107140738b Author: Bram Moolenaar Date: Thu Dec 30 15:29:18 2021 +0000 patch 8.2.3950: going beyond the end of the line with /\%V Problem: Going beyond the end of the line with /\%V. Solution: Check for valid column in getvcol(). diff --git a/src/charset.c b/src/charset.c --- a/src/charset.c +++ b/src/charset.c @@ -1240,10 +1240,15 @@ getvcol( posptr = NULL; // continue until the NUL else { - // Special check for an empty line, which can happen on exit, when - // ml_get_buf() always returns an empty string. - if (*ptr == NUL) - pos->col = 0; + colnr_T i; + + // In a few cases the position can be beyond the end of the line. + for (i = 0; i < pos->col; ++i) + if (ptr[i] == NUL) + { + pos->col = i; + break; + } posptr = ptr + pos->col; if (has_mbyte) // always start on the first byte diff --git a/src/testdir/test_regexp_latin.vim b/src/testdir/test_regexp_latin.vim --- a/src/testdir/test_regexp_latin.vim +++ b/src/testdir/test_regexp_latin.vim @@ -1053,4 +1053,12 @@ func Test_using_visual_position() bwipe! endfunc +func Test_using_invalid_visual_position() + " this was going beyond the end of the line + new + exe "norm 0o000\0\$s0" + /\%V + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -750,6 +750,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3950, +/**/ 3949, /**/ 3948,