]> granicus.if.org Git - vim/commitdiff
patch 8.0.1397: pattern with \& following nothing gives an error v8.0.1397
authorBram Moolenaar <Bram@vim.org>
Sat, 16 Dec 2017 18:59:37 +0000 (19:59 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 16 Dec 2017 18:59:37 +0000 (19:59 +0100)
Problem:    Pattern with \& following nothing gives an error.
Solution:   Emit an empty node when needed.

src/regexp_nfa.c
src/testdir/test_search.vim
src/version.c

index feb17bcaf57bf91872b55ff6740547c2f2e565f9..afd42383cf8fa0caf0956e221a8f0190cf9cfa83 100644 (file)
@@ -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 */
index d13e65458e3747ca2a42f012733a4a6e89af9492..cb65fbf0ba7d6e598ec093b7ac246336af570fb7 100644 (file)
@@ -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
index 224118a11dc34bcca325781f8e5609e4108ca2db..096d21c9931742e36779b2b590a3a7e935457f9c 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1397,
 /**/
     1396,
 /**/