Skip to content

Commit cd62512

Browse files
committed
patch 8.1.0973: pattern with syntax error gives threee error messages
Problem: Pattern with syntax error gives threee error messages. (Kuang-che Wu) Solution: Remove outdated internal error. Don't fall back to other engine after an error.
1 parent 72e83c1 commit cd62512

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/regexp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7969,6 +7969,7 @@ vim_regcomp(char_u *expr_arg, int re_flags)
79697969
{
79707970
regprog_T *prog = NULL;
79717971
char_u *expr = expr_arg;
7972+
int save_called_emsg;
79727973

79737974
regexp_engine = p_re;
79747975

@@ -8004,6 +8005,8 @@ vim_regcomp(char_u *expr_arg, int re_flags)
80048005
/*
80058006
* First try the NFA engine, unless backtracking was requested.
80068007
*/
8008+
save_called_emsg = called_emsg;
8009+
called_emsg = FALSE;
80078010
if (regexp_engine != BACKTRACKING_ENGINE)
80088011
prog = nfa_regengine.regcomp(expr,
80098012
re_flags + (regexp_engine == AUTOMATIC_ENGINE ? RE_AUTO : 0));
@@ -8032,13 +8035,15 @@ vim_regcomp(char_u *expr_arg, int re_flags)
80328035
* If the NFA engine failed, try the backtracking engine.
80338036
* The NFA engine also fails for patterns that it can't handle well
80348037
* but are still valid patterns, thus a retry should work.
8038+
* But don't try if an error message was given.
80358039
*/
8036-
if (regexp_engine == AUTOMATIC_ENGINE)
8040+
if (regexp_engine == AUTOMATIC_ENGINE && !called_emsg)
80378041
{
80388042
regexp_engine = BACKTRACKING_ENGINE;
80398043
prog = bt_regengine.regcomp(expr, re_flags);
80408044
}
80418045
}
8046+
called_emsg |= save_called_emsg;
80428047

80438048
if (prog != NULL)
80448049
{

src/regexp_nfa.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7252,12 +7252,7 @@ nfa_regcomp(char_u *expr, int re_flags)
72527252
* (and count its size). */
72537253
postfix = re2post();
72547254
if (postfix == NULL)
7255-
{
7256-
/* TODO: only give this error for debugging? */
7257-
if (post_ptr >= post_end)
7258-
siemsg("Internal error: estimated max number of states insufficient: %ld", post_end - post_start);
72597255
goto fail; /* Cascaded (syntax?) error */
7260-
}
72617256

72627257
/*
72637258
* In order to build the NFA, we parse the input regexp twice:

src/testdir/test_search.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,3 +1220,8 @@ func Test_large_hex_chars()
12201220
call assert_match('E678:', v:exception)
12211221
endtry
12221222
endfunc
1223+
1224+
func Test_one_error_msg()
1225+
" This was also giving an internal error
1226+
call assert_fails('call search(" \\((\\v[[=P=]]){185}+ ")', 'E871:')
1227+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,8 @@ static char *(features[]) =
779779

780780
static int included_patches[] =
781781
{ /* Add new patch number below this line */
782+
/**/
783+
973,
782784
/**/
783785
972,
784786
/**/

0 commit comments

Comments
 (0)