diff --git a/regcomp.c b/regcomp.c index de44cfe037..69a63011d1 100644 --- a/regcomp.c +++ b/regcomp.c @@ -3950,17 +3950,22 @@ optimize_node_left(Node* node, NodeOptInfo* opt, OptEnv* env) } } - if (! ONIGENC_IS_SINGLEBYTE(env->enc)) { - if (! IS_NULL(cc->mbuf) || - (cc->not != 0 && found != 0)) { - for (i = 0; i < SINGLE_BYTE_SIZE; i++) { - z = ONIGENC_IS_MBC_HEAD(env->enc, i); - if (z) { - mb_found = 1; - add_char_opt_map_info(&opt->map, i); - } - } - } + if (IS_NULL(cc->mbuf)) { + if (cc->not) { + for (i = 0; i < SINGLE_BYTE_SIZE; i++) { + add_char_opt_map_info(&opt->map, i); + } + mb_found = 1; + } + } + else { + for (i = 0; i < SINGLE_BYTE_SIZE; i++) { + z = ONIGENC_IS_MBC_HEAD(env->enc, i); + if (z) { + mb_found = 1; + add_char_opt_map_info(&opt->map, i); + } + } } if (mb_found) { diff --git a/regexec.c b/regexec.c index 1bae0d9516..581fe64b69 100644 --- a/regexec.c +++ b/regexec.c @@ -362,26 +362,11 @@ typedef struct { };\ } while(0) -static unsigned int MatchStackLimitSize = DEFAULT_MATCH_STACK_LIMIT_SIZE; - -extern unsigned int -onig_get_match_stack_limit_size(void) -{ - return MatchStackLimitSize; -} - -extern int -onig_set_match_stack_limit_size(unsigned int size) -{ - MatchStackLimitSize = size; - return 0; -} - static int stack_double(StackType** arg_stk_base, StackType** arg_stk_end, StackType** arg_stk, StackType* stk_alloc, MatchArg* msa) { - unsigned int n; + int n; StackType *x, *stk_base, *stk_end, *stk; stk_base = *arg_stk_base; @@ -400,12 +385,7 @@ stack_double(StackType** arg_stk_base, StackType** arg_stk_end, } else { n *= 2; - if (MatchStackLimitSize != 0 && n > MatchStackLimitSize) { - if ((unsigned int )(stk_end - stk_base) == MatchStackLimitSize) - return ONIGERR_MATCH_STACK_LIMIT_OVER; - else - n = MatchStackLimitSize; - } + if (n > MATCH_STACK_LIMIT_SIZE) return ONIGERR_MATCH_STACK_LIMIT_OVER; x = (StackType* )xrealloc(stk_base, sizeof(StackType) * n); if (IS_NULL(x)) { STACK_SAVE; @@ -2593,13 +2573,11 @@ bm_search_notrev(regex_t* reg, UChar* target, UChar* target_end, if (t < target) return p + 1; skip = reg->map[*s]; - p = s + 1; - if (p >= text_end) return (UChar* )NULL; + p++; t = p; - do { + while ((p - t) < skip) { p += enc_len(reg->enc, *p); - } while ((p - t) < skip && p < text_end); - + } s += (p - t); } } @@ -2613,13 +2591,11 @@ bm_search_notrev(regex_t* reg, UChar* target, UChar* target_end, if (t < target) return p + 1; skip = reg->int_map[*s]; - p = s + 1; - if (p >= text_end) return (UChar* )NULL; + p++; t = p; - do { + while ((p - t) < skip) { p += enc_len(reg->enc, *p); - } while ((p - t) < skip && p < text_end); - + } s += (p - t); } } diff --git a/regint.h b/regint.h index bcc5fa5fc4..ba201f1a28 100644 --- a/regint.h +++ b/regint.h @@ -46,7 +46,7 @@ #define USE_QUALIFIER_PEEK_NEXT #define INIT_MATCH_STACK_SIZE 160 -#define DEFAULT_MATCH_STACK_LIMIT_SIZE 0 /* unlimited */ +#define MATCH_STACK_LIMIT_SIZE 500000 /* interface to external system */ #ifdef NOT_RUBY /* gived from Makefile */