]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1758: Diff mode crashes when adding text property in autocommand v9.1.1758
authorzeertzjq <zeertzjq@outlook.com>
Sun, 14 Sep 2025 15:01:26 +0000 (11:01 -0400)
committerChristian Brabandt <cb@256bit.org>
Sun, 14 Sep 2025 15:01:26 +0000 (11:01 -0400)
Problem:  Diff mode crashes when adding text property in autocommand
          (after 9.1.1557).
Solution: Only restore ML_EMPTY memline flag, ignore the others
          (zeertzjq).

fixes: #18288
closes: #18291

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/diff.c
src/testdir/dumps/Test_diff_add_prop_in_autocmd_01.dump [new file with mode: 0644]
src/testdir/test_diffmode.vim
src/version.c

index 1a60ee7aee3d324cdf00ae2903b9ad07dc5d8b01..25b9ae977b1a582653c06493a1190b4ae903f3cb 100644 (file)
@@ -917,7 +917,8 @@ diff_write(buf_T *buf, diffin_T *din, linenr_T start, linenr_T end)
     cmdmod.cmod_flags = save_cmod_flags;
     free_string_option(buf->b_p_ff);
     buf->b_p_ff = save_ff;
-    buf->b_ml.ml_flags = save_ml_flags;
+    buf->b_ml.ml_flags =
+               (buf->b_ml.ml_flags & ~ML_EMPTY) | (save_ml_flags & ML_EMPTY);
     return r;
 }
 
diff --git a/src/testdir/dumps/Test_diff_add_prop_in_autocmd_01.dump b/src/testdir/dumps/Test_diff_add_prop_in_autocmd_01.dump
new file mode 100644 (file)
index 0000000..88aa421
--- /dev/null
@@ -0,0 +1,20 @@
+| +0#0000e05#a8a8a8255@1>f+0#0000000#ffff4012|o@1| @69
+| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|r| @69
+| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|z| @69
+|~+0#4040ff13#ffffff0| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|X+3#0000000&|d|i|f@1|s|p|l|i|t|_|f|i|l|e| @41|1|,|1| @11|A|l@1
+| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@72
+| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@72
+| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@72
+| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@72
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+|"+0&&|X|d|i|f@1|s|p|l|i|t|_|f|i|l|e|"| |3|L|,| |1|2|B| @49
index 42f9463b31bb35f1abae250bf530c38b22e1f53c..340397a27bce735afd8be5276ee29044dbc3edbc 100644 (file)
@@ -3541,4 +3541,29 @@ func Test_diffget_diffput_diffanchors()
   set diffanchors&
 endfunc
 
+func Test_diff_add_prop_in_autocmd()
+  CheckScreendump
+
+  let lines =<< trim END
+    func MyDiff() abort
+      let f1 = readfile(v:fname_in)
+      let f2 = readfile(v:fname_new)
+      let f0 = diff(f1, f2)
+      call writefile(split(f0, "\n"), v:fname_out)
+    endfunc
+
+    call prop_type_add('myprop', #{highlight: 'Search', override: 1})
+    autocmd OptionSet diff call prop_add(1, 1, #{type: 'myprop', length: 100})
+    set diffexpr=MyDiff()
+  END
+  call writefile(lines, 'Xtest_diff_add_prop_in_autocmd', 'D')
+  call writefile(['foo', 'bar', 'baz'], 'Xdiffsplit_file', 'D')
+
+  let buf = RunVimInTerminal('-S Xtest_diff_add_prop_in_autocmd', {})
+  call term_sendkeys(buf, ":diffsplit Xdiffsplit_file\<CR>")
+  call VerifyScreenDump(buf, 'Test_diff_add_prop_in_autocmd_01', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 51079ce760a2457c6b7c3f8611ab58fe71faf90f..e550f2f47962f3d94a60c1872402c66e81bcb0eb 100644 (file)
@@ -724,6 +724,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1758,
 /**/
     1757,
 /**/