diff src/regexp_nfa.c @ 23150:90b16a0022e5 v8.2.2121

patch 8.2.2121: internal error when using ze before zs in a pattern Commit: https://github.com/vim/vim/commit/a7a691cc142439e266f4ceb1f208bb952b57aa71 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 9 16:36:04 2020 +0100 patch 8.2.2121: internal error when using \ze before \zs in a pattern Problem: Internal error when using \ze before \zs in a pattern. Solution: Check the end is never before the start. (closes https://github.com/vim/vim/issues/7442)
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Dec 2020 16:45:04 +0100
parents 740b16b3c80b
children 8caba5736a9a
line wrap: on
line diff
--- 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;
 }