Skip to content

Commit 46e22fd

Browse files
zeertzjqchrisbra
authored andcommitted
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>
1 parent 1e7a288 commit 46e22fd

4 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,8 @@ diff_write(buf_T *buf, diffin_T *din, linenr_T start, linenr_T end)
917917
cmdmod.cmod_flags = save_cmod_flags;
918918
free_string_option(buf->b_p_ff);
919919
buf->b_p_ff = save_ff;
920-
buf->b_ml.ml_flags = save_ml_flags;
920+
buf->b_ml.ml_flags =
921+
(buf->b_ml.ml_flags & ~ML_EMPTY) | (save_ml_flags & ML_EMPTY);
921922
return r;
922923
}
923924

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0#0000e05#a8a8a8255@1>f+0#0000000#ffff4012|o@1| @69
2+
| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|r| @69
3+
| +0#0000e05#a8a8a8255@1|b+0#0000000#5fd7ff255|a|z| @69
4+
|~+0#4040ff13#ffffff0| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|X+3#0000000&|d|i|f@1|s|p|l|i|t|_|f|i|l|e| @41|1|,|1| @11|A|l@1
11+
| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@72
12+
| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@72
13+
| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@72
14+
| +0#0000e05#a8a8a8255@1| +0#0000000#ffffff0@72
15+
|~+0#4040ff13&| @73
16+
|~| @73
17+
|~| @73
18+
|~| @73
19+
|[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
20+
|"+0&&|X|d|i|f@1|s|p|l|i|t|_|f|i|l|e|"| |3|L|,| |1|2|B| @49

src/testdir/test_diffmode.vim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3541,4 +3541,29 @@ func Test_diffget_diffput_diffanchors()
35413541
set diffanchors&
35423542
endfunc
35433543

3544+
func Test_diff_add_prop_in_autocmd()
3545+
CheckScreendump
3546+
3547+
let lines =<< trim END
3548+
func MyDiff() abort
3549+
let f1 = readfile(v:fname_in)
3550+
let f2 = readfile(v:fname_new)
3551+
let f0 = diff(f1, f2)
3552+
call writefile(split(f0, "\n"), v:fname_out)
3553+
endfunc
3554+
3555+
call prop_type_add('myprop', #{highlight: 'Search', override: 1})
3556+
autocmd OptionSet diff call prop_add(1, 1, #{type: 'myprop', length: 100})
3557+
set diffexpr=MyDiff()
3558+
END
3559+
call writefile(lines, 'Xtest_diff_add_prop_in_autocmd', 'D')
3560+
call writefile(['foo', 'bar', 'baz'], 'Xdiffsplit_file', 'D')
3561+
3562+
let buf = RunVimInTerminal('-S Xtest_diff_add_prop_in_autocmd', {})
3563+
call term_sendkeys(buf, ":diffsplit Xdiffsplit_file\<CR>")
3564+
call VerifyScreenDump(buf, 'Test_diff_add_prop_in_autocmd_01', {})
3565+
3566+
call StopVimInTerminal(buf)
3567+
endfunc
3568+
35443569
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ static char *(features[]) =
724724

725725
static int included_patches[] =
726726
{ /* Add new patch number below this line */
727+
/**/
728+
1758,
727729
/**/
728730
1757,
729731
/**/

0 commit comments

Comments
 (0)