summaryrefslogtreecommitdiff
path: root/src/regexp.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-06-17 20:08:20 +0200
committerBram Moolenaar <Bram@vim.org>2017-06-17 20:08:20 +0200
commit1ef9bbe215e13a273e74fccaddd8fc5a42c76b6e (patch)
treee7e91f215db3694732b431b3ff76eaa6008827d2 /src/regexp.c
parent5b1affefd0e96154517ec6f71300086ae6d22d24 (diff)
downloadvim-git-1ef9bbe215e13a273e74fccaddd8fc5a42c76b6e.tar.gz
patch 8.0.0645: no error for illegal back reference in NFA enginev8.0.0645
Problem: The new regexp engine does not give an error for using a back reference where it is not allowed. (Dominique Pelle) Solution: Check the back reference like the old engine. (closes #1774)
Diffstat (limited to 'src/regexp.c')
-rw-r--r--src/regexp.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/src/regexp.c b/src/regexp.c
index 74a73c440..7304bd349 100644
--- a/src/regexp.c
+++ b/src/regexp.c
@@ -1294,6 +1294,34 @@ skip_regexp(
return p;
}
+/*
+ * Return TRUE if the back reference is legal. We must have seen the close
+ * brace.
+ * TODO: Should also check that we don't refer to something that is repeated
+ * (+*=): what instance of the repetition should we match?
+ */
+ static int
+seen_endbrace(int refnum)
+{
+ if (!had_endbrace[refnum])
+ {
+ char_u *p;
+
+ /* Trick: check if "@<=" or "@<!" follows, in which case
+ * the \1 can appear before the referenced match. */
+ for (p = regparse; *p != NUL; ++p)
+ if (p[0] == '@' && p[1] == '<' && (p[2] == '!' || p[2] == '='))
+ break;
+ if (*p == NUL)
+ {
+ EMSG(_("E65: Illegal back reference"));
+ rc_did_emsg = TRUE;
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
static regprog_T *bt_regcomp(char_u *expr, int re_flags);
static void bt_regfree(regprog_T *prog);
@@ -2099,24 +2127,8 @@ regatom(int *flagp)
int refnum;
refnum = c - Magic('0');
- /*
- * Check if the back reference is legal. We must have seen the
- * close brace.
- * TODO: Should also check that we don't refer to something
- * that is repeated (+*=): what instance of the repetition
- * should we match?
- */
- if (!had_endbrace[refnum])
- {
- /* Trick: check if "@<=" or "@<!" follows, in which case
- * the \1 can appear before the referenced match. */
- for (p = regparse; *p != NUL; ++p)
- if (p[0] == '@' && p[1] == '<'
- && (p[2] == '!' || p[2] == '='))
- break;
- if (*p == NUL)
- EMSG_RET_NULL(_("E65: Illegal back reference"));
- }
+ if (!seen_endbrace(refnum))
+ return NULL;
ret = regnode(BACKREF + refnum);
}
break;