Mercurial > vim
changeset 26843:1e3c49c09260 v8.2.3950
patch 8.2.3950: going beyond the end of the line with /%V
Commit: https://github.com/vim/vim/commit/94f3192b03ed27474db80b4d3a409e107140738b
Author: Bram Moolenaar <Bram@vim.org>
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().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 30 Dec 2021 16:30:04 +0100 |
parents | df509756e36d |
children | 90ab085d8d8f |
files | src/charset.c src/testdir/test_regexp_latin.vim src/version.c |
diffstat | 3 files changed, 19 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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\<Esc>0\<C-V>$s0" + /\%V + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab