]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1189: invalid memory access with folding and using "L" v9.0.1189
authorBram Moolenaar <Bram@vim.org>
Fri, 13 Jan 2023 14:17:58 +0000 (14:17 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 13 Jan 2023 14:17:58 +0000 (14:17 +0000)
Problem:    Invalid memory access with folding and using "L".
Solution:   Prevent the cursor from moving to line zero.

src/normal.c
src/testdir/test_fold.vim
src/version.c

index c319be599ad7df552400e6ff874a54244bd712e4..3d9f74dec558e07cf53733503bec56131d895b17 100644 (file)
@@ -3729,7 +3729,8 @@ nv_scroll(cmdarg_T *cap)
                {
                    (void)hasFolding(curwin->w_cursor.lnum,
                                                &curwin->w_cursor.lnum, NULL);
-                   --curwin->w_cursor.lnum;
+                   if (curwin->w_cursor.lnum > curwin->w_topline)
+                       --curwin->w_cursor.lnum;
                }
            }
            else
index adf9e52078383a801d8a72980eb9f4ba2d324fd3..f915a661336b4998d62fc6ee40c5e0bfb1ddf467 100644 (file)
@@ -1675,4 +1675,12 @@ func Test_sort_closed_fold()
   bwipe!
 endfunc
 
+func Test_indent_with_L_command()
+  " The "L" command moved the cursor to line zero, causing the text saved for
+  " undo to use line number -1, which caused trouble for undo later.
+  new
+  sil! norm 8R\r\ 3V{zf8=Lu
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 1d81e7b6fd3d8ad59fc10a4f1892f97322237989..64f7d887bed7b16418da7381a3cca3fd406e2303 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1189,
 /**/
     1188,
 /**/