0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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>
This commit is contained in:
Jonathon 2025-01-17 13:37:35 +01:00 committed by Christian Brabandt
parent 3a738fccaa
commit ca307efe48
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
4 changed files with 62 additions and 10 deletions

View File

@ -2351,7 +2351,8 @@ diff_check_with_linestatus(win_T *wp, linenr_T lnum, int *linestatus)
// Don't run linematch when lnum is offscreen. Useful for scrollbind // Don't run linematch when lnum is offscreen. Useful for scrollbind
// calculations which need to count all the filler lines above the screen. // calculations which need to count all the filler lines above the screen.
if (lnum >= wp->w_topline && lnum < wp->w_botline if (lnum >= wp->w_topline && lnum < wp->w_botline
&& !dp->is_linematched && diff_linematch(dp)) && !dp->is_linematched && diff_linematch(dp)
&& diff_check_sanity(curtab, dp))
run_linematch_algorithm(dp); run_linematch_algorithm(dp);
if (dp->is_linematched) if (dp->is_linematched)

View File

@ -0,0 +1,20 @@
| +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
| +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
| +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
| +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
| +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
|~+0#4040ff13#ffffff0| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|~| @23||+1#0000000&|~+0#4040ff13&| @22||+1#0000000&|~+0#4040ff13&| @22
|<+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
|-+2&&@1| |I|N|S|E|R|T| |-@1| +0&&@62

View File

@ -1265,7 +1265,7 @@ func CloseoffSetup()
call setline(1, ['one', 'tow', 'three']) call setline(1, ['one', 'tow', 'three'])
diffthis diffthis
call assert_equal(1, &diff) call assert_equal(1, &diff)
only! bw!
endfunc endfunc
func Test_diff_closeoff() func Test_diff_closeoff()
@ -2529,7 +2529,8 @@ func Test_diffget_diffput_linematch()
call term_sendkeys(buf, "17gg") call term_sendkeys(buf, "17gg")
call term_sendkeys(buf, ":diffput\<CR>") call term_sendkeys(buf, ":diffput\<CR>")
call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {}) call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
func Test_linematch_diff() func Test_linematch_diff()
@ -2549,7 +2550,8 @@ func Test_linematch_diff()
\ 'abc d!', \ 'abc d!',
\ 'd!']) \ 'd!'])
call VerifyScreenDump(buf, 'Test_linematch_diff1', {}) call VerifyScreenDump(buf, 'Test_linematch_diff1', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
func Test_linematch_diff_iwhite() func Test_linematch_diff_iwhite()
@ -2575,7 +2577,8 @@ func Test_linematch_diff_iwhite()
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {}) call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>") call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>")
call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {}) call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
func Test_linematch_diff_grouping() func Test_linematch_diff_grouping()
@ -2612,7 +2615,8 @@ func Test_linematch_diff_grouping()
\ '?C', \ '?C',
\ '?C']) \ '?C'])
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {}) call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
func Test_linematch_diff_scroll() func Test_linematch_diff_scroll()
@ -2643,11 +2647,10 @@ func Test_linematch_diff_scroll()
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {}) call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
call term_sendkeys(buf, "3\<c-e>") call term_sendkeys(buf, "3\<c-e>")
call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {}) call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
func Test_linematch_line_limit_exceeded() func Test_linematch_line_limit_exceeded()
CheckScreendump CheckScreendump
call delete('.Xdifile1.swp') call delete('.Xdifile1.swp')
@ -2694,7 +2697,8 @@ func Test_linematch_line_limit_exceeded()
" alignment algorithm will run on the largest diff block here " alignment algorithm will run on the largest diff block here
call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>") call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {}) call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
func Test_linematch_3diffs() func Test_linematch_3diffs()
@ -2731,6 +2735,31 @@ func Test_linematch_3diffs()
\ " BBB", \ " BBB",
\ " BBB"]) \ " BBB"])
call VerifyScreenDump(buf, 'Test_linematch_3diffs1', {}) call VerifyScreenDump(buf, 'Test_linematch_3diffs1', {})
" clean up
call StopVimInTerminal(buf)
endfunc
" this used to access invalid memory
func Test_linematch_3diffs_sanity_check()
CheckScreendump
call delete('.Xfile_linematch1.swp')
call delete('.Xfile_linematch2.swp')
call delete('.Xfile_linematch3.swp')
let lines =<< trim END
set diffopt+=linematch:60
call feedkeys("Aq\<esc>")
call feedkeys("GAklm\<esc>")
call feedkeys("o")
END
call writefile(lines, 'Xlinematch_3diffs.vim', 'D')
call writefile(['abcd', 'def', 'hij'], 'Xfile_linematch1', 'D')
call writefile(['defq', 'hijk', 'nopq'], 'Xfile_linematch2', 'D')
call writefile(['hijklm', 'nopqr', 'stuv'], 'Xfile_linematch3', 'D')
call WriteDiffFiles3(0, [], [], [])
let buf = RunVimInTerminal('-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3', {})
call VerifyScreenDump(buf, 'Test_linematch_3diffs2', {})
" clean up
call StopVimInTerminal(buf)
endfunc endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@ -704,6 +704,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 */
/**/
1027,
/**/ /**/
1026, 1026,
/**/ /**/