summaryrefslogtreecommitdiff
path: root/src/regexp_nfa.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-12-09 16:36:04 +0100
committerBram Moolenaar <Bram@vim.org>2020-12-09 16:36:04 +0100
commita7a691cc142439e266f4ceb1f208bb952b57aa71 (patch)
treeebe600566e203253e7f6f2502c3032c2608c32ec /src/regexp_nfa.c
parent730677a0dafe6f2e72888ef59f74f66f2d0a573e (diff)
downloadvim-git-a7a691cc142439e266f4ceb1f208bb952b57aa71.tar.gz
patch 8.2.2121: internal error when using \ze before \zs in a patternv8.2.2121
Problem: Internal error when using \ze before \zs in a pattern. Solution: Check the end is never before the start. (closes #7442)
Diffstat (limited to 'src/regexp_nfa.c')
-rw-r--r--src/regexp_nfa.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/regexp_nfa.c b/src/regexp_nfa.c
index c75c575fd..da80ee921 100644
--- a/src/regexp_nfa.c
+++ b/src/regexp_nfa.c
@@ -7225,6 +7225,23 @@ nfa_regexec_both(
#endif
theend:
+ // Make sure the end is never before the start. Can happen when \zs and
+ // \ze are used.
+ if (REG_MULTI)
+ {
+ lpos_T *start = &rex.reg_mmatch->startpos[0];
+ lpos_T *end = &rex.reg_mmatch->endpos[0];
+
+ if (end->lnum < start->lnum
+ || (end->lnum == start->lnum && end->col < start->col))
+ rex.reg_mmatch->endpos[0] = rex.reg_mmatch->startpos[0];
+ }
+ else
+ {
+ if (rex.reg_match->endp[0] < rex.reg_match->startp[0])
+ rex.reg_match->endp[0] = rex.reg_match->startp[0];
+ }
+
return retval;
}