From 44635add18f7ef49f8d598123ec1d4ec61563e73 Mon Sep 17 00:00:00 2001 From: Scott Prager Date: Tue, 21 Oct 2014 11:08:35 -0400 Subject: [PATCH 1/2] vim-patch:7.4.421 Problem: Crash when searching for "\ze*". (Urtica Dioica) Solution: Disallow a multi after \ze and \zs. https://code.google.com/p/vim/source/detail?r=v7-4-421 --- src/nvim/regexp_nfa.c | 17 ++++++++++++++++- src/nvim/testdir/test64.in | 13 ++++++++++++- src/nvim/testdir/test64.ok | 2 ++ src/nvim/version.c | 2 +- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 2659eac762..bbe96854ad 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1259,10 +1259,16 @@ static int nfa_regatom(void) switch (c) { case 's': EMIT(NFA_ZSTART); + if (!re_mult_next("\\zs")) { + return false; + } break; case 'e': EMIT(NFA_ZEND); - nfa_has_zend = TRUE; + nfa_has_zend = true; + if (!re_mult_next("\\zs")) { + return false; + } break; case '1': case '2': @@ -1741,6 +1747,15 @@ nfa_do_multibyte: return OK; } +/// Used in a place where no * or \+ can follow. +static bool re_mult_next(char *what) +{ + if (re_multi_type(peekchr()) == MULTI_MULT) { + EMSG2_RET_FAIL(_("E888: (NFA regexp) cannot repeat %s"), what); + } + return true; +} + /* * Parse something followed by possible [*+=]. * diff --git a/src/nvim/testdir/test64.in b/src/nvim/testdir/test64.in index 2abdcd1c08..f2452fc0f3 100644 --- a/src/nvim/testdir/test64.in +++ b/src/nvim/testdir/test64.in @@ -459,7 +459,7 @@ STARTTEST : let text = t[2] : let matchidx = 3 : for engine in [0, 1, 2] -: if engine == 2 && re == 0 || engine == 1 && re ==1 +: if engine == 2 && re == 0 || engine == 1 && re == 1 : continue : endif : let ®expengine = engine @@ -608,6 +608,17 @@ yeGopA END:" "ayb20gg/..\%$ "bybGo"apo"bp:" :" +:" Check for detecting error +:set regexpengine=2 +:for pat in [' \ze*', ' \zs*'] +: try +: let l = matchlist('x x', pat) +: $put ='E888 NOT detected for ' . pat +: catch +: $put ='E888 detected for ' . pat +: endtry +:endfor +:" :""""" Write the results """"""""""""" :/\%#=1^Results/,$wq! test.out ENDTEST diff --git a/src/nvim/testdir/test64.ok b/src/nvim/testdir/test64.ok index e7d173141a..ffc0b5341f 100644 --- a/src/nvim/testdir/test64.ok +++ b/src/nvim/testdir/test64.ok @@ -1097,3 +1097,5 @@ Test Test END EN E +E888 detected for \ze* +E888 detected for \zs* diff --git a/src/nvim/version.c b/src/nvim/version.c index 9943e2945f..76cf667ce5 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -244,7 +244,7 @@ static int included_patches[] = { //424 NA //423, //422, - //421, + 421, //420 NA 419, 418, From ca7c509ae0396be0b15c268b1b2e0600e796e322 Mon Sep 17 00:00:00 2001 From: Scott Prager Date: Sat, 25 Oct 2014 15:34:06 -0400 Subject: [PATCH 2/2] vim-patch:7.4.437 Problem: New and old regexp engine are not consistent. Solution: Also give an error for "\ze*" for the old regexp engine. https://code.google.com/p/vim/source/detail?r=v7-4-437 --- src/nvim/regexp.c | 15 +++++++++++++++ src/nvim/regexp_nfa.c | 9 --------- src/nvim/version.c | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index cef2e6d9bf..d57bc889ac 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1983,9 +1983,15 @@ static char_u *regatom(int *flagp) break; case 's': ret = regnode(MOPEN + 0); + if (!re_mult_next("\\zs")) { + return NULL; + } break; case 'e': ret = regnode(MCLOSE + 0); + if (!re_mult_next("\\ze")) { + return NULL; + } break; default: EMSG_RET_NULL(_("E68: Invalid character after \\z")); @@ -2460,6 +2466,15 @@ do_multibyte: return ret; } +/// Used in a place where no * or \+ can follow. +static bool re_mult_next(char *what) +{ + if (re_multi_type(peekchr()) == MULTI_MULT) { + EMSG2_RET_FAIL(_("E888: (NFA regexp) cannot repeat %s"), what); + } + return true; +} + /* * Return TRUE if MULTIBYTECODE should be used instead of EXACTLY for * character "c". diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index bbe96854ad..9ae1740627 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1747,15 +1747,6 @@ nfa_do_multibyte: return OK; } -/// Used in a place where no * or \+ can follow. -static bool re_mult_next(char *what) -{ - if (re_multi_type(peekchr()) == MULTI_MULT) { - EMSG2_RET_FAIL(_("E888: (NFA regexp) cannot repeat %s"), what); - } - return true; -} - /* * Parse something followed by possible [*+=]. * diff --git a/src/nvim/version.c b/src/nvim/version.c index 76cf667ce5..2bc99fcad4 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -228,7 +228,7 @@ static int included_patches[] = { 440, 439, //438, - //437, + 437, 436, //435, //434,