patch 9.1.1758: Diff mode crashes when adding text property in autocommand

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>
This commit is contained in:
zeertzjq
2025-09-14 11:01:26 -04:00
committed by Christian Brabandt
parent 1e7a288cd3
commit 46e22fd2f7
4 changed files with 49 additions and 1 deletions

View 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; cmdmod.cmod_flags = save_cmod_flags;
free_string_option(buf->b_p_ff); free_string_option(buf->b_p_ff);
buf->b_p_ff = save_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; return r;
} }

View File

@ -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

View File

@ -3541,4 +3541,29 @@ func Test_diffget_diffput_diffanchors()
%bw! %bw!
set diffopt& set diffopt&
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) call StopVimInTerminal(buf)

View File

@ -724,6 +724,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1758,
/**/ /**/
1757, 1757,
/**/ /**/