| 937 | match_ctx_free (&mctx); |
| 938 | re_string_destruct (&mctx.input); |
| 939 | return err; |
| 940 | } |
| 941 | |
| 942 | static reg_errcode_t |
| 943 | prune_impossible_nodes (re_match_context_t *mctx) |
| 944 | { |
| 945 | const re_dfa_t *const dfa = mctx->dfa; |
| 946 | int halt_node, match_last; |
| 947 | reg_errcode_t ret; |
| 948 | re_dfastate_t **sifted_states; |
| 949 | re_dfastate_t **lim_states = NULL; |
| 950 | re_sift_context_t sctx; |
| 951 | #ifdef DEBUG |
| 952 | assert (mctx->state_log != NULL); |
| 953 | #endif |
| 954 | match_last = mctx->match_last; |
| 955 | halt_node = mctx->last_node; |
| 956 | |
| 957 | /* Avoid overflow. */ |
| 958 | if (BE (SIZE_MAX / sizeof (re_dfastate_t *) <= match_last, 0)) |
| 959 | return REG_ESPACE; |
| 960 | |
| 961 | sifted_states = re_malloc (re_dfastate_t *, match_last + 1); |
| 962 | if (BE (sifted_states == NULL, 0)) |
| 963 | { |
| 964 | ret = REG_ESPACE; |
| 965 | goto free_return; |
| 966 | } |
| 967 | if (dfa->nbackref) |
| 968 | { |
| 969 | lim_states = re_malloc (re_dfastate_t *, match_last + 1); |
| 970 | if (BE (lim_states == NULL, 0)) |
| 971 | { |
| 972 | ret = REG_ESPACE; |
| 973 | goto free_return; |
| 974 | } |
| 975 | while (1) |
| 976 | { |
| 977 | memset (lim_states, '\0', |
| 978 | sizeof (re_dfastate_t *) * (match_last + 1)); |
| 979 | sift_ctx_init (&sctx, sifted_states, lim_states, halt_node, |
| 980 | match_last); |
| 981 | ret = sift_states_backward (mctx, &sctx); |
| 982 | re_node_set_free (&sctx.limits); |
| 983 | if (BE (ret != REG_NOERROR, 0)) |
| 984 | goto free_return; |
| 985 | if (sifted_states[0] != NULL || lim_states[0] != NULL) |
| 986 | break; |
| 987 | do |
| 988 | { |
| 989 | --match_last; |
| 990 | if (match_last < 0) |
| 991 | { |
| 992 | ret = REG_NOMATCH; |
| 993 | goto free_return; |
| 994 | } |
| 995 | } while (mctx->state_log[match_last] == NULL |
| 996 | || !mctx->state_log[match_last]->halt); |
no test coverage detected