patch 9.2.0285: :syn sync grouphere may go beyond end of line
Commit:
https://github.com/vim/vim/commit/b7cffc84340d6c141fb8f7dbe771c4c15dcc47d4
Author: zeertzjq <
zeer...@outlook.com>
Date: Fri Apr 3 08:30:40 2026 +0000
patch 9.2.0285: :syn sync grouphere may go beyond end of line
Problem: :syn sync grouphere may go beyond end of line.
Solution: Start searching for the end of region at the end of match
instead of a possibly invalid position (zeertzjq).
closes: #19896
Signed-off-by: zeertzjq <
zeer...@outlook.com>
Signed-off-by: Christian Brabandt <
c...@256bit.org>
diff --git a/src/syntax.c b/src/syntax.c
index ed4c1225f..c845a1051 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -595,7 +595,7 @@ syn_sync(
int found_flags = 0;
int found_match_idx = 0;
linenr_T found_current_lnum = 0;
- int found_current_col= 0;
+ int found_current_col = 0;
lpos_T found_m_endpos;
colnr_T prev_current_col;
@@ -817,6 +817,8 @@ syn_sync(
*/
if (found_flags & HL_SYNC_HERE)
{
+ current_lnum = found_m_endpos.lnum;
+ current_col = found_m_endpos.col;
if (current_state.ga_len)
{
cur_si = &CUR_STATE(current_state.ga_len - 1);
@@ -825,8 +827,6 @@ syn_sync(
update_si_end(cur_si, (int)current_col, TRUE);
check_keepend();
}
- current_col = found_m_endpos.col;
- current_lnum = found_m_endpos.lnum;
(void)syn_finish_line(FALSE);
++current_lnum;
}
diff --git a/src/testdir/test_syntax.vim b/src/testdir/test_syntax.vim
index e4d46911d..27f2efc2c 100644
--- a/src/testdir/test_syntax.vim
+++ b/src/testdir/test_syntax.vim
@@ -988,5 +988,30 @@ func Test_WinEnter_synstack_synID()
bw!
endfunc
+" This was going beyond the end of the "foo" line
+func Test_syn_sync_grouphere_shorter_next_line()
+ let lines =<< trim END
+ if [[ "$var1" == 1 ]]; then
+ foo
+ else
+ bar
+ fi
+ END
+ let lines = ['a']->repeat(50) + lines + ['a']->repeat(28 + winheight(0))
+
+ new
+ call setline(1, lines)
+ syn region shIf transparent
+ \ start="\<if\_s" skip=+-fi\>+ end="\<;\_s*then\>" end="\<fi\>"
+ syn sync minlines=20 maxlines=40
+ syn sync match shIfSync grouphere shIf "\<if\>"
+ redraw!
+
+ normal! G
+ " Should not go beyond end of line
+ redraw!
+
+ bw!
+endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index ebb473294..ce87898c7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 285,
/**/
284,
/**/