@@ -3022,6 +3022,8 @@ find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos,
30223022 if (r && regmatch .startpos [0 ].col
30233023 <= best_regmatch .startpos [0 ].col )
30243024 {
3025+ int line_len ;
3026+
30253027 /* Add offset to skip pattern match */
30263028 syn_add_end_off (& pos , & regmatch , spp_skip , SPO_ME_OFF , 1 );
30273029
@@ -3031,6 +3033,7 @@ find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos,
30313033 break ;
30323034
30333035 line = ml_get_buf (syn_buf , startpos -> lnum , FALSE);
3036+ line_len = (int )STRLEN (line );
30343037
30353038 /* take care of an empty match or negative offset */
30363039 if (pos .col <= matchcol )
@@ -3040,12 +3043,12 @@ find_endpos(idx, startpos, m_endpos, hl_endpos, flagsp, end_endpos,
30403043 else
30413044 /* Be careful not to jump over the NUL at the end-of-line */
30423045 for (matchcol = regmatch .endpos [0 ].col ;
3043- line [ matchcol ] != NUL && matchcol < pos .col ;
3046+ matchcol < line_len && matchcol < pos .col ;
30443047 ++ matchcol )
30453048 ;
30463049
30473050 /* if the skip pattern includes end-of-line, break here */
3048- if (line [ matchcol ] == NUL )
3051+ if (matchcol >= line_len )
30493052 break ;
30503053
30513054 continue ; /* start with first end pattern again */
0 commit comments