]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1027: no sanitize check when running linematch v9.1.1027
authorJonathon <jonathonwhite@protonmail.com>
Fri, 17 Jan 2025 12:37:35 +0000 (13:37 +0100)
committerChristian Brabandt <cb@256bit.org>
Fri, 17 Jan 2025 12:37:35 +0000 (13:37 +0100)
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>
src/diff.c
src/testdir/dumps/Test_linematch_3diffs2.dump [new file with mode: 0644]
src/testdir/test_diffmode.vim
src/version.c

index c348894ec946f2478723ab3a2e4b4b8e6444fc47..41d61b1b569d22b09d521cede32ada7164943ff4 100644 (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
     // calculations which need to count all the filler lines above the screen.
     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);
 
     if (dp->is_linematched)
diff --git a/src/testdir/dumps/Test_linematch_3diffs2.dump b/src/testdir/dumps/Test_linematch_3diffs2.dump
new file mode 100644 (file)
index 0000000..3a333e6
--- /dev/null
@@ -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
index 8939bb80c37b0902281fb45827333cfcd31039e0..36d3d9ba6539eb7a43ca19b1b6d0f12bb1cd1418 100644 (file)
@@ -1265,7 +1265,7 @@ func CloseoffSetup()
   call setline(1, ['one', 'tow', 'three'])
   diffthis
   call assert_equal(1, &diff)
-  only!
+  bw!
 endfunc
 
 func Test_diff_closeoff()
@@ -2529,7 +2529,8 @@ func Test_diffget_diffput_linematch()
   call term_sendkeys(buf, "17gg")
   call term_sendkeys(buf, ":diffput\<CR>")
   call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {})
-
+  " clean up
+  call StopVimInTerminal(buf)
 endfunc
 
 func Test_linematch_diff()
@@ -2549,7 +2550,8 @@ func Test_linematch_diff()
       \ 'abc d!',
       \ 'd!'])
   call VerifyScreenDump(buf, 'Test_linematch_diff1', {})
-
+  " clean up
+  call StopVimInTerminal(buf)
 endfunc
 
 func Test_linematch_diff_iwhite()
@@ -2575,7 +2577,8 @@ func Test_linematch_diff_iwhite()
   call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
   call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>")
   call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {})
-
+  " clean up
+  call StopVimInTerminal(buf)
 endfunc
 
 func Test_linematch_diff_grouping()
@@ -2612,7 +2615,8 @@ func Test_linematch_diff_grouping()
       \ '?C',
       \ '?C'])
   call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {})
-
+  " clean up
+  call StopVimInTerminal(buf)
 endfunc
 
 func Test_linematch_diff_scroll()
@@ -2643,11 +2647,10 @@ func Test_linematch_diff_scroll()
   call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
   call term_sendkeys(buf, "3\<c-e>")
   call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {})
-
+  " clean up
+  call StopVimInTerminal(buf)
 endfunc
 
-
-
 func Test_linematch_line_limit_exceeded()
   CheckScreendump
   call delete('.Xdifile1.swp')
@@ -2694,7 +2697,8 @@ func Test_linematch_line_limit_exceeded()
   " alignment algorithm will run on the largest diff block here
   call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
   call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {})
-
+  " clean up
+  call StopVimInTerminal(buf)
 endfunc
 
 func Test_linematch_3diffs()
@@ -2731,6 +2735,31 @@ func Test_linematch_3diffs()
         \ "      BBB",
         \ "      BBB"])
   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
 " vim: shiftwidth=2 sts=2 expandtab
index 46c4818b1cbe36eb17d89d7d70ff368c7d78e907..d6b73fd79237d33bc0307642d15d616b2692fd48 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1027,
 /**/
     1026,
 /**/