| 613 | Return REG_NOERROR if we find a match, and REG_NOMATCH if not, |
| 614 | otherwise return the error code. |
| 615 | Note: We assume front end functions already check ranges. |
| 616 | (START + RANGE >= 0 && START + RANGE <= LENGTH) */ |
| 617 | |
| 618 | static reg_errcode_t |
| 619 | re_search_internal (const regex_t *preg, |
| 620 | const char *string, |
| 621 | int length, int start, int range, int stop, |
| 622 | size_t nmatch, regmatch_t pmatch[], |
| 623 | int eflags) |
| 624 | { |
| 625 | reg_errcode_t err; |
| 626 | const re_dfa_t *dfa = (const re_dfa_t *) preg->buffer; |
| 627 | int left_lim, right_lim, incr; |
| 628 | int fl_longest_match, match_first, match_kind, match_last = -1; |
| 629 | int extra_nmatch; |
| 630 | int sb, ch; |
| 631 | #if defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) |
| 632 | re_match_context_t mctx = { .dfa = dfa }; |
| 633 | #else |
| 634 | re_match_context_t mctx; |
| 635 | #endif |
| 636 | char *fastmap = (preg->fastmap != NULL && preg->fastmap_accurate |
| 637 | && range && !preg->can_be_null) ? preg->fastmap : NULL; |
| 638 | RE_TRANSLATE_TYPE t = preg->translate; |
| 639 | |
| 640 | #if !(defined _LIBC || (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)) |
| 641 | memset (&mctx, '\0', sizeof (re_match_context_t)); |
| 642 | mctx.dfa = dfa; |
| 643 | #endif |
| 644 | |
| 645 | extra_nmatch = (nmatch > preg->re_nsub) ? nmatch - (preg->re_nsub + 1) : 0; |
| 646 | nmatch -= extra_nmatch; |
| 647 | |
| 648 | /* Check if the DFA haven't been compiled. */ |
| 649 | if (BE (preg->used == 0 || dfa->init_state == NULL |
| 650 | || dfa->init_state_word == NULL || dfa->init_state_nl == NULL |
| 651 | || dfa->init_state_begbuf == NULL, 0)) |
| 652 | return REG_NOMATCH; |
| 653 | |
| 654 | #ifdef DEBUG |
| 655 | /* We assume front-end functions already check them. */ |
| 656 | assert (start + range >= 0 && start + range <= length); |
| 657 | #endif |
| 658 | |
| 659 | /* If initial states with non-begbuf contexts have no elements, |
| 660 | the regex must be anchored. If preg->newline_anchor is set, |
| 661 | we'll never use init_state_nl, so do not check it. */ |
| 662 | if (dfa->init_state->nodes.nelem == 0 |
| 663 | && dfa->init_state_word->nodes.nelem == 0 |
| 664 | && (dfa->init_state_nl->nodes.nelem == 0 |
| 665 | || !preg->newline_anchor)) |
| 666 | { |
| 667 | if (start != 0 && start + range != 0) |
| 668 | return REG_NOMATCH; |
| 669 | start = range = 0; |
| 670 | } |
| 671 | |
| 672 | /* We must check the longest matching, if nmatch > 0. */ |
no test coverage detected