@@ -906,15 +906,17 @@ static int patmatch(struct grep_pat *p,
906906 const char * line , const char * eol ,
907907 regmatch_t * match , int eflags )
908908{
909- int hit ;
910-
911909 if (p -> pcre2_pattern )
912- hit = !pcre2match (p , line , eol , match , eflags );
913- else
914- hit = !regexec_buf (& p -> regexp , line , eol - line , 1 , match ,
915- eflags );
910+ return !pcre2match (p , line , eol , match , eflags );
916911
917- return hit ;
912+ switch (regexec_buf (& p -> regexp , line , eol - line , 1 , match , eflags )) {
913+ case 0 :
914+ return 1 ;
915+ case REG_NOMATCH :
916+ return 0 ;
917+ default :
918+ return -1 ;
919+ }
918920}
919921
920922static void strip_timestamp (const char * bol , const char * * eol_p )
@@ -952,6 +954,8 @@ static int headerless_match_one_pattern(struct grep_pat *p,
952954
953955 again :
954956 hit = patmatch (p , bol , eol , pmatch , eflags );
957+ if (hit < 0 )
958+ hit = 0 ;
955959
956960 if (hit && p -> word_regexp ) {
957961 if ((pmatch [0 ].rm_so < 0 ) ||
@@ -1461,6 +1465,8 @@ static int look_ahead(struct grep_opt *opt,
14611465 regmatch_t m ;
14621466
14631467 hit = patmatch (p , bol , bol + * left_p , & m , 0 );
1468+ if (hit < 0 )
1469+ return -1 ;
14641470 if (!hit || m .rm_so < 0 || m .rm_eo < 0 )
14651471 continue ;
14661472 if (earliest < 0 || m .rm_so < earliest )
@@ -1655,9 +1661,13 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
16551661 if (try_lookahead
16561662 && !(last_hit
16571663 && (show_function ||
1658- lno <= last_hit + opt -> post_context ))
1659- && look_ahead (opt , & left , & lno , & bol ))
1660- break ;
1664+ lno <= last_hit + opt -> post_context ))) {
1665+ hit = look_ahead (opt , & left , & lno , & bol );
1666+ if (hit < 0 )
1667+ try_lookahead = 0 ;
1668+ else if (hit )
1669+ break ;
1670+ }
16611671 eol = end_of_line (bol , & left );
16621672
16631673 if ((ctx == GREP_CONTEXT_HEAD ) && (eol == bol ))
0 commit comments