From fed678b1bdf279f30fe3f8175210280ce0fc1cad Mon Sep 17 00:00:00 2001 From: "K.Kosako" Date: Tue, 25 Sep 2018 10:34:35 +0900 Subject: [PATCH] use enc_min_len for Sunday quick search --- src/regcomp.c | 15 ++++++++------- src/regexec.c | 14 +++++++++----- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/regcomp.c b/src/regcomp.c index 00f7a17..fc4b3d5 100644 --- a/src/regcomp.c +++ b/src/regcomp.c @@ -4553,21 +4553,22 @@ setup_tree(Node* node, regex_t* reg, int state, ScanEnv* env) } #ifdef USE_SUNDAY_QUICK_SEARCH_ALGORITHM -/* set skip map for Sunday quick search */ static int -set_sunday_quick_search_skip_table(UChar* s, UChar* end, - OnigEncoding enc ARG_UNUSED, UChar skip[]) +set_sunday_quick_search_skip_table(UChar* s, UChar* end, OnigEncoding enc, + UChar skip[]) { - int i, len; + int i, len, emin; + + emin = ONIGENC_MBC_MINLEN(enc); len = (int )(end - s); - if (len + 1 >= ONIG_CHAR_TABLE_SIZE) + if (len + emin >= ONIG_CHAR_TABLE_SIZE) return ONIGERR_PARSER_BUG; - for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = (UChar )(len + 1); + for (i = 0; i < ONIG_CHAR_TABLE_SIZE; i++) skip[i] = (UChar )(len + emin); for (i = 0; i < len; i++) - skip[s[i]] = len - i; + skip[s[i]] = len - i + (emin - 1); return 0; } diff --git a/src/regexec.c b/src/regexec.c index 6120af0..2ab410e 100644 --- a/src/regexec.c +++ b/src/regexec.c @@ -4118,11 +4118,12 @@ static UChar* sunday_quick_search_step_forward(regex_t* reg, const UChar* target, const UChar* target_end, const UChar* text, const UChar* text_end, - const UChar* text_range) + const UChar* text_range) { const UChar *s, *se, *t, *p, *end; const UChar *tail; int skip, tlen1; + int enc_minlen; #ifdef ONIG_DEBUG_SEARCH fprintf(stderr, @@ -4135,6 +4136,7 @@ sunday_quick_search_step_forward(regex_t* reg, if (end + tlen1 > text_end) end = text_end - tlen1; + enc_minlen = ONIGENC_MBC_MINLEN(reg->enc); s = text; while (s < end) { @@ -4144,8 +4146,8 @@ sunday_quick_search_step_forward(regex_t* reg, if (t == target) return (UChar* )s; p--; t--; } - if (se + 1 >= text_end) break; - skip = reg->map[*(se + 1)]; + if (se + enc_minlen >= text_end) break; + skip = reg->map[*(se + enc_minlen)]; t = s; do { s += enclen(reg->enc, s); @@ -4162,11 +4164,13 @@ sunday_quick_search(regex_t* reg, const UChar* target, const UChar* target_end, { const UChar *s, *t, *p, *end; const UChar *tail; + int enc_minlen; end = text_range + (target_end - target); if (end > text_end) end = text_end; + enc_minlen = ONIGENC_MBC_MINLEN(reg->enc); tail = target_end - 1; s = text + (tail - target); @@ -4177,8 +4181,8 @@ sunday_quick_search(regex_t* reg, const UChar* target, const UChar* target_end, if (t == target) return (UChar* )p; p--; t--; } - if (s + 1 >= text_end) break; - s += reg->map[*(s + 1)]; + if (s + enc_minlen >= text_end) break; + s += reg->map[*(s + enc_minlen)]; } return (UChar* )NULL; -- 2.40.0