]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0101: invalid memory access in diff mode with "dp" and undo v9.0.0101
authorBram Moolenaar <Bram@vim.org>
Thu, 28 Jul 2022 17:44:27 +0000 (18:44 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 28 Jul 2022 17:44:27 +0000 (18:44 +0100)
Problem:    Invalid memory access in diff mode with "dp" and undo.
Solution:   Make sure the line number does not go below one.

src/diff.c
src/testdir/test_diffmode.vim
src/version.c

index e4bafe2c934e24f30d8f52e85940b959ffecec41..fb43eee844cd89a5aa7f01280c9e82396a570027 100644 (file)
@@ -464,7 +464,10 @@ diff_mark_adjust_tp(
                    for (i = 0; i < DB_COUNT; ++i)
                        if (tp->tp_diffbuf[i] != NULL && i != idx)
                        {
-                           dp->df_lnum[i] -= off;
+                           if (dp->df_lnum[i] > off)
+                               dp->df_lnum[i] -= off;
+                           else
+                               dp->df_lnum[i] = 1;
                            dp->df_count[i] += n;
                        }
                }
@@ -2863,8 +2866,8 @@ ex_diffgetput(exarg_T *eap)
            {
                // remember deleting the last line of the buffer
                buf_empty = curbuf->b_ml.ml_line_count == 1;
-               ml_delete(lnum);
-               --added;
+               if (ml_delete(lnum) == OK)
+                   --added;
            }
            for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i)
            {
index dcacd5516bb7dff0f3b839d56834a6721ecd8b6e..41f7fe3493ca5b287d8029f1a4f9d6fabd868da1 100644 (file)
@@ -1628,5 +1628,19 @@ func Test_diff_manipulations()
   %bwipe!
 endfunc
 
+" This was causing the line number in the diff block to go below one.
+" FIXME: somehow this causes a valgrind error when run directly but not when
+" run as a test.
+func Test_diff_put_and_undo()
+  set diff
+  next 0
+  split 00
+  sil! norm o0\egguudpo0\eggJuudp
+
+  bwipe!
+  bwipe!
+  set nodiff
+endfunc
+
 
 " vim: shiftwidth=2 sts=2 expandtab
index 9e682a5fd6357187d70494d00e6bb78283373c8b..1241e98b08b0f4e2aa899a00a9db9095259d0e00 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    101,
 /**/
     100,
 /**/