@@ -907,15 +907,17 @@ static int patmatch(struct grep_pat *p,
907907 const char * line , const char * eol ,
908908 regmatch_t * match , int eflags )
909909{
910- int hit ;
911-
912910 if (p -> pcre2_pattern )
913- hit = !pcre2match (p , line , eol , match , eflags );
914- else
915- hit = !regexec_buf (& p -> regexp , line , eol - line , 1 , match ,
916- eflags );
911+ return !pcre2match (p , line , eol , match , eflags );
917912
918- return hit ;
913+ switch (regexec_buf (& p -> regexp , line , eol - line , 1 , match , eflags )) {
914+ case 0 :
915+ return 1 ;
916+ case REG_NOMATCH :
917+ return 0 ;
918+ default :
919+ return -1 ;
920+ }
919921}
920922
921923static void strip_timestamp (const char * bol , const char * * eol_p )
@@ -953,6 +955,8 @@ static int headerless_match_one_pattern(struct grep_pat *p,
953955
954956 again :
955957 hit = patmatch (p , bol , eol , pmatch , eflags );
958+ if (hit < 0 )
959+ hit = 0 ;
956960
957961 if (hit && p -> word_regexp ) {
958962 if ((pmatch [0 ].rm_so < 0 ) ||
@@ -1462,6 +1466,8 @@ static int look_ahead(struct grep_opt *opt,
14621466 regmatch_t m ;
14631467
14641468 hit = patmatch (p , bol , bol + * left_p , & m , 0 );
1469+ if (hit < 0 )
1470+ return -1 ;
14651471 if (!hit || m .rm_so < 0 || m .rm_eo < 0 )
14661472 continue ;
14671473 if (earliest < 0 || m .rm_so < earliest )
@@ -1656,9 +1662,13 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
16561662 if (try_lookahead
16571663 && !(last_hit
16581664 && (show_function ||
1659- lno <= last_hit + opt -> post_context ))
1660- && look_ahead (opt , & left , & lno , & bol ))
1661- break ;
1665+ lno <= last_hit + opt -> post_context ))) {
1666+ hit = look_ahead (opt , & left , & lno , & bol );
1667+ if (hit < 0 )
1668+ try_lookahead = 0 ;
1669+ else if (hit )
1670+ break ;
1671+ }
16621672 eol = end_of_line (bol , & left );
16631673
16641674 if ((ctx == GREP_CONTEXT_HEAD ) && (eol == bol ))
0 commit comments