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.
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index feb17bc..afd4238 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -2321,7 +2321,6 @@
static int
nfa_regbranch(void)
{
- int ch;
int old_post_pos;
old_post_pos = (int)(post_ptr - post_start);
@@ -2330,11 +2329,13 @@
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 @@
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 */