]> granicus.if.org Git - vim/commitdiff
patch 8.2.3950: going beyond the end of the line with /\%V v8.2.3950
authorBram Moolenaar <Bram@vim.org>
Thu, 30 Dec 2021 15:29:18 +0000 (15:29 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 30 Dec 2021 15:29:18 +0000 (15:29 +0000)
Problem:    Going beyond the end of the line with /\%V.
Solution:   Check for valid column in getvcol().

src/charset.c
src/testdir/test_regexp_latin.vim
src/version.c

index 31b03eb38a15a342023f36f2b9037458a9d734ab..d762a2545bf0a52e393ea2f8b3f61824bfa0fc28 100644 (file)
@@ -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
index 03efdbea30e6316a5efd0f715844ca6a8483c407..f936549e7aab8b50000d1f91a6e8e6a0784d4fce 100644 (file)
@@ -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
index 9f5ed308a1f258460dc005a2202ae6c87778b8d9..56d900dc2c06756657925cf2c5242cfd9b9cae64 100644 (file)
@@ -749,6 +749,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3950,
 /**/
     3949,
 /**/