@@ -906,15 +906,17 @@ static int patmatch(struct grep_pat *p,
906
906
const char * line , const char * eol ,
907
907
regmatch_t * match , int eflags )
908
908
{
909
- int hit ;
910
-
911
909
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 );
916
911
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
+ }
918
920
}
919
921
920
922
static void strip_timestamp (const char * bol , const char * * eol_p )
@@ -952,6 +954,8 @@ static int headerless_match_one_pattern(struct grep_pat *p,
952
954
953
955
again :
954
956
hit = patmatch (p , bol , eol , pmatch , eflags );
957
+ if (hit < 0 )
958
+ hit = 0 ;
955
959
956
960
if (hit && p -> word_regexp ) {
957
961
if ((pmatch [0 ].rm_so < 0 ) ||
@@ -1461,6 +1465,8 @@ static int look_ahead(struct grep_opt *opt,
1461
1465
regmatch_t m ;
1462
1466
1463
1467
hit = patmatch (p , bol , bol + * left_p , & m , 0 );
1468
+ if (hit < 0 )
1469
+ return -1 ;
1464
1470
if (!hit || m .rm_so < 0 || m .rm_eo < 0 )
1465
1471
continue ;
1466
1472
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
1655
1661
if (try_lookahead
1656
1662
&& !(last_hit
1657
1663
&& (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
+ }
1661
1671
eol = end_of_line (bol , & left );
1662
1672
1663
1673
if ((ctx == GREP_CONTEXT_HEAD ) && (eol == bol ))
0 commit comments