From 890dd05492d88d48eee1dda7f7a1811d027ce7ca Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Sat, 16 Dec 2017 19:59:37 +0100 Subject: [PATCH] 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. --- src/regexp_nfa.c | 8 ++++---- src/testdir/test_search.vim | 8 ++++++++ src/version.c | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c index feb17bcaf..afd42383c 100644 --- a/src/regexp_nfa.c +++ b/src/regexp_nfa.c @@ -2321,7 +2321,6 @@ nfa_regconcat(void) static int nfa_regbranch(void) { - int ch; int old_post_pos; old_post_pos = (int)(post_ptr - post_start); @@ -2330,11 +2329,13 @@ nfa_regbranch(void) if (nfa_regconcat() == FAIL) return FAIL; - ch = peekchr(); /* Try next concats */ - while (ch == Magic('&')) + while (peekchr() == Magic('&')) { skipchr(); + /* if concat is empty do emit a node */ + if (old_post_pos == (int)(post_ptr - post_start)) + EMIT(NFA_EMPTY); EMIT(NFA_NOPEN); EMIT(NFA_PREV_ATOM_NO_WIDTH); old_post_pos = (int)(post_ptr - post_start); @@ -2344,7 +2345,6 @@ nfa_regbranch(void) if (old_post_pos == (int)(post_ptr - post_start)) EMIT(NFA_EMPTY); EMIT(NFA_CONCAT); - ch = peekchr(); } /* if a branch is empty, emit one node for it */ diff --git a/src/testdir/test_search.vim b/src/testdir/test_search.vim index d13e65458..cb65fbf0b 100644 --- a/src/testdir/test_search.vim +++ b/src/testdir/test_search.vim @@ -721,3 +721,11 @@ func Test_search_multibyte() enew! let &encoding = save_enc endfunc + +" This was causing E874. Also causes an invalid read? +func Test_look_behind() + new + call setline(1, '0\|\&\n\@<=') + call search(getline(".")) + bwipe! +endfunc diff --git a/src/version.c b/src/version.c index 224118a11..096d21c99 100644 --- a/src/version.c +++ b/src/version.c @@ -771,6 +771,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1397, /**/ 1396, /**/ -- 2.50.1