]> granicus.if.org Git - onig/commitdiff
use enc_min_len for Sunday quick search
authorK.Kosako <kosako@sofnec.co.jp>
Tue, 25 Sep 2018 01:34:35 +0000 (10:34 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Tue, 25 Sep 2018 01:34:35 +0000 (10:34 +0900)
src/regcomp.c
src/regexec.c

index 00f7a173843dd79b99b92d7de6401c6dbe8b5a6d..fc4b3d50ffab61e321993423ad4f5e3124fa39b9 100644 (file)
@@ -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;
 }
index 6120af09ab0ac8f6666f254825911e6136795d94..2ab410efea5064e9c79b105ea47c250b0533239c 100644 (file)
@@ -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;