Skip to content

Commit ca307ef

Browse files
jwhite510chrisbra
authored andcommitted
patch 9.1.1027: no sanitize check when running linematch
Problem: no sanitize check when running linematch Solution: add sanitize check before applying the linematch algorithm, similar to diff_find_change() (Jonathon) closes: #16446 Signed-off-by: Jonathon <jonathonwhite@protonmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 3a738fc commit ca307ef

File tree

4 files changed

+62
-10
lines changed

4 files changed

+62
-10
lines changed

src/diff.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,8 @@ diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus)
23512351
// Don't run linematch when lnum is offscreen. Useful for scrollbind
23522352
// calculations which need to count all the filler lines above the screen.
23532353
if (lnum >= wp->w_topline && lnum < wp->w_botline
2354-
&& !dp->is_linematched && diff_linematch(dp))
2354+
&& !dp->is_linematched && diff_linematch(dp)
2355+
&& diff_check_sanity(curtab, dp))
23552356
run_linematch_algorithm(dp);
23562357

23572358
if (dp->is_linematched)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
| +0#0000e05#a8a8a8255@1|a+0#0000000#5fd7ff255|b|c|d|q| @17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21
2+
| +0#0000e05#a8a8a8255@1|d+0#0000000#ffd7ff255|e|f| @19||+1&#ffffff0| +0#0000e05#a8a8a8255@1|d+0#0000000#ffd7ff255|e|f|q+2&#ff404010| +0&#ffd7ff255@17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21
3+
| +0#0000e05#a8a8a8255@1|h+0#0000000#ffd7ff255|i|j|k|l+2&#ff404010|m| +0&#ffd7ff255@16||+1&#ffffff0| +0#0000e05#a8a8a8255@1|h+0#0000000#ffd7ff255|i|j|k| @17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|h+0#0000000#ffd7ff255|i|j|k|l+2&#ff404010|m| +0&#ffd7ff255@15
4+
| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@22||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|n+0#0000000#ffd7ff255|o|p|q| @17||+1&#ffffff0| +0#0000e05#a8a8a8255@1|n+0#0000000#ffd7ff255|o|p|q|r+2&#ff404010| +0&#ffd7ff255@16
5+
| +0#0000e05#a8a8a8255@1> +0#0000000#ffd7ff255@22||+1&#ffffff0| +0#0000e05#a8a8a8255@1|-+0#4040ff13#afffff255@21||+1#0000000#ffffff0| +0#0000e05#a8a8a8255@1|s+2#0000000#ff404010|t|u|v| +0&#ffd7ff255@17
6+
|~+0#4040ff13#ffffff0| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
7+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
8+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
9+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
10+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
11+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
12+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
13+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
14+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
15+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
16+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
17+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
18+
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
19+
|<+3#0000000&|e|m|a|t|c|h|1| |[|+|]| |4|,|1| @5|A|l@1| |<+1&&|l|i|n|e|m|a|t|c|h|2| |3|,|1| @5|A|l@1| |<|l|i|n|e|m|a|t|c|h|3| |3|,|1| @5|A|l@1
20+
|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62

src/testdir/test_diffmode.vim

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ func CloseoffSetup()
12651265
call setline(1, ['one', 'tow', 'three'])
12661266
diffthis
12671267
call assert_equal(1, &diff)
1268-
only!
1268+
bw!
12691269
endfunc
12701270

12711271
func Test_diff_closeoff()
@@ -2529,7 +2529,8 @@ func Test_diffget_diffput_linematch()
25292529
call term_sendkeys(buf, "17gg")
25302530
call term_sendkeys(buf, ":diffput\<CR>")
25312531
call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {})
2532-
2532+
" clean up
2533+
call StopVimInTerminal(buf)
25332534
endfunc
25342535

25352536
func Test_linematch_diff()
@@ -2549,7 +2550,8 @@ func Test_linematch_diff()
25492550
\ 'abc d!',
25502551
\ 'd!'])
25512552
call VerifyScreenDump(buf, 'Test_linematch_diff1', {})
2552-
2553+
" clean up
2554+
call StopVimInTerminal(buf)
25532555
endfunc
25542556

25552557
func Test_linematch_diff_iwhite()
@@ -2575,7 +2577,8 @@ func Test_linematch_diff_iwhite()
25752577
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
25762578
call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>")
25772579
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {})
2578-
2580+
" clean up
2581+
call StopVimInTerminal(buf)
25792582
endfunc
25802583

25812584
func Test_linematch_diff_grouping()
@@ -2612,7 +2615,8 @@ func Test_linematch_diff_grouping()
26122615
\ '?C',
26132616
\ '?C'])
26142617
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {})
2615-
2618+
" clean up
2619+
call StopVimInTerminal(buf)
26162620
endfunc
26172621

26182622
func Test_linematch_diff_scroll()
@@ -2643,11 +2647,10 @@ func Test_linematch_diff_scroll()
26432647
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
26442648
call term_sendkeys(buf, "3\<c-e>")
26452649
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {})
2646-
2650+
" clean up
2651+
call StopVimInTerminal(buf)
26472652
endfunc
26482653

2649-
2650-
26512654
func Test_linematch_line_limit_exceeded()
26522655
CheckScreendump
26532656
call delete('.Xdifile1.swp')
@@ -2694,7 +2697,8 @@ func Test_linematch_line_limit_exceeded()
26942697
" alignment algorithm will run on the largest diff block here
26952698
call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
26962699
call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {})
2697-
2700+
" clean up
2701+
call StopVimInTerminal(buf)
26982702
endfunc
26992703

27002704
func Test_linematch_3diffs()
@@ -2731,6 +2735,31 @@ func Test_linematch_3diffs()
27312735
\ " BBB",
27322736
\ " BBB"])
27332737
call VerifyScreenDump(buf, 'Test_linematch_3diffs1', {})
2738+
" clean up
2739+
call StopVimInTerminal(buf)
2740+
endfunc
27342741

2742+
" this used to access invalid memory
2743+
func Test_linematch_3diffs_sanity_check()
2744+
CheckScreendump
2745+
call delete('.Xfile_linematch1.swp')
2746+
call delete('.Xfile_linematch2.swp')
2747+
call delete('.Xfile_linematch3.swp')
2748+
let lines =<< trim END
2749+
set diffopt+=linematch:60
2750+
call feedkeys("Aq\<esc>")
2751+
call feedkeys("GAklm\<esc>")
2752+
call feedkeys("o")
2753+
END
2754+
call writefile(lines, 'Xlinematch_3diffs.vim', 'D')
2755+
call writefile(['abcd', 'def', 'hij'], 'Xfile_linematch1', 'D')
2756+
call writefile(['defq', 'hijk', 'nopq'], 'Xfile_linematch2', 'D')
2757+
call writefile(['hijklm', 'nopqr', 'stuv'], 'Xfile_linematch3', 'D')
2758+
call WriteDiffFiles3(0, [], [], [])
2759+
let buf = RunVimInTerminal('-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3', {})
2760+
call VerifyScreenDump(buf, 'Test_linematch_3diffs2', {})
2761+
2762+
" clean up
2763+
call StopVimInTerminal(buf)
27352764
endfunc
27362765
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1027,
707709
/**/
708710
1026,
709711
/**/

0 commit comments

Comments
 (0)