summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-12-30 15:29:18 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-30 15:29:18 +0000
commit94f3192b03ed27474db80b4d3a409e107140738b (patch)
tree0072263578a64fc1ca12eca38d3a923fb73273e0
parent4c13e5e6763c6eb36a343a2b8235ea227202e952 (diff)
patch 8.2.3950: going beyond the end of the line with /\%Vv8.2.3950
Problem: Going beyond the end of the line with /\%V. Solution: Check for valid column in getvcol().
-rw-r--r--src/charset.c13
-rw-r--r--src/testdir/test_regexp_latin.vim8
-rw-r--r--src/version.c2
3 files changed, 19 insertions, 4 deletions
diff --git a/src/charset.c b/src/charset.c
index 31b03eb38a..d762a2545b 100644
--- 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
index 03efdbea30..f936549e7a 100644
--- 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
diff --git a/src/version.c b/src/version.c
index 9f5ed308a1..56d900dc2c 100644
--- 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,