diff options
| author | Paul Eggert | 2018-10-15 00:55:37 -0500 |
|---|---|---|
| committer | Paul Eggert | 2018-10-15 00:57:57 -0500 |
| commit | 3d91dc1bb5aeecda786ebe1805c33d14c8bd89fa (patch) | |
| tree | 155498240a837b179319741542aaa78c8a47c9ab /lib/regexec.c | |
| parent | 6b8fd34c4ab1aa23b180440cdc8210900896bbf4 (diff) | |
| download | emacs-3d91dc1bb5aeecda786ebe1805c33d14c8bd89fa.tar.gz emacs-3d91dc1bb5aeecda786ebe1805c33d14c8bd89fa.zip | |
Update lib/regex from glibc via Gnulib
This syncs recent refactorings from glibc, and incorporates:
2018-10-15 libc-config: merge from glibc
2018-10-15 regex: depend on libc-config
* .gitignore: Do not ignore m4/_*.m4.
* lib/cdefs.h: New file, copied from Gnulib.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lib/libc-config.h, m4/__inline.m4: New files, copied from Gnulib.
* lib/regcomp.c, lib/regex.c, lib/regex_internal.c:
* lib/regex_internal.h, lib/regexec.c:
Copy from glibc via Gnulib.
Diffstat (limited to 'lib/regexec.c')
| -rw-r--r-- | lib/regexec.c | 363 |
1 files changed, 185 insertions, 178 deletions
diff --git a/lib/regexec.c b/lib/regexec.c index 65913111644..8b82ea50d44 100644 --- a/lib/regexec.c +++ b/lib/regexec.c | |||
| @@ -328,9 +328,8 @@ re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1, | |||
| 328 | Idx len; | 328 | Idx len; |
| 329 | char *s = NULL; | 329 | char *s = NULL; |
| 330 | 330 | ||
| 331 | if (BE ((length1 < 0 || length2 < 0 || stop < 0 | 331 | if (__glibc_unlikely ((length1 < 0 || length2 < 0 || stop < 0 |
| 332 | || INT_ADD_WRAPV (length1, length2, &len)), | 332 | || INT_ADD_WRAPV (length1, length2, &len)))) |
| 333 | 0)) | ||
| 334 | return -2; | 333 | return -2; |
| 335 | 334 | ||
| 336 | /* Concatenate the strings. */ | 335 | /* Concatenate the strings. */ |
| @@ -339,7 +338,7 @@ re_search_2_stub (struct re_pattern_buffer *bufp, const char *string1, | |||
| 339 | { | 338 | { |
| 340 | s = re_malloc (char, len); | 339 | s = re_malloc (char, len); |
| 341 | 340 | ||
| 342 | if (BE (s == NULL, 0)) | 341 | if (__glibc_unlikely (s == NULL)) |
| 343 | return -2; | 342 | return -2; |
| 344 | #ifdef _LIBC | 343 | #ifdef _LIBC |
| 345 | memcpy (__mempcpy (s, string1, length1), string2, length2); | 344 | memcpy (__mempcpy (s, string1, length1), string2, length2); |
| @@ -379,11 +378,13 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, | |||
| 379 | Idx last_start = start + range; | 378 | Idx last_start = start + range; |
| 380 | 379 | ||
| 381 | /* Check for out-of-range. */ | 380 | /* Check for out-of-range. */ |
| 382 | if (BE (start < 0 || start > length, 0)) | 381 | if (__glibc_unlikely (start < 0 || start > length)) |
| 383 | return -1; | 382 | return -1; |
| 384 | if (BE (length < last_start || (0 <= range && last_start < start), 0)) | 383 | if (__glibc_unlikely (length < last_start |
| 384 | || (0 <= range && last_start < start))) | ||
| 385 | last_start = length; | 385 | last_start = length; |
| 386 | else if (BE (last_start < 0 || (range < 0 && start <= last_start), 0)) | 386 | else if (__glibc_unlikely (last_start < 0 |
| 387 | || (range < 0 && start <= last_start))) | ||
| 387 | last_start = 0; | 388 | last_start = 0; |
| 388 | 389 | ||
| 389 | lock_lock (dfa->lock); | 390 | lock_lock (dfa->lock); |
| @@ -395,17 +396,17 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, | |||
| 395 | if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) | 396 | if (start < last_start && bufp->fastmap != NULL && !bufp->fastmap_accurate) |
| 396 | re_compile_fastmap (bufp); | 397 | re_compile_fastmap (bufp); |
| 397 | 398 | ||
| 398 | if (BE (bufp->no_sub, 0)) | 399 | if (__glibc_unlikely (bufp->no_sub)) |
| 399 | regs = NULL; | 400 | regs = NULL; |
| 400 | 401 | ||
| 401 | /* We need at least 1 register. */ | 402 | /* We need at least 1 register. */ |
| 402 | if (regs == NULL) | 403 | if (regs == NULL) |
| 403 | nregs = 1; | 404 | nregs = 1; |
| 404 | else if (BE (bufp->regs_allocated == REGS_FIXED | 405 | else if (__glibc_unlikely (bufp->regs_allocated == REGS_FIXED |
| 405 | && regs->num_regs <= bufp->re_nsub, 0)) | 406 | && regs->num_regs <= bufp->re_nsub)) |
| 406 | { | 407 | { |
| 407 | nregs = regs->num_regs; | 408 | nregs = regs->num_regs; |
| 408 | if (BE (nregs < 1, 0)) | 409 | if (__glibc_unlikely (nregs < 1)) |
| 409 | { | 410 | { |
| 410 | /* Nothing can be copied to regs. */ | 411 | /* Nothing can be copied to regs. */ |
| 411 | regs = NULL; | 412 | regs = NULL; |
| @@ -415,7 +416,7 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, | |||
| 415 | else | 416 | else |
| 416 | nregs = bufp->re_nsub + 1; | 417 | nregs = bufp->re_nsub + 1; |
| 417 | pmatch = re_malloc (regmatch_t, nregs); | 418 | pmatch = re_malloc (regmatch_t, nregs); |
| 418 | if (BE (pmatch == NULL, 0)) | 419 | if (__glibc_unlikely (pmatch == NULL)) |
| 419 | { | 420 | { |
| 420 | rval = -2; | 421 | rval = -2; |
| 421 | goto out; | 422 | goto out; |
| @@ -434,11 +435,11 @@ re_search_stub (struct re_pattern_buffer *bufp, const char *string, Idx length, | |||
| 434 | /* If caller wants register contents data back, copy them. */ | 435 | /* If caller wants register contents data back, copy them. */ |
| 435 | bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, | 436 | bufp->regs_allocated = re_copy_regs (regs, pmatch, nregs, |
| 436 | bufp->regs_allocated); | 437 | bufp->regs_allocated); |
| 437 | if (BE (bufp->regs_allocated == REGS_UNALLOCATED, 0)) | 438 | if (__glibc_unlikely (bufp->regs_allocated == REGS_UNALLOCATED)) |
| 438 | rval = -2; | 439 | rval = -2; |
| 439 | } | 440 | } |
| 440 | 441 | ||
| 441 | if (BE (rval == 0, 1)) | 442 | if (__glibc_likely (rval == 0)) |
| 442 | { | 443 | { |
| 443 | if (ret_len) | 444 | if (ret_len) |
| 444 | { | 445 | { |
| @@ -468,10 +469,10 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, | |||
| 468 | if (regs_allocated == REGS_UNALLOCATED) | 469 | if (regs_allocated == REGS_UNALLOCATED) |
| 469 | { /* No. So allocate them with malloc. */ | 470 | { /* No. So allocate them with malloc. */ |
| 470 | regs->start = re_malloc (regoff_t, need_regs); | 471 | regs->start = re_malloc (regoff_t, need_regs); |
| 471 | if (BE (regs->start == NULL, 0)) | 472 | if (__glibc_unlikely (regs->start == NULL)) |
| 472 | return REGS_UNALLOCATED; | 473 | return REGS_UNALLOCATED; |
| 473 | regs->end = re_malloc (regoff_t, need_regs); | 474 | regs->end = re_malloc (regoff_t, need_regs); |
| 474 | if (BE (regs->end == NULL, 0)) | 475 | if (__glibc_unlikely (regs->end == NULL)) |
| 475 | { | 476 | { |
| 476 | re_free (regs->start); | 477 | re_free (regs->start); |
| 477 | return REGS_UNALLOCATED; | 478 | return REGS_UNALLOCATED; |
| @@ -482,14 +483,14 @@ re_copy_regs (struct re_registers *regs, regmatch_t *pmatch, Idx nregs, | |||
| 482 | { /* Yes. If we need more elements than were already | 483 | { /* Yes. If we need more elements than were already |
| 483 | allocated, reallocate them. If we need fewer, just | 484 | allocated, reallocate them. If we need fewer, just |
| 484 | leave it alone. */ | 485 | leave it alone. */ |
| 485 | if (BE (need_regs > regs->num_regs, 0)) | 486 | if (__glibc_unlikely (need_regs > regs->num_regs)) |
| 486 | { | 487 | { |
| 487 | regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); | 488 | regoff_t *new_start = re_realloc (regs->start, regoff_t, need_regs); |
| 488 | regoff_t *new_end; | 489 | regoff_t *new_end; |
| 489 | if (BE (new_start == NULL, 0)) | 490 | if (__glibc_unlikely (new_start == NULL)) |
| 490 | return REGS_UNALLOCATED; | 491 | return REGS_UNALLOCATED; |
| 491 | new_end = re_realloc (regs->end, regoff_t, need_regs); | 492 | new_end = re_realloc (regs->end, regoff_t, need_regs); |
| 492 | if (BE (new_end == NULL, 0)) | 493 | if (__glibc_unlikely (new_end == NULL)) |
| 493 | { | 494 | { |
| 494 | re_free (new_start); | 495 | re_free (new_start); |
| 495 | return REGS_UNALLOCATED; | 496 | return REGS_UNALLOCATED; |
| @@ -615,9 +616,10 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 615 | nmatch -= extra_nmatch; | 616 | nmatch -= extra_nmatch; |
| 616 | 617 | ||
| 617 | /* Check if the DFA haven't been compiled. */ | 618 | /* Check if the DFA haven't been compiled. */ |
| 618 | if (BE (preg->used == 0 || dfa->init_state == NULL | 619 | if (__glibc_unlikely (preg->used == 0 || dfa->init_state == NULL |
| 619 | || dfa->init_state_word == NULL || dfa->init_state_nl == NULL | 620 | || dfa->init_state_word == NULL |
| 620 | || dfa->init_state_begbuf == NULL, 0)) | 621 | || dfa->init_state_nl == NULL |
| 622 | || dfa->init_state_begbuf == NULL)) | ||
| 621 | return REG_NOMATCH; | 623 | return REG_NOMATCH; |
| 622 | 624 | ||
| 623 | #ifdef DEBUG | 625 | #ifdef DEBUG |
| @@ -644,14 +646,14 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 644 | err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, | 646 | err = re_string_allocate (&mctx.input, string, length, dfa->nodes_len + 1, |
| 645 | preg->translate, (preg->syntax & RE_ICASE) != 0, | 647 | preg->translate, (preg->syntax & RE_ICASE) != 0, |
| 646 | dfa); | 648 | dfa); |
| 647 | if (BE (err != REG_NOERROR, 0)) | 649 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 648 | goto free_return; | 650 | goto free_return; |
| 649 | mctx.input.stop = stop; | 651 | mctx.input.stop = stop; |
| 650 | mctx.input.raw_stop = stop; | 652 | mctx.input.raw_stop = stop; |
| 651 | mctx.input.newline_anchor = preg->newline_anchor; | 653 | mctx.input.newline_anchor = preg->newline_anchor; |
| 652 | 654 | ||
| 653 | err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); | 655 | err = match_ctx_init (&mctx, eflags, dfa->nbackref * 2); |
| 654 | if (BE (err != REG_NOERROR, 0)) | 656 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 655 | goto free_return; | 657 | goto free_return; |
| 656 | 658 | ||
| 657 | /* We will log all the DFA states through which the dfa pass, | 659 | /* We will log all the DFA states through which the dfa pass, |
| @@ -661,15 +663,15 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 661 | if (nmatch > 1 || dfa->has_mb_node) | 663 | if (nmatch > 1 || dfa->has_mb_node) |
| 662 | { | 664 | { |
| 663 | /* Avoid overflow. */ | 665 | /* Avoid overflow. */ |
| 664 | if (BE ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) | 666 | if (__glibc_unlikely ((MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) |
| 665 | <= mctx.input.bufs_len), 0)) | 667 | <= mctx.input.bufs_len))) |
| 666 | { | 668 | { |
| 667 | err = REG_ESPACE; | 669 | err = REG_ESPACE; |
| 668 | goto free_return; | 670 | goto free_return; |
| 669 | } | 671 | } |
| 670 | 672 | ||
| 671 | mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); | 673 | mctx.state_log = re_malloc (re_dfastate_t *, mctx.input.bufs_len + 1); |
| 672 | if (BE (mctx.state_log == NULL, 0)) | 674 | if (__glibc_unlikely (mctx.state_log == NULL)) |
| 673 | { | 675 | { |
| 674 | err = REG_ESPACE; | 676 | err = REG_ESPACE; |
| 675 | goto free_return; | 677 | goto free_return; |
| @@ -713,19 +715,19 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 713 | 715 | ||
| 714 | case 7: | 716 | case 7: |
| 715 | /* Fastmap with single-byte translation, match forward. */ | 717 | /* Fastmap with single-byte translation, match forward. */ |
| 716 | while (BE (match_first < right_lim, 1) | 718 | while (__glibc_likely (match_first < right_lim) |
| 717 | && !fastmap[t[(unsigned char) string[match_first]]]) | 719 | && !fastmap[t[(unsigned char) string[match_first]]]) |
| 718 | ++match_first; | 720 | ++match_first; |
| 719 | goto forward_match_found_start_or_reached_end; | 721 | goto forward_match_found_start_or_reached_end; |
| 720 | 722 | ||
| 721 | case 6: | 723 | case 6: |
| 722 | /* Fastmap without translation, match forward. */ | 724 | /* Fastmap without translation, match forward. */ |
| 723 | while (BE (match_first < right_lim, 1) | 725 | while (__glibc_likely (match_first < right_lim) |
| 724 | && !fastmap[(unsigned char) string[match_first]]) | 726 | && !fastmap[(unsigned char) string[match_first]]) |
| 725 | ++match_first; | 727 | ++match_first; |
| 726 | 728 | ||
| 727 | forward_match_found_start_or_reached_end: | 729 | forward_match_found_start_or_reached_end: |
| 728 | if (BE (match_first == right_lim, 0)) | 730 | if (__glibc_unlikely (match_first == right_lim)) |
| 729 | { | 731 | { |
| 730 | ch = match_first >= length | 732 | ch = match_first >= length |
| 731 | ? 0 : (unsigned char) string[match_first]; | 733 | ? 0 : (unsigned char) string[match_first]; |
| @@ -758,11 +760,12 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 758 | /* If MATCH_FIRST is out of the valid range, reconstruct the | 760 | /* If MATCH_FIRST is out of the valid range, reconstruct the |
| 759 | buffers. */ | 761 | buffers. */ |
| 760 | __re_size_t offset = match_first - mctx.input.raw_mbs_idx; | 762 | __re_size_t offset = match_first - mctx.input.raw_mbs_idx; |
| 761 | if (BE (offset >= (__re_size_t) mctx.input.valid_raw_len, 0)) | 763 | if (__glibc_unlikely (offset |
| 764 | >= (__re_size_t) mctx.input.valid_raw_len)) | ||
| 762 | { | 765 | { |
| 763 | err = re_string_reconstruct (&mctx.input, match_first, | 766 | err = re_string_reconstruct (&mctx.input, match_first, |
| 764 | eflags); | 767 | eflags); |
| 765 | if (BE (err != REG_NOERROR, 0)) | 768 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 766 | goto free_return; | 769 | goto free_return; |
| 767 | 770 | ||
| 768 | offset = match_first - mctx.input.raw_mbs_idx; | 771 | offset = match_first - mctx.input.raw_mbs_idx; |
| @@ -786,7 +789,7 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 786 | /* Reconstruct the buffers so that the matcher can assume that | 789 | /* Reconstruct the buffers so that the matcher can assume that |
| 787 | the matching starts from the beginning of the buffer. */ | 790 | the matching starts from the beginning of the buffer. */ |
| 788 | err = re_string_reconstruct (&mctx.input, match_first, eflags); | 791 | err = re_string_reconstruct (&mctx.input, match_first, eflags); |
| 789 | if (BE (err != REG_NOERROR, 0)) | 792 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 790 | goto free_return; | 793 | goto free_return; |
| 791 | 794 | ||
| 792 | #ifdef RE_ENABLE_I18N | 795 | #ifdef RE_ENABLE_I18N |
| @@ -803,7 +806,7 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 803 | start <= last_start ? &match_first : NULL); | 806 | start <= last_start ? &match_first : NULL); |
| 804 | if (match_last != -1) | 807 | if (match_last != -1) |
| 805 | { | 808 | { |
| 806 | if (BE (match_last == -2, 0)) | 809 | if (__glibc_unlikely (match_last == -2)) |
| 807 | { | 810 | { |
| 808 | err = REG_ESPACE; | 811 | err = REG_ESPACE; |
| 809 | goto free_return; | 812 | goto free_return; |
| @@ -823,7 +826,7 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 823 | err = prune_impossible_nodes (&mctx); | 826 | err = prune_impossible_nodes (&mctx); |
| 824 | if (err == REG_NOERROR) | 827 | if (err == REG_NOERROR) |
| 825 | break; | 828 | break; |
| 826 | if (BE (err != REG_NOMATCH, 0)) | 829 | if (__glibc_unlikely (err != REG_NOMATCH)) |
| 827 | goto free_return; | 830 | goto free_return; |
| 828 | match_last = -1; | 831 | match_last = -1; |
| 829 | } | 832 | } |
| @@ -860,7 +863,7 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 860 | { | 863 | { |
| 861 | err = set_regs (preg, &mctx, nmatch, pmatch, | 864 | err = set_regs (preg, &mctx, nmatch, pmatch, |
| 862 | dfa->has_plural_match && dfa->nbackref > 0); | 865 | dfa->has_plural_match && dfa->nbackref > 0); |
| 863 | if (BE (err != REG_NOERROR, 0)) | 866 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 864 | goto free_return; | 867 | goto free_return; |
| 865 | } | 868 | } |
| 866 | 869 | ||
| @@ -871,7 +874,7 @@ re_search_internal (const regex_t *preg, const char *string, Idx length, | |||
| 871 | if (pmatch[reg_idx].rm_so != -1) | 874 | if (pmatch[reg_idx].rm_so != -1) |
| 872 | { | 875 | { |
| 873 | #ifdef RE_ENABLE_I18N | 876 | #ifdef RE_ENABLE_I18N |
| 874 | if (BE (mctx.input.offsets_needed != 0, 0)) | 877 | if (__glibc_unlikely (mctx.input.offsets_needed != 0)) |
| 875 | { | 878 | { |
| 876 | pmatch[reg_idx].rm_so = | 879 | pmatch[reg_idx].rm_so = |
| 877 | (pmatch[reg_idx].rm_so == mctx.input.valid_len | 880 | (pmatch[reg_idx].rm_so == mctx.input.valid_len |
| @@ -930,11 +933,12 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
| 930 | halt_node = mctx->last_node; | 933 | halt_node = mctx->last_node; |
| 931 | 934 | ||
| 932 | /* Avoid overflow. */ | 935 | /* Avoid overflow. */ |
| 933 | if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) <= match_last, 0)) | 936 | if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) |
| 937 | <= match_last)) | ||
| 934 | return REG_ESPACE; | 938 | return REG_ESPACE; |
| 935 | 939 | ||
| 936 | sifted_states = re_malloc (re_dfastate_t *, match_last + 1); | 940 | sifted_states = re_malloc (re_dfastate_t *, match_last + 1); |
| 937 | if (BE (sifted_states == NULL, 0)) | 941 | if (__glibc_unlikely (sifted_states == NULL)) |
| 938 | { | 942 | { |
| 939 | ret = REG_ESPACE; | 943 | ret = REG_ESPACE; |
| 940 | goto free_return; | 944 | goto free_return; |
| @@ -942,7 +946,7 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
| 942 | if (dfa->nbackref) | 946 | if (dfa->nbackref) |
| 943 | { | 947 | { |
| 944 | lim_states = re_malloc (re_dfastate_t *, match_last + 1); | 948 | lim_states = re_malloc (re_dfastate_t *, match_last + 1); |
| 945 | if (BE (lim_states == NULL, 0)) | 949 | if (__glibc_unlikely (lim_states == NULL)) |
| 946 | { | 950 | { |
| 947 | ret = REG_ESPACE; | 951 | ret = REG_ESPACE; |
| 948 | goto free_return; | 952 | goto free_return; |
| @@ -955,7 +959,7 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
| 955 | match_last); | 959 | match_last); |
| 956 | ret = sift_states_backward (mctx, &sctx); | 960 | ret = sift_states_backward (mctx, &sctx); |
| 957 | re_node_set_free (&sctx.limits); | 961 | re_node_set_free (&sctx.limits); |
| 958 | if (BE (ret != REG_NOERROR, 0)) | 962 | if (__glibc_unlikely (ret != REG_NOERROR)) |
| 959 | goto free_return; | 963 | goto free_return; |
| 960 | if (sifted_states[0] != NULL || lim_states[0] != NULL) | 964 | if (sifted_states[0] != NULL || lim_states[0] != NULL) |
| 961 | break; | 965 | break; |
| @@ -977,7 +981,7 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
| 977 | match_last + 1); | 981 | match_last + 1); |
| 978 | re_free (lim_states); | 982 | re_free (lim_states); |
| 979 | lim_states = NULL; | 983 | lim_states = NULL; |
| 980 | if (BE (ret != REG_NOERROR, 0)) | 984 | if (__glibc_unlikely (ret != REG_NOERROR)) |
| 981 | goto free_return; | 985 | goto free_return; |
| 982 | } | 986 | } |
| 983 | else | 987 | else |
| @@ -985,7 +989,7 @@ prune_impossible_nodes (re_match_context_t *mctx) | |||
| 985 | sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last); | 989 | sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, match_last); |
| 986 | ret = sift_states_backward (mctx, &sctx); | 990 | ret = sift_states_backward (mctx, &sctx); |
| 987 | re_node_set_free (&sctx.limits); | 991 | re_node_set_free (&sctx.limits); |
| 988 | if (BE (ret != REG_NOERROR, 0)) | 992 | if (__glibc_unlikely (ret != REG_NOERROR)) |
| 989 | goto free_return; | 993 | goto free_return; |
| 990 | if (sifted_states[0] == NULL) | 994 | if (sifted_states[0] == NULL) |
| 991 | { | 995 | { |
| @@ -1068,7 +1072,7 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match, | |||
| 1068 | err = REG_NOERROR; | 1072 | err = REG_NOERROR; |
| 1069 | cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); | 1073 | cur_state = acquire_init_state_context (&err, mctx, cur_str_idx); |
| 1070 | /* An initial state must not be NULL (invalid). */ | 1074 | /* An initial state must not be NULL (invalid). */ |
| 1071 | if (BE (cur_state == NULL, 0)) | 1075 | if (__glibc_unlikely (cur_state == NULL)) |
| 1072 | { | 1076 | { |
| 1073 | assert (err == REG_ESPACE); | 1077 | assert (err == REG_ESPACE); |
| 1074 | return -2; | 1078 | return -2; |
| @@ -1080,24 +1084,24 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match, | |||
| 1080 | 1084 | ||
| 1081 | /* Check OP_OPEN_SUBEXP in the initial state in case that we use them | 1085 | /* Check OP_OPEN_SUBEXP in the initial state in case that we use them |
| 1082 | later. E.g. Processing back references. */ | 1086 | later. E.g. Processing back references. */ |
| 1083 | if (BE (dfa->nbackref, 0)) | 1087 | if (__glibc_unlikely (dfa->nbackref)) |
| 1084 | { | 1088 | { |
| 1085 | at_init_state = false; | 1089 | at_init_state = false; |
| 1086 | err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); | 1090 | err = check_subexp_matching_top (mctx, &cur_state->nodes, 0); |
| 1087 | if (BE (err != REG_NOERROR, 0)) | 1091 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1088 | return err; | 1092 | return err; |
| 1089 | 1093 | ||
| 1090 | if (cur_state->has_backref) | 1094 | if (cur_state->has_backref) |
| 1091 | { | 1095 | { |
| 1092 | err = transit_state_bkref (mctx, &cur_state->nodes); | 1096 | err = transit_state_bkref (mctx, &cur_state->nodes); |
| 1093 | if (BE (err != REG_NOERROR, 0)) | 1097 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1094 | return err; | 1098 | return err; |
| 1095 | } | 1099 | } |
| 1096 | } | 1100 | } |
| 1097 | } | 1101 | } |
| 1098 | 1102 | ||
| 1099 | /* If the RE accepts NULL string. */ | 1103 | /* If the RE accepts NULL string. */ |
| 1100 | if (BE (cur_state->halt, 0)) | 1104 | if (__glibc_unlikely (cur_state->halt)) |
| 1101 | { | 1105 | { |
| 1102 | if (!cur_state->has_constraint | 1106 | if (!cur_state->has_constraint |
| 1103 | || check_halt_state_context (mctx, cur_state, cur_str_idx)) | 1107 | || check_halt_state_context (mctx, cur_state, cur_str_idx)) |
| @@ -1117,13 +1121,13 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match, | |||
| 1117 | re_dfastate_t *old_state = cur_state; | 1121 | re_dfastate_t *old_state = cur_state; |
| 1118 | Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; | 1122 | Idx next_char_idx = re_string_cur_idx (&mctx->input) + 1; |
| 1119 | 1123 | ||
| 1120 | if ((BE (next_char_idx >= mctx->input.bufs_len, 0) | 1124 | if ((__glibc_unlikely (next_char_idx >= mctx->input.bufs_len) |
| 1121 | && mctx->input.bufs_len < mctx->input.len) | 1125 | && mctx->input.bufs_len < mctx->input.len) |
| 1122 | || (BE (next_char_idx >= mctx->input.valid_len, 0) | 1126 | || (__glibc_unlikely (next_char_idx >= mctx->input.valid_len) |
| 1123 | && mctx->input.valid_len < mctx->input.len)) | 1127 | && mctx->input.valid_len < mctx->input.len)) |
| 1124 | { | 1128 | { |
| 1125 | err = extend_buffers (mctx, next_char_idx + 1); | 1129 | err = extend_buffers (mctx, next_char_idx + 1); |
| 1126 | if (BE (err != REG_NOERROR, 0)) | 1130 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1127 | { | 1131 | { |
| 1128 | assert (err == REG_ESPACE); | 1132 | assert (err == REG_ESPACE); |
| 1129 | return -2; | 1133 | return -2; |
| @@ -1139,7 +1143,7 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match, | |||
| 1139 | /* Reached the invalid state or an error. Try to recover a valid | 1143 | /* Reached the invalid state or an error. Try to recover a valid |
| 1140 | state using the state log, if available and if we have not | 1144 | state using the state log, if available and if we have not |
| 1141 | already found a valid (even if not the longest) match. */ | 1145 | already found a valid (even if not the longest) match. */ |
| 1142 | if (BE (err != REG_NOERROR, 0)) | 1146 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1143 | return -2; | 1147 | return -2; |
| 1144 | 1148 | ||
| 1145 | if (mctx->state_log == NULL | 1149 | if (mctx->state_log == NULL |
| @@ -1148,7 +1152,7 @@ check_matching (re_match_context_t *mctx, bool fl_longest_match, | |||
| 1148 | break; | 1152 | break; |
| 1149 | } | 1153 | } |
| 1150 | 1154 | ||
| 1151 | if (BE (at_init_state, 0)) | 1155 | if (__glibc_unlikely (at_init_state)) |
| 1152 | { | 1156 | { |
| 1153 | if (old_state == cur_state) | 1157 | if (old_state == cur_state) |
| 1154 | next_start_idx = next_char_idx; | 1158 | next_start_idx = next_char_idx; |
| @@ -1237,7 +1241,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, | |||
| 1237 | re_node_set *edests = &dfa->edests[node]; | 1241 | re_node_set *edests = &dfa->edests[node]; |
| 1238 | Idx dest_node; | 1242 | Idx dest_node; |
| 1239 | ok = re_node_set_insert (eps_via_nodes, node); | 1243 | ok = re_node_set_insert (eps_via_nodes, node); |
| 1240 | if (BE (! ok, 0)) | 1244 | if (__glibc_unlikely (! ok)) |
| 1241 | return -2; | 1245 | return -2; |
| 1242 | /* Pick up a valid destination, or return -1 if none | 1246 | /* Pick up a valid destination, or return -1 if none |
| 1243 | is found. */ | 1247 | is found. */ |
| @@ -1299,7 +1303,7 @@ proceed_next_node (const re_match_context_t *mctx, Idx nregs, regmatch_t *regs, | |||
| 1299 | { | 1303 | { |
| 1300 | Idx dest_node; | 1304 | Idx dest_node; |
| 1301 | ok = re_node_set_insert (eps_via_nodes, node); | 1305 | ok = re_node_set_insert (eps_via_nodes, node); |
| 1302 | if (BE (! ok, 0)) | 1306 | if (__glibc_unlikely (! ok)) |
| 1303 | return -2; | 1307 | return -2; |
| 1304 | dest_node = dfa->edests[node].elems[0]; | 1308 | dest_node = dfa->edests[node].elems[0]; |
| 1305 | if (re_node_set_contains (&mctx->state_log[*pidx]->nodes, | 1309 | if (re_node_set_contains (&mctx->state_log[*pidx]->nodes, |
| @@ -1449,9 +1453,9 @@ set_regs (const regex_t *preg, const re_match_context_t *mctx, size_t nmatch, | |||
| 1449 | cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node, | 1453 | cur_node = proceed_next_node (mctx, nmatch, pmatch, &idx, cur_node, |
| 1450 | &eps_via_nodes, fs); | 1454 | &eps_via_nodes, fs); |
| 1451 | 1455 | ||
| 1452 | if (BE (cur_node < 0, 0)) | 1456 | if (__glibc_unlikely (cur_node < 0)) |
| 1453 | { | 1457 | { |
| 1454 | if (BE (cur_node == -2, 0)) | 1458 | if (__glibc_unlikely (cur_node == -2)) |
| 1455 | { | 1459 | { |
| 1456 | re_node_set_free (&eps_via_nodes); | 1460 | re_node_set_free (&eps_via_nodes); |
| 1457 | if (prev_idx_match_malloced) | 1461 | if (prev_idx_match_malloced) |
| @@ -1579,10 +1583,10 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) | |||
| 1579 | /* Build sifted state_log[str_idx]. It has the nodes which can epsilon | 1583 | /* Build sifted state_log[str_idx]. It has the nodes which can epsilon |
| 1580 | transit to the last_node and the last_node itself. */ | 1584 | transit to the last_node and the last_node itself. */ |
| 1581 | err = re_node_set_init_1 (&cur_dest, sctx->last_node); | 1585 | err = re_node_set_init_1 (&cur_dest, sctx->last_node); |
| 1582 | if (BE (err != REG_NOERROR, 0)) | 1586 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1583 | return err; | 1587 | return err; |
| 1584 | err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); | 1588 | err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); |
| 1585 | if (BE (err != REG_NOERROR, 0)) | 1589 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1586 | goto free_return; | 1590 | goto free_return; |
| 1587 | 1591 | ||
| 1588 | /* Then check each states in the state_log. */ | 1592 | /* Then check each states in the state_log. */ |
| @@ -1603,7 +1607,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) | |||
| 1603 | if (mctx->state_log[str_idx]) | 1607 | if (mctx->state_log[str_idx]) |
| 1604 | { | 1608 | { |
| 1605 | err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); | 1609 | err = build_sifted_states (mctx, sctx, str_idx, &cur_dest); |
| 1606 | if (BE (err != REG_NOERROR, 0)) | 1610 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1607 | goto free_return; | 1611 | goto free_return; |
| 1608 | } | 1612 | } |
| 1609 | 1613 | ||
| @@ -1612,7 +1616,7 @@ sift_states_backward (const re_match_context_t *mctx, re_sift_context_t *sctx) | |||
| 1612 | - It is in CUR_SRC. | 1616 | - It is in CUR_SRC. |
| 1613 | And update state_log. */ | 1617 | And update state_log. */ |
| 1614 | err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); | 1618 | err = update_cur_sifted_state (mctx, sctx, str_idx, &cur_dest); |
| 1615 | if (BE (err != REG_NOERROR, 0)) | 1619 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1616 | goto free_return; | 1620 | goto free_return; |
| 1617 | } | 1621 | } |
| 1618 | err = REG_NOERROR; | 1622 | err = REG_NOERROR; |
| @@ -1674,7 +1678,7 @@ build_sifted_states (const re_match_context_t *mctx, re_sift_context_t *sctx, | |||
| 1674 | continue; | 1678 | continue; |
| 1675 | } | 1679 | } |
| 1676 | ok = re_node_set_insert (cur_dest, prev_node); | 1680 | ok = re_node_set_insert (cur_dest, prev_node); |
| 1677 | if (BE (! ok, 0)) | 1681 | if (__glibc_unlikely (! ok)) |
| 1678 | return REG_ESPACE; | 1682 | return REG_ESPACE; |
| 1679 | } | 1683 | } |
| 1680 | 1684 | ||
| @@ -1695,7 +1699,7 @@ clean_state_log_if_needed (re_match_context_t *mctx, Idx next_state_log_idx) | |||
| 1695 | { | 1699 | { |
| 1696 | reg_errcode_t err; | 1700 | reg_errcode_t err; |
| 1697 | err = extend_buffers (mctx, next_state_log_idx + 1); | 1701 | err = extend_buffers (mctx, next_state_log_idx + 1); |
| 1698 | if (BE (err != REG_NOERROR, 0)) | 1702 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1699 | return err; | 1703 | return err; |
| 1700 | } | 1704 | } |
| 1701 | 1705 | ||
| @@ -1723,11 +1727,11 @@ merge_state_array (const re_dfa_t *dfa, re_dfastate_t **dst, | |||
| 1723 | re_node_set merged_set; | 1727 | re_node_set merged_set; |
| 1724 | err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes, | 1728 | err = re_node_set_init_union (&merged_set, &dst[st_idx]->nodes, |
| 1725 | &src[st_idx]->nodes); | 1729 | &src[st_idx]->nodes); |
| 1726 | if (BE (err != REG_NOERROR, 0)) | 1730 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1727 | return err; | 1731 | return err; |
| 1728 | dst[st_idx] = re_acquire_state (&err, dfa, &merged_set); | 1732 | dst[st_idx] = re_acquire_state (&err, dfa, &merged_set); |
| 1729 | re_node_set_free (&merged_set); | 1733 | re_node_set_free (&merged_set); |
| 1730 | if (BE (err != REG_NOERROR, 0)) | 1734 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1731 | return err; | 1735 | return err; |
| 1732 | } | 1736 | } |
| 1733 | } | 1737 | } |
| @@ -1754,7 +1758,7 @@ update_cur_sifted_state (const re_match_context_t *mctx, | |||
| 1754 | /* At first, add the nodes which can epsilon transit to a node in | 1758 | /* At first, add the nodes which can epsilon transit to a node in |
| 1755 | DEST_NODE. */ | 1759 | DEST_NODE. */ |
| 1756 | err = add_epsilon_src_nodes (dfa, dest_nodes, candidates); | 1760 | err = add_epsilon_src_nodes (dfa, dest_nodes, candidates); |
| 1757 | if (BE (err != REG_NOERROR, 0)) | 1761 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1758 | return err; | 1762 | return err; |
| 1759 | 1763 | ||
| 1760 | /* Then, check the limitations in the current sift_context. */ | 1764 | /* Then, check the limitations in the current sift_context. */ |
| @@ -1762,20 +1766,20 @@ update_cur_sifted_state (const re_match_context_t *mctx, | |||
| 1762 | { | 1766 | { |
| 1763 | err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits, | 1767 | err = check_subexp_limits (dfa, dest_nodes, candidates, &sctx->limits, |
| 1764 | mctx->bkref_ents, str_idx); | 1768 | mctx->bkref_ents, str_idx); |
| 1765 | if (BE (err != REG_NOERROR, 0)) | 1769 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1766 | return err; | 1770 | return err; |
| 1767 | } | 1771 | } |
| 1768 | } | 1772 | } |
| 1769 | 1773 | ||
| 1770 | sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes); | 1774 | sctx->sifted_states[str_idx] = re_acquire_state (&err, dfa, dest_nodes); |
| 1771 | if (BE (err != REG_NOERROR, 0)) | 1775 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1772 | return err; | 1776 | return err; |
| 1773 | } | 1777 | } |
| 1774 | 1778 | ||
| 1775 | if (candidates && mctx->state_log[str_idx]->has_backref) | 1779 | if (candidates && mctx->state_log[str_idx]->has_backref) |
| 1776 | { | 1780 | { |
| 1777 | err = sift_states_bkref (mctx, sctx, str_idx, candidates); | 1781 | err = sift_states_bkref (mctx, sctx, str_idx, candidates); |
| 1778 | if (BE (err != REG_NOERROR, 0)) | 1782 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1779 | return err; | 1783 | return err; |
| 1780 | } | 1784 | } |
| 1781 | return REG_NOERROR; | 1785 | return REG_NOERROR; |
| @@ -1790,19 +1794,19 @@ add_epsilon_src_nodes (const re_dfa_t *dfa, re_node_set *dest_nodes, | |||
| 1790 | Idx i; | 1794 | Idx i; |
| 1791 | 1795 | ||
| 1792 | re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes); | 1796 | re_dfastate_t *state = re_acquire_state (&err, dfa, dest_nodes); |
| 1793 | if (BE (err != REG_NOERROR, 0)) | 1797 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1794 | return err; | 1798 | return err; |
| 1795 | 1799 | ||
| 1796 | if (!state->inveclosure.alloc) | 1800 | if (!state->inveclosure.alloc) |
| 1797 | { | 1801 | { |
| 1798 | err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem); | 1802 | err = re_node_set_alloc (&state->inveclosure, dest_nodes->nelem); |
| 1799 | if (BE (err != REG_NOERROR, 0)) | 1803 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1800 | return REG_ESPACE; | 1804 | return REG_ESPACE; |
| 1801 | for (i = 0; i < dest_nodes->nelem; i++) | 1805 | for (i = 0; i < dest_nodes->nelem; i++) |
| 1802 | { | 1806 | { |
| 1803 | err = re_node_set_merge (&state->inveclosure, | 1807 | err = re_node_set_merge (&state->inveclosure, |
| 1804 | dfa->inveclosures + dest_nodes->elems[i]); | 1808 | dfa->inveclosures + dest_nodes->elems[i]); |
| 1805 | if (BE (err != REG_NOERROR, 0)) | 1809 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1806 | return REG_ESPACE; | 1810 | return REG_ESPACE; |
| 1807 | } | 1811 | } |
| 1808 | } | 1812 | } |
| @@ -1837,7 +1841,7 @@ sub_epsilon_src_nodes (const re_dfa_t *dfa, Idx node, re_node_set *dest_nodes, | |||
| 1837 | { | 1841 | { |
| 1838 | err = re_node_set_add_intersect (&except_nodes, candidates, | 1842 | err = re_node_set_add_intersect (&except_nodes, candidates, |
| 1839 | dfa->inveclosures + cur_node); | 1843 | dfa->inveclosures + cur_node); |
| 1840 | if (BE (err != REG_NOERROR, 0)) | 1844 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 1841 | { | 1845 | { |
| 1842 | re_node_set_free (&except_nodes); | 1846 | re_node_set_free (&except_nodes); |
| 1843 | return err; | 1847 | return err; |
| @@ -2043,7 +2047,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, | |||
| 2043 | { | 2047 | { |
| 2044 | err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes, | 2048 | err = sub_epsilon_src_nodes (dfa, ops_node, dest_nodes, |
| 2045 | candidates); | 2049 | candidates); |
| 2046 | if (BE (err != REG_NOERROR, 0)) | 2050 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2047 | return err; | 2051 | return err; |
| 2048 | } | 2052 | } |
| 2049 | 2053 | ||
| @@ -2061,7 +2065,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, | |||
| 2061 | Remove it form the current sifted state. */ | 2065 | Remove it form the current sifted state. */ |
| 2062 | err = sub_epsilon_src_nodes (dfa, node, dest_nodes, | 2066 | err = sub_epsilon_src_nodes (dfa, node, dest_nodes, |
| 2063 | candidates); | 2067 | candidates); |
| 2064 | if (BE (err != REG_NOERROR, 0)) | 2068 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2065 | return err; | 2069 | return err; |
| 2066 | --node_idx; | 2070 | --node_idx; |
| 2067 | } | 2071 | } |
| @@ -2081,7 +2085,7 @@ check_subexp_limits (const re_dfa_t *dfa, re_node_set *dest_nodes, | |||
| 2081 | Remove it form the current sifted state. */ | 2085 | Remove it form the current sifted state. */ |
| 2082 | err = sub_epsilon_src_nodes (dfa, node, dest_nodes, | 2086 | err = sub_epsilon_src_nodes (dfa, node, dest_nodes, |
| 2083 | candidates); | 2087 | candidates); |
| 2084 | if (BE (err != REG_NOERROR, 0)) | 2088 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2085 | return err; | 2089 | return err; |
| 2086 | } | 2090 | } |
| 2087 | } | 2091 | } |
| @@ -2147,27 +2151,27 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx, | |||
| 2147 | { | 2151 | { |
| 2148 | local_sctx = *sctx; | 2152 | local_sctx = *sctx; |
| 2149 | err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits); | 2153 | err = re_node_set_init_copy (&local_sctx.limits, &sctx->limits); |
| 2150 | if (BE (err != REG_NOERROR, 0)) | 2154 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2151 | goto free_return; | 2155 | goto free_return; |
| 2152 | } | 2156 | } |
| 2153 | local_sctx.last_node = node; | 2157 | local_sctx.last_node = node; |
| 2154 | local_sctx.last_str_idx = str_idx; | 2158 | local_sctx.last_str_idx = str_idx; |
| 2155 | ok = re_node_set_insert (&local_sctx.limits, enabled_idx); | 2159 | ok = re_node_set_insert (&local_sctx.limits, enabled_idx); |
| 2156 | if (BE (! ok, 0)) | 2160 | if (__glibc_unlikely (! ok)) |
| 2157 | { | 2161 | { |
| 2158 | err = REG_ESPACE; | 2162 | err = REG_ESPACE; |
| 2159 | goto free_return; | 2163 | goto free_return; |
| 2160 | } | 2164 | } |
| 2161 | cur_state = local_sctx.sifted_states[str_idx]; | 2165 | cur_state = local_sctx.sifted_states[str_idx]; |
| 2162 | err = sift_states_backward (mctx, &local_sctx); | 2166 | err = sift_states_backward (mctx, &local_sctx); |
| 2163 | if (BE (err != REG_NOERROR, 0)) | 2167 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2164 | goto free_return; | 2168 | goto free_return; |
| 2165 | if (sctx->limited_states != NULL) | 2169 | if (sctx->limited_states != NULL) |
| 2166 | { | 2170 | { |
| 2167 | err = merge_state_array (dfa, sctx->limited_states, | 2171 | err = merge_state_array (dfa, sctx->limited_states, |
| 2168 | local_sctx.sifted_states, | 2172 | local_sctx.sifted_states, |
| 2169 | str_idx + 1); | 2173 | str_idx + 1); |
| 2170 | if (BE (err != REG_NOERROR, 0)) | 2174 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2171 | goto free_return; | 2175 | goto free_return; |
| 2172 | } | 2176 | } |
| 2173 | local_sctx.sifted_states[str_idx] = cur_state; | 2177 | local_sctx.sifted_states[str_idx] = cur_state; |
| @@ -2229,10 +2233,10 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx, | |||
| 2229 | 2233 | ||
| 2230 | #ifdef RE_ENABLE_I18N | 2234 | #ifdef RE_ENABLE_I18N |
| 2231 | /* If the current state can accept multibyte. */ | 2235 | /* If the current state can accept multibyte. */ |
| 2232 | if (BE (state->accept_mb, 0)) | 2236 | if (__glibc_unlikely (state->accept_mb)) |
| 2233 | { | 2237 | { |
| 2234 | *err = transit_state_mb (mctx, state); | 2238 | *err = transit_state_mb (mctx, state); |
| 2235 | if (BE (*err != REG_NOERROR, 0)) | 2239 | if (__glibc_unlikely (*err != REG_NOERROR)) |
| 2236 | return NULL; | 2240 | return NULL; |
| 2237 | } | 2241 | } |
| 2238 | #endif /* RE_ENABLE_I18N */ | 2242 | #endif /* RE_ENABLE_I18N */ |
| @@ -2249,11 +2253,11 @@ transit_state (reg_errcode_t *err, re_match_context_t *mctx, | |||
| 2249 | for (;;) | 2253 | for (;;) |
| 2250 | { | 2254 | { |
| 2251 | trtable = state->trtable; | 2255 | trtable = state->trtable; |
| 2252 | if (BE (trtable != NULL, 1)) | 2256 | if (__glibc_likely (trtable != NULL)) |
| 2253 | return trtable[ch]; | 2257 | return trtable[ch]; |
| 2254 | 2258 | ||
| 2255 | trtable = state->word_trtable; | 2259 | trtable = state->word_trtable; |
| 2256 | if (BE (trtable != NULL, 1)) | 2260 | if (__glibc_likely (trtable != NULL)) |
| 2257 | { | 2261 | { |
| 2258 | unsigned int context; | 2262 | unsigned int context; |
| 2259 | context | 2263 | context |
| @@ -2309,7 +2313,7 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, | |||
| 2309 | table_nodes = next_state->entrance_nodes; | 2313 | table_nodes = next_state->entrance_nodes; |
| 2310 | *err = re_node_set_init_union (&next_nodes, table_nodes, | 2314 | *err = re_node_set_init_union (&next_nodes, table_nodes, |
| 2311 | log_nodes); | 2315 | log_nodes); |
| 2312 | if (BE (*err != REG_NOERROR, 0)) | 2316 | if (__glibc_unlikely (*err != REG_NOERROR)) |
| 2313 | return NULL; | 2317 | return NULL; |
| 2314 | } | 2318 | } |
| 2315 | else | 2319 | else |
| @@ -2329,21 +2333,21 @@ merge_state_with_log (reg_errcode_t *err, re_match_context_t *mctx, | |||
| 2329 | re_node_set_free (&next_nodes); | 2333 | re_node_set_free (&next_nodes); |
| 2330 | } | 2334 | } |
| 2331 | 2335 | ||
| 2332 | if (BE (dfa->nbackref, 0) && next_state != NULL) | 2336 | if (__glibc_unlikely (dfa->nbackref) && next_state != NULL) |
| 2333 | { | 2337 | { |
| 2334 | /* Check OP_OPEN_SUBEXP in the current state in case that we use them | 2338 | /* Check OP_OPEN_SUBEXP in the current state in case that we use them |
| 2335 | later. We must check them here, since the back references in the | 2339 | later. We must check them here, since the back references in the |
| 2336 | next state might use them. */ | 2340 | next state might use them. */ |
| 2337 | *err = check_subexp_matching_top (mctx, &next_state->nodes, | 2341 | *err = check_subexp_matching_top (mctx, &next_state->nodes, |
| 2338 | cur_idx); | 2342 | cur_idx); |
| 2339 | if (BE (*err != REG_NOERROR, 0)) | 2343 | if (__glibc_unlikely (*err != REG_NOERROR)) |
| 2340 | return NULL; | 2344 | return NULL; |
| 2341 | 2345 | ||
| 2342 | /* If the next state has back references. */ | 2346 | /* If the next state has back references. */ |
| 2343 | if (next_state->has_backref) | 2347 | if (next_state->has_backref) |
| 2344 | { | 2348 | { |
| 2345 | *err = transit_state_bkref (mctx, &next_state->nodes); | 2349 | *err = transit_state_bkref (mctx, &next_state->nodes); |
| 2346 | if (BE (*err != REG_NOERROR, 0)) | 2350 | if (__glibc_unlikely (*err != REG_NOERROR)) |
| 2347 | return NULL; | 2351 | return NULL; |
| 2348 | next_state = mctx->state_log[cur_idx]; | 2352 | next_state = mctx->state_log[cur_idx]; |
| 2349 | } | 2353 | } |
| @@ -2407,7 +2411,7 @@ check_subexp_matching_top (re_match_context_t *mctx, re_node_set *cur_nodes, | |||
| 2407 | & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) | 2411 | & ((bitset_word_t) 1 << dfa->nodes[node].opr.idx))) |
| 2408 | { | 2412 | { |
| 2409 | err = match_ctx_add_subtop (mctx, node, str_idx); | 2413 | err = match_ctx_add_subtop (mctx, node, str_idx); |
| 2410 | if (BE (err != REG_NOERROR, 0)) | 2414 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2411 | return err; | 2415 | return err; |
| 2412 | } | 2416 | } |
| 2413 | } | 2417 | } |
| @@ -2429,7 +2433,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, | |||
| 2429 | unsigned int context; | 2433 | unsigned int context; |
| 2430 | 2434 | ||
| 2431 | *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1); | 2435 | *err = re_node_set_alloc (&next_nodes, state->nodes.nelem + 1); |
| 2432 | if (BE (*err != REG_NOERROR, 0)) | 2436 | if (__glibc_unlikely (*err != REG_NOERROR)) |
| 2433 | return NULL; | 2437 | return NULL; |
| 2434 | for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt) | 2438 | for (node_cnt = 0; node_cnt < state->nodes.nelem; ++node_cnt) |
| 2435 | { | 2439 | { |
| @@ -2438,7 +2442,7 @@ transit_state_sb (reg_errcode_t *err, re_match_context_t *mctx, | |||
| 2438 | { | 2442 | { |
| 2439 | *err = re_node_set_merge (&next_nodes, | 2443 | *err = re_node_set_merge (&next_nodes, |
| 2440 | dfa->eclosures + dfa->nexts[cur_node]); | 2444 | dfa->eclosures + dfa->nexts[cur_node]); |
| 2441 | if (BE (*err != REG_NOERROR, 0)) | 2445 | if (__glibc_unlikely (*err != REG_NOERROR)) |
| 2442 | { | 2446 | { |
| 2443 | re_node_set_free (&next_nodes); | 2447 | re_node_set_free (&next_nodes); |
| 2444 | return NULL; | 2448 | return NULL; |
| @@ -2497,7 +2501,7 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) | |||
| 2497 | mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted | 2501 | mctx->max_mb_elem_len = ((mctx->max_mb_elem_len < naccepted) ? naccepted |
| 2498 | : mctx->max_mb_elem_len); | 2502 | : mctx->max_mb_elem_len); |
| 2499 | err = clean_state_log_if_needed (mctx, dest_idx); | 2503 | err = clean_state_log_if_needed (mctx, dest_idx); |
| 2500 | if (BE (err != REG_NOERROR, 0)) | 2504 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2501 | return err; | 2505 | return err; |
| 2502 | #ifdef DEBUG | 2506 | #ifdef DEBUG |
| 2503 | assert (dfa->nexts[cur_node_idx] != -1); | 2507 | assert (dfa->nexts[cur_node_idx] != -1); |
| @@ -2511,7 +2515,7 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) | |||
| 2511 | { | 2515 | { |
| 2512 | err = re_node_set_init_union (&dest_nodes, | 2516 | err = re_node_set_init_union (&dest_nodes, |
| 2513 | dest_state->entrance_nodes, new_nodes); | 2517 | dest_state->entrance_nodes, new_nodes); |
| 2514 | if (BE (err != REG_NOERROR, 0)) | 2518 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2515 | return err; | 2519 | return err; |
| 2516 | } | 2520 | } |
| 2517 | context = re_string_context_at (&mctx->input, dest_idx - 1, | 2521 | context = re_string_context_at (&mctx->input, dest_idx - 1, |
| @@ -2520,7 +2524,8 @@ transit_state_mb (re_match_context_t *mctx, re_dfastate_t *pstate) | |||
| 2520 | = re_acquire_state_context (&err, dfa, &dest_nodes, context); | 2524 | = re_acquire_state_context (&err, dfa, &dest_nodes, context); |
| 2521 | if (dest_state != NULL) | 2525 | if (dest_state != NULL) |
| 2522 | re_node_set_free (&dest_nodes); | 2526 | re_node_set_free (&dest_nodes); |
| 2523 | if (BE (mctx->state_log[dest_idx] == NULL && err != REG_NOERROR, 0)) | 2527 | if (__glibc_unlikely (mctx->state_log[dest_idx] == NULL |
| 2528 | && err != REG_NOERROR)) | ||
| 2524 | return err; | 2529 | return err; |
| 2525 | } | 2530 | } |
| 2526 | return REG_NOERROR; | 2531 | return REG_NOERROR; |
| @@ -2559,7 +2564,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) | |||
| 2559 | Check the substring which the substring matched. */ | 2564 | Check the substring which the substring matched. */ |
| 2560 | bkc_idx = mctx->nbkref_ents; | 2565 | bkc_idx = mctx->nbkref_ents; |
| 2561 | err = get_subexp (mctx, node_idx, cur_str_idx); | 2566 | err = get_subexp (mctx, node_idx, cur_str_idx); |
| 2562 | if (BE (err != REG_NOERROR, 0)) | 2567 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2563 | goto free_return; | 2568 | goto free_return; |
| 2564 | 2569 | ||
| 2565 | /* And add the epsilon closures (which is 'new_dest_nodes') of | 2570 | /* And add the epsilon closures (which is 'new_dest_nodes') of |
| @@ -2592,8 +2597,8 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) | |||
| 2592 | mctx->state_log[dest_str_idx] | 2597 | mctx->state_log[dest_str_idx] |
| 2593 | = re_acquire_state_context (&err, dfa, new_dest_nodes, | 2598 | = re_acquire_state_context (&err, dfa, new_dest_nodes, |
| 2594 | context); | 2599 | context); |
| 2595 | if (BE (mctx->state_log[dest_str_idx] == NULL | 2600 | if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL |
| 2596 | && err != REG_NOERROR, 0)) | 2601 | && err != REG_NOERROR)) |
| 2597 | goto free_return; | 2602 | goto free_return; |
| 2598 | } | 2603 | } |
| 2599 | else | 2604 | else |
| @@ -2602,7 +2607,7 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) | |||
| 2602 | err = re_node_set_init_union (&dest_nodes, | 2607 | err = re_node_set_init_union (&dest_nodes, |
| 2603 | dest_state->entrance_nodes, | 2608 | dest_state->entrance_nodes, |
| 2604 | new_dest_nodes); | 2609 | new_dest_nodes); |
| 2605 | if (BE (err != REG_NOERROR, 0)) | 2610 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2606 | { | 2611 | { |
| 2607 | re_node_set_free (&dest_nodes); | 2612 | re_node_set_free (&dest_nodes); |
| 2608 | goto free_return; | 2613 | goto free_return; |
| @@ -2610,8 +2615,8 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) | |||
| 2610 | mctx->state_log[dest_str_idx] | 2615 | mctx->state_log[dest_str_idx] |
| 2611 | = re_acquire_state_context (&err, dfa, &dest_nodes, context); | 2616 | = re_acquire_state_context (&err, dfa, &dest_nodes, context); |
| 2612 | re_node_set_free (&dest_nodes); | 2617 | re_node_set_free (&dest_nodes); |
| 2613 | if (BE (mctx->state_log[dest_str_idx] == NULL | 2618 | if (__glibc_unlikely (mctx->state_log[dest_str_idx] == NULL |
| 2614 | && err != REG_NOERROR, 0)) | 2619 | && err != REG_NOERROR)) |
| 2615 | goto free_return; | 2620 | goto free_return; |
| 2616 | } | 2621 | } |
| 2617 | /* We need to check recursively if the backreference can epsilon | 2622 | /* We need to check recursively if the backreference can epsilon |
| @@ -2621,10 +2626,10 @@ transit_state_bkref (re_match_context_t *mctx, const re_node_set *nodes) | |||
| 2621 | { | 2626 | { |
| 2622 | err = check_subexp_matching_top (mctx, new_dest_nodes, | 2627 | err = check_subexp_matching_top (mctx, new_dest_nodes, |
| 2623 | cur_str_idx); | 2628 | cur_str_idx); |
| 2624 | if (BE (err != REG_NOERROR, 0)) | 2629 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2625 | goto free_return; | 2630 | goto free_return; |
| 2626 | err = transit_state_bkref (mctx, new_dest_nodes); | 2631 | err = transit_state_bkref (mctx, new_dest_nodes); |
| 2627 | if (BE (err != REG_NOERROR, 0)) | 2632 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2628 | goto free_return; | 2633 | goto free_return; |
| 2629 | } | 2634 | } |
| 2630 | } | 2635 | } |
| @@ -2685,7 +2690,8 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | |||
| 2685 | at the back reference? */ | 2690 | at the back reference? */ |
| 2686 | if (sl_str_diff > 0) | 2691 | if (sl_str_diff > 0) |
| 2687 | { | 2692 | { |
| 2688 | if (BE (bkref_str_off + sl_str_diff > mctx->input.valid_len, 0)) | 2693 | if (__glibc_unlikely (bkref_str_off + sl_str_diff |
| 2694 | > mctx->input.valid_len)) | ||
| 2689 | { | 2695 | { |
| 2690 | /* Not enough chars for a successful match. */ | 2696 | /* Not enough chars for a successful match. */ |
| 2691 | if (bkref_str_off + sl_str_diff > mctx->input.len) | 2697 | if (bkref_str_off + sl_str_diff > mctx->input.len) |
| @@ -2694,7 +2700,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | |||
| 2694 | err = clean_state_log_if_needed (mctx, | 2700 | err = clean_state_log_if_needed (mctx, |
| 2695 | bkref_str_off | 2701 | bkref_str_off |
| 2696 | + sl_str_diff); | 2702 | + sl_str_diff); |
| 2697 | if (BE (err != REG_NOERROR, 0)) | 2703 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2698 | return err; | 2704 | return err; |
| 2699 | buf = (const char *) re_string_get_buffer (&mctx->input); | 2705 | buf = (const char *) re_string_get_buffer (&mctx->input); |
| 2700 | } | 2706 | } |
| @@ -2713,7 +2719,7 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | |||
| 2713 | 2719 | ||
| 2714 | if (err == REG_NOMATCH) | 2720 | if (err == REG_NOMATCH) |
| 2715 | continue; | 2721 | continue; |
| 2716 | if (BE (err != REG_NOERROR, 0)) | 2722 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2717 | return err; | 2723 | return err; |
| 2718 | } | 2724 | } |
| 2719 | 2725 | ||
| @@ -2732,14 +2738,14 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | |||
| 2732 | at the back reference? */ | 2738 | at the back reference? */ |
| 2733 | if (sl_str_off > 0) | 2739 | if (sl_str_off > 0) |
| 2734 | { | 2740 | { |
| 2735 | if (BE (bkref_str_off >= mctx->input.valid_len, 0)) | 2741 | if (__glibc_unlikely (bkref_str_off >= mctx->input.valid_len)) |
| 2736 | { | 2742 | { |
| 2737 | /* If we are at the end of the input, we cannot match. */ | 2743 | /* If we are at the end of the input, we cannot match. */ |
| 2738 | if (bkref_str_off >= mctx->input.len) | 2744 | if (bkref_str_off >= mctx->input.len) |
| 2739 | break; | 2745 | break; |
| 2740 | 2746 | ||
| 2741 | err = extend_buffers (mctx, bkref_str_off + 1); | 2747 | err = extend_buffers (mctx, bkref_str_off + 1); |
| 2742 | if (BE (err != REG_NOERROR, 0)) | 2748 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2743 | return err; | 2749 | return err; |
| 2744 | 2750 | ||
| 2745 | buf = (const char *) re_string_get_buffer (&mctx->input); | 2751 | buf = (const char *) re_string_get_buffer (&mctx->input); |
| @@ -2770,10 +2776,10 @@ get_subexp (re_match_context_t *mctx, Idx bkref_node, Idx bkref_str_idx) | |||
| 2770 | OP_CLOSE_SUBEXP); | 2776 | OP_CLOSE_SUBEXP); |
| 2771 | if (err == REG_NOMATCH) | 2777 | if (err == REG_NOMATCH) |
| 2772 | continue; | 2778 | continue; |
| 2773 | if (BE (err != REG_NOERROR, 0)) | 2779 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2774 | return err; | 2780 | return err; |
| 2775 | sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str); | 2781 | sub_last = match_ctx_add_sublast (sub_top, cls_node, sl_str); |
| 2776 | if (BE (sub_last == NULL, 0)) | 2782 | if (__glibc_unlikely (sub_last == NULL)) |
| 2777 | return REG_ESPACE; | 2783 | return REG_ESPACE; |
| 2778 | err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, | 2784 | err = get_subexp_sub (mctx, sub_top, sub_last, bkref_node, |
| 2779 | bkref_str_idx); | 2785 | bkref_str_idx); |
| @@ -2804,7 +2810,7 @@ get_subexp_sub (re_match_context_t *mctx, const re_sub_match_top_t *sub_top, | |||
| 2804 | return err; | 2810 | return err; |
| 2805 | err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, | 2811 | err = match_ctx_add_entry (mctx, bkref_node, bkref_str, sub_top->str_idx, |
| 2806 | sub_last->str_idx); | 2812 | sub_last->str_idx); |
| 2807 | if (BE (err != REG_NOERROR, 0)) | 2813 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2808 | return err; | 2814 | return err; |
| 2809 | to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx; | 2815 | to_idx = bkref_str + sub_last->str_idx - sub_top->str_idx; |
| 2810 | return clean_state_log_if_needed (mctx, to_idx); | 2816 | return clean_state_log_if_needed (mctx, to_idx); |
| @@ -2854,19 +2860,19 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2854 | 2860 | ||
| 2855 | subexp_num = dfa->nodes[top_node].opr.idx; | 2861 | subexp_num = dfa->nodes[top_node].opr.idx; |
| 2856 | /* Extend the buffer if we need. */ | 2862 | /* Extend the buffer if we need. */ |
| 2857 | if (BE (path->alloc < last_str + mctx->max_mb_elem_len + 1, 0)) | 2863 | if (__glibc_unlikely (path->alloc < last_str + mctx->max_mb_elem_len + 1)) |
| 2858 | { | 2864 | { |
| 2859 | re_dfastate_t **new_array; | 2865 | re_dfastate_t **new_array; |
| 2860 | Idx old_alloc = path->alloc; | 2866 | Idx old_alloc = path->alloc; |
| 2861 | Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1; | 2867 | Idx incr_alloc = last_str + mctx->max_mb_elem_len + 1; |
| 2862 | Idx new_alloc; | 2868 | Idx new_alloc; |
| 2863 | if (BE (IDX_MAX - old_alloc < incr_alloc, 0)) | 2869 | if (__glibc_unlikely (IDX_MAX - old_alloc < incr_alloc)) |
| 2864 | return REG_ESPACE; | 2870 | return REG_ESPACE; |
| 2865 | new_alloc = old_alloc + incr_alloc; | 2871 | new_alloc = old_alloc + incr_alloc; |
| 2866 | if (BE (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc, 0)) | 2872 | if (__glibc_unlikely (SIZE_MAX / sizeof (re_dfastate_t *) < new_alloc)) |
| 2867 | return REG_ESPACE; | 2873 | return REG_ESPACE; |
| 2868 | new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); | 2874 | new_array = re_realloc (path->array, re_dfastate_t *, new_alloc); |
| 2869 | if (BE (new_array == NULL, 0)) | 2875 | if (__glibc_unlikely (new_array == NULL)) |
| 2870 | return REG_ESPACE; | 2876 | return REG_ESPACE; |
| 2871 | path->array = new_array; | 2877 | path->array = new_array; |
| 2872 | path->alloc = new_alloc; | 2878 | path->alloc = new_alloc; |
| @@ -2887,10 +2893,10 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2887 | if (str_idx == top_str) | 2893 | if (str_idx == top_str) |
| 2888 | { | 2894 | { |
| 2889 | err = re_node_set_init_1 (&next_nodes, top_node); | 2895 | err = re_node_set_init_1 (&next_nodes, top_node); |
| 2890 | if (BE (err != REG_NOERROR, 0)) | 2896 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2891 | return err; | 2897 | return err; |
| 2892 | err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); | 2898 | err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); |
| 2893 | if (BE (err != REG_NOERROR, 0)) | 2899 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2894 | { | 2900 | { |
| 2895 | re_node_set_free (&next_nodes); | 2901 | re_node_set_free (&next_nodes); |
| 2896 | return err; | 2902 | return err; |
| @@ -2902,7 +2908,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2902 | if (cur_state && cur_state->has_backref) | 2908 | if (cur_state && cur_state->has_backref) |
| 2903 | { | 2909 | { |
| 2904 | err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); | 2910 | err = re_node_set_init_copy (&next_nodes, &cur_state->nodes); |
| 2905 | if (BE (err != REG_NOERROR, 0)) | 2911 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2906 | return err; | 2912 | return err; |
| 2907 | } | 2913 | } |
| 2908 | else | 2914 | else |
| @@ -2914,14 +2920,14 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2914 | { | 2920 | { |
| 2915 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, | 2921 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, |
| 2916 | subexp_num, type); | 2922 | subexp_num, type); |
| 2917 | if (BE (err != REG_NOERROR, 0)) | 2923 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2918 | { | 2924 | { |
| 2919 | re_node_set_free (&next_nodes); | 2925 | re_node_set_free (&next_nodes); |
| 2920 | return err; | 2926 | return err; |
| 2921 | } | 2927 | } |
| 2922 | } | 2928 | } |
| 2923 | cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); | 2929 | cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); |
| 2924 | if (BE (cur_state == NULL && err != REG_NOERROR, 0)) | 2930 | if (__glibc_unlikely (cur_state == NULL && err != REG_NOERROR)) |
| 2925 | { | 2931 | { |
| 2926 | re_node_set_free (&next_nodes); | 2932 | re_node_set_free (&next_nodes); |
| 2927 | return err; | 2933 | return err; |
| @@ -2936,7 +2942,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2936 | { | 2942 | { |
| 2937 | err = re_node_set_merge (&next_nodes, | 2943 | err = re_node_set_merge (&next_nodes, |
| 2938 | &mctx->state_log[str_idx + 1]->nodes); | 2944 | &mctx->state_log[str_idx + 1]->nodes); |
| 2939 | if (BE (err != REG_NOERROR, 0)) | 2945 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2940 | { | 2946 | { |
| 2941 | re_node_set_free (&next_nodes); | 2947 | re_node_set_free (&next_nodes); |
| 2942 | return err; | 2948 | return err; |
| @@ -2947,7 +2953,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2947 | err = check_arrival_add_next_nodes (mctx, str_idx, | 2953 | err = check_arrival_add_next_nodes (mctx, str_idx, |
| 2948 | &cur_state->non_eps_nodes, | 2954 | &cur_state->non_eps_nodes, |
| 2949 | &next_nodes); | 2955 | &next_nodes); |
| 2950 | if (BE (err != REG_NOERROR, 0)) | 2956 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2951 | { | 2957 | { |
| 2952 | re_node_set_free (&next_nodes); | 2958 | re_node_set_free (&next_nodes); |
| 2953 | return err; | 2959 | return err; |
| @@ -2957,14 +2963,14 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2957 | if (next_nodes.nelem) | 2963 | if (next_nodes.nelem) |
| 2958 | { | 2964 | { |
| 2959 | err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); | 2965 | err = check_arrival_expand_ecl (dfa, &next_nodes, subexp_num, type); |
| 2960 | if (BE (err != REG_NOERROR, 0)) | 2966 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2961 | { | 2967 | { |
| 2962 | re_node_set_free (&next_nodes); | 2968 | re_node_set_free (&next_nodes); |
| 2963 | return err; | 2969 | return err; |
| 2964 | } | 2970 | } |
| 2965 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, | 2971 | err = expand_bkref_cache (mctx, &next_nodes, str_idx, |
| 2966 | subexp_num, type); | 2972 | subexp_num, type); |
| 2967 | if (BE (err != REG_NOERROR, 0)) | 2973 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 2968 | { | 2974 | { |
| 2969 | re_node_set_free (&next_nodes); | 2975 | re_node_set_free (&next_nodes); |
| 2970 | return err; | 2976 | return err; |
| @@ -2972,7 +2978,7 @@ check_arrival (re_match_context_t *mctx, state_array_t *path, Idx top_node, | |||
| 2972 | } | 2978 | } |
| 2973 | context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); | 2979 | context = re_string_context_at (&mctx->input, str_idx - 1, mctx->eflags); |
| 2974 | cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); | 2980 | cur_state = re_acquire_state_context (&err, dfa, &next_nodes, context); |
| 2975 | if (BE (cur_state == NULL && err != REG_NOERROR, 0)) | 2981 | if (__glibc_unlikely (cur_state == NULL && err != REG_NOERROR)) |
| 2976 | { | 2982 | { |
| 2977 | re_node_set_free (&next_nodes); | 2983 | re_node_set_free (&next_nodes); |
| 2978 | return err; | 2984 | return err; |
| @@ -3041,22 +3047,22 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, | |||
| 3041 | if (dest_state) | 3047 | if (dest_state) |
| 3042 | { | 3048 | { |
| 3043 | err = re_node_set_merge (&union_set, &dest_state->nodes); | 3049 | err = re_node_set_merge (&union_set, &dest_state->nodes); |
| 3044 | if (BE (err != REG_NOERROR, 0)) | 3050 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3045 | { | 3051 | { |
| 3046 | re_node_set_free (&union_set); | 3052 | re_node_set_free (&union_set); |
| 3047 | return err; | 3053 | return err; |
| 3048 | } | 3054 | } |
| 3049 | } | 3055 | } |
| 3050 | ok = re_node_set_insert (&union_set, next_node); | 3056 | ok = re_node_set_insert (&union_set, next_node); |
| 3051 | if (BE (! ok, 0)) | 3057 | if (__glibc_unlikely (! ok)) |
| 3052 | { | 3058 | { |
| 3053 | re_node_set_free (&union_set); | 3059 | re_node_set_free (&union_set); |
| 3054 | return REG_ESPACE; | 3060 | return REG_ESPACE; |
| 3055 | } | 3061 | } |
| 3056 | mctx->state_log[next_idx] = re_acquire_state (&err, dfa, | 3062 | mctx->state_log[next_idx] = re_acquire_state (&err, dfa, |
| 3057 | &union_set); | 3063 | &union_set); |
| 3058 | if (BE (mctx->state_log[next_idx] == NULL | 3064 | if (__glibc_unlikely (mctx->state_log[next_idx] == NULL |
| 3059 | && err != REG_NOERROR, 0)) | 3065 | && err != REG_NOERROR)) |
| 3060 | { | 3066 | { |
| 3061 | re_node_set_free (&union_set); | 3067 | re_node_set_free (&union_set); |
| 3062 | return err; | 3068 | return err; |
| @@ -3068,7 +3074,7 @@ check_arrival_add_next_nodes (re_match_context_t *mctx, Idx str_idx, | |||
| 3068 | || check_node_accept (mctx, dfa->nodes + cur_node, str_idx)) | 3074 | || check_node_accept (mctx, dfa->nodes + cur_node, str_idx)) |
| 3069 | { | 3075 | { |
| 3070 | ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]); | 3076 | ok = re_node_set_insert (next_nodes, dfa->nexts[cur_node]); |
| 3071 | if (BE (! ok, 0)) | 3077 | if (__glibc_unlikely (! ok)) |
| 3072 | { | 3078 | { |
| 3073 | re_node_set_free (&union_set); | 3079 | re_node_set_free (&union_set); |
| 3074 | return REG_ESPACE; | 3080 | return REG_ESPACE; |
| @@ -3096,7 +3102,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, | |||
| 3096 | assert (cur_nodes->nelem); | 3102 | assert (cur_nodes->nelem); |
| 3097 | #endif | 3103 | #endif |
| 3098 | err = re_node_set_alloc (&new_nodes, cur_nodes->nelem); | 3104 | err = re_node_set_alloc (&new_nodes, cur_nodes->nelem); |
| 3099 | if (BE (err != REG_NOERROR, 0)) | 3105 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3100 | return err; | 3106 | return err; |
| 3101 | /* Create a new node set NEW_NODES with the nodes which are epsilon | 3107 | /* Create a new node set NEW_NODES with the nodes which are epsilon |
| 3102 | closures of the node in CUR_NODES. */ | 3108 | closures of the node in CUR_NODES. */ |
| @@ -3110,7 +3116,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, | |||
| 3110 | { | 3116 | { |
| 3111 | /* There are no problematic nodes, just merge them. */ | 3117 | /* There are no problematic nodes, just merge them. */ |
| 3112 | err = re_node_set_merge (&new_nodes, eclosure); | 3118 | err = re_node_set_merge (&new_nodes, eclosure); |
| 3113 | if (BE (err != REG_NOERROR, 0)) | 3119 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3114 | { | 3120 | { |
| 3115 | re_node_set_free (&new_nodes); | 3121 | re_node_set_free (&new_nodes); |
| 3116 | return err; | 3122 | return err; |
| @@ -3121,7 +3127,7 @@ check_arrival_expand_ecl (const re_dfa_t *dfa, re_node_set *cur_nodes, | |||
| 3121 | /* There are problematic nodes, re-calculate incrementally. */ | 3127 | /* There are problematic nodes, re-calculate incrementally. */ |
| 3122 | err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node, | 3128 | err = check_arrival_expand_ecl_sub (dfa, &new_nodes, cur_node, |
| 3123 | ex_subexp, type); | 3129 | ex_subexp, type); |
| 3124 | if (BE (err != REG_NOERROR, 0)) | 3130 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3125 | { | 3131 | { |
| 3126 | re_node_set_free (&new_nodes); | 3132 | re_node_set_free (&new_nodes); |
| 3127 | return err; | 3133 | return err; |
| @@ -3153,13 +3159,13 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, | |||
| 3153 | if (type == OP_CLOSE_SUBEXP) | 3159 | if (type == OP_CLOSE_SUBEXP) |
| 3154 | { | 3160 | { |
| 3155 | ok = re_node_set_insert (dst_nodes, cur_node); | 3161 | ok = re_node_set_insert (dst_nodes, cur_node); |
| 3156 | if (BE (! ok, 0)) | 3162 | if (__glibc_unlikely (! ok)) |
| 3157 | return REG_ESPACE; | 3163 | return REG_ESPACE; |
| 3158 | } | 3164 | } |
| 3159 | break; | 3165 | break; |
| 3160 | } | 3166 | } |
| 3161 | ok = re_node_set_insert (dst_nodes, cur_node); | 3167 | ok = re_node_set_insert (dst_nodes, cur_node); |
| 3162 | if (BE (! ok, 0)) | 3168 | if (__glibc_unlikely (! ok)) |
| 3163 | return REG_ESPACE; | 3169 | return REG_ESPACE; |
| 3164 | if (dfa->edests[cur_node].nelem == 0) | 3170 | if (dfa->edests[cur_node].nelem == 0) |
| 3165 | break; | 3171 | break; |
| @@ -3169,7 +3175,7 @@ check_arrival_expand_ecl_sub (const re_dfa_t *dfa, re_node_set *dst_nodes, | |||
| 3169 | err = check_arrival_expand_ecl_sub (dfa, dst_nodes, | 3175 | err = check_arrival_expand_ecl_sub (dfa, dst_nodes, |
| 3170 | dfa->edests[cur_node].elems[1], | 3176 | dfa->edests[cur_node].elems[1], |
| 3171 | ex_subexp, type); | 3177 | ex_subexp, type); |
| 3172 | if (BE (err != REG_NOERROR, 0)) | 3178 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3173 | return err; | 3179 | return err; |
| 3174 | } | 3180 | } |
| 3175 | cur_node = dfa->edests[cur_node].elems[0]; | 3181 | cur_node = dfa->edests[cur_node].elems[0]; |
| @@ -3221,8 +3227,8 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, | |||
| 3221 | err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type); | 3227 | err2 = check_arrival_expand_ecl (dfa, &new_dests, subexp_num, type); |
| 3222 | err3 = re_node_set_merge (cur_nodes, &new_dests); | 3228 | err3 = re_node_set_merge (cur_nodes, &new_dests); |
| 3223 | re_node_set_free (&new_dests); | 3229 | re_node_set_free (&new_dests); |
| 3224 | if (BE (err != REG_NOERROR || err2 != REG_NOERROR | 3230 | if (__glibc_unlikely (err != REG_NOERROR || err2 != REG_NOERROR |
| 3225 | || err3 != REG_NOERROR, 0)) | 3231 | || err3 != REG_NOERROR)) |
| 3226 | { | 3232 | { |
| 3227 | err = (err != REG_NOERROR ? err | 3233 | err = (err != REG_NOERROR ? err |
| 3228 | : (err2 != REG_NOERROR ? err2 : err3)); | 3234 | : (err2 != REG_NOERROR ? err2 : err3)); |
| @@ -3244,7 +3250,7 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, | |||
| 3244 | err = re_node_set_init_copy (&union_set, | 3250 | err = re_node_set_init_copy (&union_set, |
| 3245 | &mctx->state_log[to_idx]->nodes); | 3251 | &mctx->state_log[to_idx]->nodes); |
| 3246 | ok = re_node_set_insert (&union_set, next_node); | 3252 | ok = re_node_set_insert (&union_set, next_node); |
| 3247 | if (BE (err != REG_NOERROR || ! ok, 0)) | 3253 | if (__glibc_unlikely (err != REG_NOERROR || ! ok)) |
| 3248 | { | 3254 | { |
| 3249 | re_node_set_free (&union_set); | 3255 | re_node_set_free (&union_set); |
| 3250 | err = err != REG_NOERROR ? err : REG_ESPACE; | 3256 | err = err != REG_NOERROR ? err : REG_ESPACE; |
| @@ -3254,13 +3260,13 @@ expand_bkref_cache (re_match_context_t *mctx, re_node_set *cur_nodes, | |||
| 3254 | else | 3260 | else |
| 3255 | { | 3261 | { |
| 3256 | err = re_node_set_init_1 (&union_set, next_node); | 3262 | err = re_node_set_init_1 (&union_set, next_node); |
| 3257 | if (BE (err != REG_NOERROR, 0)) | 3263 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3258 | return err; | 3264 | return err; |
| 3259 | } | 3265 | } |
| 3260 | mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set); | 3266 | mctx->state_log[to_idx] = re_acquire_state (&err, dfa, &union_set); |
| 3261 | re_node_set_free (&union_set); | 3267 | re_node_set_free (&union_set); |
| 3262 | if (BE (mctx->state_log[to_idx] == NULL | 3268 | if (__glibc_unlikely (mctx->state_log[to_idx] == NULL |
| 3263 | && err != REG_NOERROR, 0)) | 3269 | && err != REG_NOERROR)) |
| 3264 | return err; | 3270 | return err; |
| 3265 | } | 3271 | } |
| 3266 | } | 3272 | } |
| @@ -3303,7 +3309,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) | |||
| 3303 | else | 3309 | else |
| 3304 | { | 3310 | { |
| 3305 | dests_alloc = re_malloc (struct dests_alloc, 1); | 3311 | dests_alloc = re_malloc (struct dests_alloc, 1); |
| 3306 | if (BE (dests_alloc == NULL, 0)) | 3312 | if (__glibc_unlikely (dests_alloc == NULL)) |
| 3307 | return false; | 3313 | return false; |
| 3308 | dests_node_malloced = true; | 3314 | dests_node_malloced = true; |
| 3309 | } | 3315 | } |
| @@ -3316,7 +3322,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) | |||
| 3316 | /* At first, group all nodes belonging to 'state' into several | 3322 | /* At first, group all nodes belonging to 'state' into several |
| 3317 | destinations. */ | 3323 | destinations. */ |
| 3318 | ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); | 3324 | ndests = group_nodes_into_DFAstates (dfa, state, dests_node, dests_ch); |
| 3319 | if (BE (ndests <= 0, 0)) | 3325 | if (__glibc_unlikely (ndests <= 0)) |
| 3320 | { | 3326 | { |
| 3321 | if (dests_node_malloced) | 3327 | if (dests_node_malloced) |
| 3322 | re_free (dests_alloc); | 3328 | re_free (dests_alloc); |
| @@ -3325,7 +3331,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) | |||
| 3325 | { | 3331 | { |
| 3326 | state->trtable = (re_dfastate_t **) | 3332 | state->trtable = (re_dfastate_t **) |
| 3327 | calloc (sizeof (re_dfastate_t *), SBC_MAX); | 3333 | calloc (sizeof (re_dfastate_t *), SBC_MAX); |
| 3328 | if (BE (state->trtable == NULL, 0)) | 3334 | if (__glibc_unlikely (state->trtable == NULL)) |
| 3329 | return false; | 3335 | return false; |
| 3330 | return true; | 3336 | return true; |
| 3331 | } | 3337 | } |
| @@ -3333,14 +3339,14 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) | |||
| 3333 | } | 3339 | } |
| 3334 | 3340 | ||
| 3335 | err = re_node_set_alloc (&follows, ndests + 1); | 3341 | err = re_node_set_alloc (&follows, ndests + 1); |
| 3336 | if (BE (err != REG_NOERROR, 0)) | 3342 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3337 | goto out_free; | 3343 | goto out_free; |
| 3338 | 3344 | ||
| 3339 | /* Avoid arithmetic overflow in size calculation. */ | 3345 | /* Avoid arithmetic overflow in size calculation. */ |
| 3340 | if (BE ((((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX) | 3346 | size_t ndests_max |
| 3341 | / (3 * sizeof (re_dfastate_t *))) | 3347 | = ((SIZE_MAX - (sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX) |
| 3342 | < ndests), | 3348 | / (3 * sizeof (re_dfastate_t *))); |
| 3343 | 0)) | 3349 | if (__glibc_unlikely (ndests_max < ndests)) |
| 3344 | goto out_free; | 3350 | goto out_free; |
| 3345 | 3351 | ||
| 3346 | if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX | 3352 | if (__libc_use_alloca ((sizeof (re_node_set) + sizeof (bitset_t)) * SBC_MAX |
| @@ -3350,7 +3356,7 @@ build_trtable (const re_dfa_t *dfa, re_dfastate_t *state) | |||
| 3350 | else | 3356 | else |
| 3351 | { | 3357 | { |
| 3352 | dest_states = re_malloc (re_dfastate_t *, ndests * 3); | 3358 | dest_states = re_malloc (re_dfastate_t *, ndests * 3); |
| 3353 | if (BE (dest_states == NULL, 0)) | 3359 | if (__glibc_unlikely (dest_states == NULL)) |
| 3354 | { | 3360 | { |
| 3355 | out_free: | 3361 | out_free: |
| 3356 | if (dest_states_malloced) | 3362 | if (dest_states_malloced) |
| @@ -3380,12 +3386,12 @@ out_free: | |||
| 3380 | if (next_node != -1) | 3386 | if (next_node != -1) |
| 3381 | { | 3387 | { |
| 3382 | err = re_node_set_merge (&follows, dfa->eclosures + next_node); | 3388 | err = re_node_set_merge (&follows, dfa->eclosures + next_node); |
| 3383 | if (BE (err != REG_NOERROR, 0)) | 3389 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3384 | goto out_free; | 3390 | goto out_free; |
| 3385 | } | 3391 | } |
| 3386 | } | 3392 | } |
| 3387 | dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0); | 3393 | dest_states[i] = re_acquire_state_context (&err, dfa, &follows, 0); |
| 3388 | if (BE (dest_states[i] == NULL && err != REG_NOERROR, 0)) | 3394 | if (__glibc_unlikely (dest_states[i] == NULL && err != REG_NOERROR)) |
| 3389 | goto out_free; | 3395 | goto out_free; |
| 3390 | /* If the new state has context constraint, | 3396 | /* If the new state has context constraint, |
| 3391 | build appropriate states for these contexts. */ | 3397 | build appropriate states for these contexts. */ |
| @@ -3393,7 +3399,8 @@ out_free: | |||
| 3393 | { | 3399 | { |
| 3394 | dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows, | 3400 | dest_states_word[i] = re_acquire_state_context (&err, dfa, &follows, |
| 3395 | CONTEXT_WORD); | 3401 | CONTEXT_WORD); |
| 3396 | if (BE (dest_states_word[i] == NULL && err != REG_NOERROR, 0)) | 3402 | if (__glibc_unlikely (dest_states_word[i] == NULL |
| 3403 | && err != REG_NOERROR)) | ||
| 3397 | goto out_free; | 3404 | goto out_free; |
| 3398 | 3405 | ||
| 3399 | if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1) | 3406 | if (dest_states[i] != dest_states_word[i] && dfa->mb_cur_max > 1) |
| @@ -3401,7 +3408,7 @@ out_free: | |||
| 3401 | 3408 | ||
| 3402 | dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows, | 3409 | dest_states_nl[i] = re_acquire_state_context (&err, dfa, &follows, |
| 3403 | CONTEXT_NEWLINE); | 3410 | CONTEXT_NEWLINE); |
| 3404 | if (BE (dest_states_nl[i] == NULL && err != REG_NOERROR, 0)) | 3411 | if (__glibc_unlikely (dest_states_nl[i] == NULL && err != REG_NOERROR)) |
| 3405 | goto out_free; | 3412 | goto out_free; |
| 3406 | } | 3413 | } |
| 3407 | else | 3414 | else |
| @@ -3412,7 +3419,7 @@ out_free: | |||
| 3412 | bitset_merge (acceptable, dests_ch[i]); | 3419 | bitset_merge (acceptable, dests_ch[i]); |
| 3413 | } | 3420 | } |
| 3414 | 3421 | ||
| 3415 | if (!BE (need_word_trtable, 0)) | 3422 | if (!__glibc_unlikely (need_word_trtable)) |
| 3416 | { | 3423 | { |
| 3417 | /* We don't care about whether the following character is a word | 3424 | /* We don't care about whether the following character is a word |
| 3418 | character, or we are in a single-byte character set so we can | 3425 | character, or we are in a single-byte character set so we can |
| @@ -3420,7 +3427,7 @@ out_free: | |||
| 3420 | 256-entry transition table. */ | 3427 | 256-entry transition table. */ |
| 3421 | trtable = state->trtable = | 3428 | trtable = state->trtable = |
| 3422 | (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); | 3429 | (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), SBC_MAX); |
| 3423 | if (BE (trtable == NULL, 0)) | 3430 | if (__glibc_unlikely (trtable == NULL)) |
| 3424 | goto out_free; | 3431 | goto out_free; |
| 3425 | 3432 | ||
| 3426 | /* For all characters ch...: */ | 3433 | /* For all characters ch...: */ |
| @@ -3428,7 +3435,7 @@ out_free: | |||
| 3428 | for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; | 3435 | for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; |
| 3429 | elem; | 3436 | elem; |
| 3430 | mask <<= 1, elem >>= 1, ++ch) | 3437 | mask <<= 1, elem >>= 1, ++ch) |
| 3431 | if (BE (elem & 1, 0)) | 3438 | if (__glibc_unlikely (elem & 1)) |
| 3432 | { | 3439 | { |
| 3433 | /* There must be exactly one destination which accepts | 3440 | /* There must be exactly one destination which accepts |
| 3434 | character ch. See group_nodes_into_DFAstates. */ | 3441 | character ch. See group_nodes_into_DFAstates. */ |
| @@ -3451,7 +3458,7 @@ out_free: | |||
| 3451 | starting at trtable[SBC_MAX]. */ | 3458 | starting at trtable[SBC_MAX]. */ |
| 3452 | trtable = state->word_trtable = | 3459 | trtable = state->word_trtable = |
| 3453 | (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); | 3460 | (re_dfastate_t **) calloc (sizeof (re_dfastate_t *), 2 * SBC_MAX); |
| 3454 | if (BE (trtable == NULL, 0)) | 3461 | if (__glibc_unlikely (trtable == NULL)) |
| 3455 | goto out_free; | 3462 | goto out_free; |
| 3456 | 3463 | ||
| 3457 | /* For all characters ch...: */ | 3464 | /* For all characters ch...: */ |
| @@ -3459,7 +3466,7 @@ out_free: | |||
| 3459 | for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; | 3466 | for (ch = i * BITSET_WORD_BITS, elem = acceptable[i], mask = 1; |
| 3460 | elem; | 3467 | elem; |
| 3461 | mask <<= 1, elem >>= 1, ++ch) | 3468 | mask <<= 1, elem >>= 1, ++ch) |
| 3462 | if (BE (elem & 1, 0)) | 3469 | if (__glibc_unlikely (elem & 1)) |
| 3463 | { | 3470 | { |
| 3464 | /* There must be exactly one destination which accepts | 3471 | /* There must be exactly one destination which accepts |
| 3465 | character ch. See group_nodes_into_DFAstates. */ | 3472 | character ch. See group_nodes_into_DFAstates. */ |
| @@ -3658,14 +3665,14 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | |||
| 3658 | bitset_copy (dests_ch[ndests], remains); | 3665 | bitset_copy (dests_ch[ndests], remains); |
| 3659 | bitset_copy (dests_ch[j], intersec); | 3666 | bitset_copy (dests_ch[j], intersec); |
| 3660 | err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]); | 3667 | err = re_node_set_init_copy (dests_node + ndests, &dests_node[j]); |
| 3661 | if (BE (err != REG_NOERROR, 0)) | 3668 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3662 | goto error_return; | 3669 | goto error_return; |
| 3663 | ++ndests; | 3670 | ++ndests; |
| 3664 | } | 3671 | } |
| 3665 | 3672 | ||
| 3666 | /* Put the position in the current group. */ | 3673 | /* Put the position in the current group. */ |
| 3667 | ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]); | 3674 | ok = re_node_set_insert (&dests_node[j], cur_nodes->elems[i]); |
| 3668 | if (BE (! ok, 0)) | 3675 | if (__glibc_unlikely (! ok)) |
| 3669 | goto error_return; | 3676 | goto error_return; |
| 3670 | 3677 | ||
| 3671 | /* If all characters are consumed, go to next node. */ | 3678 | /* If all characters are consumed, go to next node. */ |
| @@ -3677,7 +3684,7 @@ group_nodes_into_DFAstates (const re_dfa_t *dfa, const re_dfastate_t *state, | |||
| 3677 | { | 3684 | { |
| 3678 | bitset_copy (dests_ch[ndests], accepts); | 3685 | bitset_copy (dests_ch[ndests], accepts); |
| 3679 | err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]); | 3686 | err = re_node_set_init_1 (dests_node + ndests, cur_nodes->elems[i]); |
| 3680 | if (BE (err != REG_NOERROR, 0)) | 3687 | if (__glibc_unlikely (err != REG_NOERROR)) |
| 3681 | goto error_return; | 3688 | goto error_return; |
| 3682 | ++ndests; | 3689 | ++ndests; |
| 3683 | bitset_empty (accepts); | 3690 | bitset_empty (accepts); |
| @@ -3711,10 +3718,10 @@ check_node_accept_bytes (const re_dfa_t *dfa, Idx node_idx, | |||
| 3711 | int char_len, elem_len; | 3718 | int char_len, elem_len; |
| 3712 | Idx i; | 3719 | Idx i; |
| 3713 | 3720 | ||
| 3714 | if (BE (node->type == OP_UTF8_PERIOD, 0)) | 3721 | if (__glibc_unlikely (node->type == OP_UTF8_PERIOD)) |
| 3715 | { | 3722 | { |
| 3716 | unsigned char c = re_string_byte_at (input, str_idx), d; | 3723 | unsigned char c = re_string_byte_at (input, str_idx), d; |
| 3717 | if (BE (c < 0xc2, 1)) | 3724 | if (__glibc_likely (c < 0xc2)) |
| 3718 | return 0; | 3725 | return 0; |
| 3719 | 3726 | ||
| 3720 | if (str_idx + 2 > input->len) | 3727 | if (str_idx + 2 > input->len) |
| @@ -4049,15 +4056,15 @@ extend_buffers (re_match_context_t *mctx, int min_len) | |||
| 4049 | re_string_t *pstr = &mctx->input; | 4056 | re_string_t *pstr = &mctx->input; |
| 4050 | 4057 | ||
| 4051 | /* Avoid overflow. */ | 4058 | /* Avoid overflow. */ |
| 4052 | if (BE (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2 | 4059 | if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / sizeof (re_dfastate_t *)) / 2 |
| 4053 | <= pstr->bufs_len, 0)) | 4060 | <= pstr->bufs_len)) |
| 4054 | return REG_ESPACE; | 4061 | return REG_ESPACE; |
| 4055 | 4062 | ||
| 4056 | /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ | 4063 | /* Double the lengths of the buffers, but allocate at least MIN_LEN. */ |
| 4057 | ret = re_string_realloc_buffers (pstr, | 4064 | ret = re_string_realloc_buffers (pstr, |
| 4058 | MAX (min_len, | 4065 | MAX (min_len, |
| 4059 | MIN (pstr->len, pstr->bufs_len * 2))); | 4066 | MIN (pstr->len, pstr->bufs_len * 2))); |
| 4060 | if (BE (ret != REG_NOERROR, 0)) | 4067 | if (__glibc_unlikely (ret != REG_NOERROR)) |
| 4061 | return ret; | 4068 | return ret; |
| 4062 | 4069 | ||
| 4063 | if (mctx->state_log != NULL) | 4070 | if (mctx->state_log != NULL) |
| @@ -4068,7 +4075,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) | |||
| 4068 | does not have the right size. */ | 4075 | does not have the right size. */ |
| 4069 | re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, | 4076 | re_dfastate_t **new_array = re_realloc (mctx->state_log, re_dfastate_t *, |
| 4070 | pstr->bufs_len + 1); | 4077 | pstr->bufs_len + 1); |
| 4071 | if (BE (new_array == NULL, 0)) | 4078 | if (__glibc_unlikely (new_array == NULL)) |
| 4072 | return REG_ESPACE; | 4079 | return REG_ESPACE; |
| 4073 | mctx->state_log = new_array; | 4080 | mctx->state_log = new_array; |
| 4074 | } | 4081 | } |
| @@ -4080,7 +4087,7 @@ extend_buffers (re_match_context_t *mctx, int min_len) | |||
| 4080 | if (pstr->mb_cur_max > 1) | 4087 | if (pstr->mb_cur_max > 1) |
| 4081 | { | 4088 | { |
| 4082 | ret = build_wcs_upper_buffer (pstr); | 4089 | ret = build_wcs_upper_buffer (pstr); |
| 4083 | if (BE (ret != REG_NOERROR, 0)) | 4090 | if (__glibc_unlikely (ret != REG_NOERROR)) |
| 4084 | return ret; | 4091 | return ret; |
| 4085 | } | 4092 | } |
| 4086 | else | 4093 | else |
| @@ -4119,12 +4126,12 @@ match_ctx_init (re_match_context_t *mctx, int eflags, Idx n) | |||
| 4119 | size_t max_object_size = | 4126 | size_t max_object_size = |
| 4120 | MAX (sizeof (struct re_backref_cache_entry), | 4127 | MAX (sizeof (struct re_backref_cache_entry), |
| 4121 | sizeof (re_sub_match_top_t *)); | 4128 | sizeof (re_sub_match_top_t *)); |
| 4122 | if (BE (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n, 0)) | 4129 | if (__glibc_unlikely (MIN (IDX_MAX, SIZE_MAX / max_object_size) < n)) |
| 4123 | return REG_ESPACE; | 4130 | return REG_ESPACE; |
| 4124 | 4131 | ||
| 4125 | mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); | 4132 | mctx->bkref_ents = re_malloc (struct re_backref_cache_entry, n); |
| 4126 | mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); | 4133 | mctx->sub_tops = re_malloc (re_sub_match_top_t *, n); |
| 4127 | if (BE (mctx->bkref_ents == NULL || mctx->sub_tops == NULL, 0)) | 4134 | if (__glibc_unlikely (mctx->bkref_ents == NULL || mctx->sub_tops == NULL)) |
| 4128 | return REG_ESPACE; | 4135 | return REG_ESPACE; |
| 4129 | } | 4136 | } |
| 4130 | /* Already zero-ed by the caller. | 4137 | /* Already zero-ed by the caller. |
| @@ -4195,7 +4202,7 @@ match_ctx_add_entry (re_match_context_t *mctx, Idx node, Idx str_idx, Idx from, | |||
| 4195 | struct re_backref_cache_entry* new_entry; | 4202 | struct re_backref_cache_entry* new_entry; |
| 4196 | new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, | 4203 | new_entry = re_realloc (mctx->bkref_ents, struct re_backref_cache_entry, |
| 4197 | mctx->abkref_ents * 2); | 4204 | mctx->abkref_ents * 2); |
| 4198 | if (BE (new_entry == NULL, 0)) | 4205 | if (__glibc_unlikely (new_entry == NULL)) |
| 4199 | { | 4206 | { |
| 4200 | re_free (mctx->bkref_ents); | 4207 | re_free (mctx->bkref_ents); |
| 4201 | return REG_ESPACE; | 4208 | return REG_ESPACE; |
| @@ -4264,19 +4271,19 @@ match_ctx_add_subtop (re_match_context_t *mctx, Idx node, Idx str_idx) | |||
| 4264 | assert (mctx->sub_tops != NULL); | 4271 | assert (mctx->sub_tops != NULL); |
| 4265 | assert (mctx->asub_tops > 0); | 4272 | assert (mctx->asub_tops > 0); |
| 4266 | #endif | 4273 | #endif |
| 4267 | if (BE (mctx->nsub_tops == mctx->asub_tops, 0)) | 4274 | if (__glibc_unlikely (mctx->nsub_tops == mctx->asub_tops)) |
| 4268 | { | 4275 | { |
| 4269 | Idx new_asub_tops = mctx->asub_tops * 2; | 4276 | Idx new_asub_tops = mctx->asub_tops * 2; |
| 4270 | re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, | 4277 | re_sub_match_top_t **new_array = re_realloc (mctx->sub_tops, |
| 4271 | re_sub_match_top_t *, | 4278 | re_sub_match_top_t *, |
| 4272 | new_asub_tops); | 4279 | new_asub_tops); |
| 4273 | if (BE (new_array == NULL, 0)) | 4280 | if (__glibc_unlikely (new_array == NULL)) |
| 4274 | return REG_ESPACE; | 4281 | return REG_ESPACE; |
| 4275 | mctx->sub_tops = new_array; | 4282 | mctx->sub_tops = new_array; |
| 4276 | mctx->asub_tops = new_asub_tops; | 4283 | mctx->asub_tops = new_asub_tops; |
| 4277 | } | 4284 | } |
| 4278 | mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); | 4285 | mctx->sub_tops[mctx->nsub_tops] = calloc (1, sizeof (re_sub_match_top_t)); |
| 4279 | if (BE (mctx->sub_tops[mctx->nsub_tops] == NULL, 0)) | 4286 | if (__glibc_unlikely (mctx->sub_tops[mctx->nsub_tops] == NULL)) |
| 4280 | return REG_ESPACE; | 4287 | return REG_ESPACE; |
| 4281 | mctx->sub_tops[mctx->nsub_tops]->node = node; | 4288 | mctx->sub_tops[mctx->nsub_tops]->node = node; |
| 4282 | mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx; | 4289 | mctx->sub_tops[mctx->nsub_tops++]->str_idx = str_idx; |
| @@ -4290,19 +4297,19 @@ static re_sub_match_last_t * | |||
| 4290 | match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) | 4297 | match_ctx_add_sublast (re_sub_match_top_t *subtop, Idx node, Idx str_idx) |
| 4291 | { | 4298 | { |
| 4292 | re_sub_match_last_t *new_entry; | 4299 | re_sub_match_last_t *new_entry; |
| 4293 | if (BE (subtop->nlasts == subtop->alasts, 0)) | 4300 | if (__glibc_unlikely (subtop->nlasts == subtop->alasts)) |
| 4294 | { | 4301 | { |
| 4295 | Idx new_alasts = 2 * subtop->alasts + 1; | 4302 | Idx new_alasts = 2 * subtop->alasts + 1; |
| 4296 | re_sub_match_last_t **new_array = re_realloc (subtop->lasts, | 4303 | re_sub_match_last_t **new_array = re_realloc (subtop->lasts, |
| 4297 | re_sub_match_last_t *, | 4304 | re_sub_match_last_t *, |
| 4298 | new_alasts); | 4305 | new_alasts); |
| 4299 | if (BE (new_array == NULL, 0)) | 4306 | if (__glibc_unlikely (new_array == NULL)) |
| 4300 | return NULL; | 4307 | return NULL; |
| 4301 | subtop->lasts = new_array; | 4308 | subtop->lasts = new_array; |
| 4302 | subtop->alasts = new_alasts; | 4309 | subtop->alasts = new_alasts; |
| 4303 | } | 4310 | } |
| 4304 | new_entry = calloc (1, sizeof (re_sub_match_last_t)); | 4311 | new_entry = calloc (1, sizeof (re_sub_match_last_t)); |
| 4305 | if (BE (new_entry != NULL, 1)) | 4312 | if (__glibc_likely (new_entry != NULL)) |
| 4306 | { | 4313 | { |
| 4307 | subtop->lasts[subtop->nlasts] = new_entry; | 4314 | subtop->lasts[subtop->nlasts] = new_entry; |
| 4308 | new_entry->node = node; | 4315 | new_entry->node = node; |