Skip to content

Commit 890dd05

Browse files
committed
patch 8.0.1397: pattern with \& following nothing gives an error
Problem: Pattern with \& following nothing gives an error. Solution: Emit an empty node when needed.
1 parent a1d5c15 commit 890dd05

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/regexp_nfa.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,7 +2321,6 @@ nfa_regconcat(void)
23212321
static int
23222322
nfa_regbranch(void)
23232323
{
2324-
int ch;
23252324
int old_post_pos;
23262325

23272326
old_post_pos = (int)(post_ptr - post_start);
@@ -2330,11 +2329,13 @@ nfa_regbranch(void)
23302329
if (nfa_regconcat() == FAIL)
23312330
return FAIL;
23322331

2333-
ch = peekchr();
23342332
/* Try next concats */
2335-
while (ch == Magic('&'))
2333+
while (peekchr() == Magic('&'))
23362334
{
23372335
skipchr();
2336+
/* if concat is empty do emit a node */
2337+
if (old_post_pos == (int)(post_ptr - post_start))
2338+
EMIT(NFA_EMPTY);
23382339
EMIT(NFA_NOPEN);
23392340
EMIT(NFA_PREV_ATOM_NO_WIDTH);
23402341
old_post_pos = (int)(post_ptr - post_start);
@@ -2344,7 +2345,6 @@ nfa_regbranch(void)
23442345
if (old_post_pos == (int)(post_ptr - post_start))
23452346
EMIT(NFA_EMPTY);
23462347
EMIT(NFA_CONCAT);
2347-
ch = peekchr();
23482348
}
23492349

23502350
/* if a branch is empty, emit one node for it */

src/testdir/test_search.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,3 +721,11 @@ func Test_search_multibyte()
721721
enew!
722722
let &encoding = save_enc
723723
endfunc
724+
725+
" This was causing E874. Also causes an invalid read?
726+
func Test_look_behind()
727+
new
728+
call setline(1, '0\|\&\n\@<=')
729+
call search(getline("."))
730+
bwipe!
731+
endfunc

src/version.c

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

772772
static int included_patches[] =
773773
{ /* Add new patch number below this line */
774+
/**/
775+
1397,
774776
/**/
775777
1396,
776778
/**/

0 commit comments

Comments
 (0)