]> granicus.if.org Git - onig/commitdiff
allow ONIG_TYPE_LONG and other types combination in onig_set_callout_of_name()
authorK.Kosako <kosako@sofnec.co.jp>
Tue, 6 Mar 2018 08:40:23 +0000 (17:40 +0900)
committerK.Kosako <kosako@sofnec.co.jp>
Tue, 6 Mar 2018 08:40:23 +0000 (17:40 +0900)
src/ascii.c
src/oniguruma.h
src/regparse.c
src/utf16_be.c
src/utf16_le.c

index 9c33d0b2764de9c6df068043875c4b19a08db098..aad2157eb018b2b0301304e2ea4792846e2df856 100644 (file)
@@ -38,8 +38,8 @@ init(void)
     OnigEncoding enc;
     char* name;
     OnigType t_long;
-    OnigType  args[4];
-    OnigValue opts[4];
+    unsigned int args[4];
+    OnigValue    opts[4];
 
     enc = ONIG_ENCODING_ASCII;
     t_long = ONIG_TYPE_LONG;
@@ -59,9 +59,9 @@ init(void)
     BC_B_O(name, total_count, 1, args, 1, opts);
 
     name = "CMP";
-    args[0] = ONIG_TYPE_TAG;
+    args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG;
     args[1] = ONIG_TYPE_STRING;
-    args[2] = ONIG_TYPE_TAG;
+    args[2] = ONIG_TYPE_TAG | ONIG_TYPE_LONG;
     BC_P(name, cmp, 3, args);
 
 #endif /* USE_CALLOUT */
index df4535af9027d402cba6905d0cee84027b1aae78..4120686c8e03ac7678a54ff0b1621ec81c7b06f7 100644 (file)
@@ -941,7 +941,7 @@ OnigCalloutFunc onig_get_retraction_callout_of_contents P_((void));
 ONIG_EXTERN
 int onig_set_retraction_callout_of_contents P_((OnigCalloutFunc f));
 ONIG_EXTERN
-int onig_set_callout_of_name P_((OnigEncoding enc, OnigCalloutType type, OnigUChar* name, OnigUChar* name_end, int callout_in, OnigCalloutFunc callout, OnigCalloutFunc end_callout, int arg_num, OnigType arg_types[], int optional_arg_num, OnigValue opt_defaults[])); /* name: single-byte string */
+int onig_set_callout_of_name P_((OnigEncoding enc, OnigCalloutType type, OnigUChar* name, OnigUChar* name_end, int callout_in, OnigCalloutFunc callout, OnigCalloutFunc end_callout, int arg_num, unsigned int arg_types[], int optional_arg_num, OnigValue opt_defaults[])); /* name: single-byte string */
 ONIG_EXTERN
 OnigUChar* onig_get_callout_name_by_name_id P_((int id));
 ONIG_EXTERN
index 346ad1940eea2d0d0d6cad011c5773ff35cb9713..39316ba321db6810bbbc95a98df40d6080601485 100644 (file)
@@ -1131,7 +1131,7 @@ typedef struct {
   OnigCalloutFunc end_func;
   int             arg_num;
   int             opt_arg_num;
-  OnigType        arg_types[ONIG_CALLOUT_MAX_ARGS_NUM];
+  unsigned int    arg_types[ONIG_CALLOUT_MAX_ARGS_NUM];
   OnigValue       opt_defaults[ONIG_CALLOUT_MAX_ARGS_NUM];
   UChar*          name; /* reference to GlobalCalloutNameTable entry: e->name */
 } CalloutNameListEntry;
@@ -1491,7 +1491,7 @@ onig_set_callout_of_name(OnigEncoding enc, OnigCalloutType callout_type,
                          UChar* name, UChar* name_end, int in,
                          OnigCalloutFunc start_func,
                          OnigCalloutFunc end_func,
-                         int arg_num, OnigType arg_types[],
+                         int arg_num, unsigned int arg_types[],
                          int opt_arg_num, OnigValue opt_defaults[])
 {
   int r;
@@ -1515,8 +1515,23 @@ onig_set_callout_of_name(OnigEncoding enc, OnigCalloutType callout_type,
     return ONIGERR_INVALID_CALLOUT_ARG;
 
   for (i = 0; i < arg_num; i++) {
-    if (arg_types[i] == ONIG_TYPE_VOID || arg_types[i] == ONIG_TYPE_POINTER)
+    unsigned int t = arg_types[i];
+    if (t == ONIG_TYPE_VOID)
       return ONIGERR_INVALID_CALLOUT_ARG;
+    else {
+      if (i >= arg_num - opt_arg_num) {
+        if (t != ONIG_TYPE_LONG && t != ONIG_TYPE_CHAR && t != ONIG_TYPE_STRING &&
+            t != ONIG_TYPE_TAG)
+          return ONIGERR_INVALID_CALLOUT_ARG;
+      }
+      else {
+        if (t != ONIG_TYPE_LONG) {
+          t = t & ~ONIG_TYPE_LONG;
+          if (t != ONIG_TYPE_CHAR && t != ONIG_TYPE_STRING && t != ONIG_TYPE_TAG)
+            return ONIGERR_INVALID_CALLOUT_ARG;
+        }
+      }
+    }
   }
 
   if (! is_allowed_callout_name(enc, name, name_end)) {
@@ -1652,7 +1667,7 @@ get_callout_opt_arg_num_by_name_id(int name_id)
   return GlobalCalloutNameList->v[name_id].opt_arg_num;
 }
 
-static OnigType
+static unsigned int
 get_callout_arg_type_by_name_id(int name_id, int index)
 {
   return GlobalCalloutNameList->v[name_id].arg_types[index];
@@ -6695,14 +6710,27 @@ parse_callout_args(int skip_mode, int cterm, UChar** src, UChar* end,
 
     if (cn != 0) {
       if (skip_mode == 0) {
-        long rl;
+        if ((types[n] & ONIG_TYPE_LONG) != 0) {
+          int fixed = 0;
+          if (cn > 0) {
+            long rl;
+            r = parse_long(enc, buf, bufend, 1, LONG_MAX, &rl);
+            if (r == ONIG_NORMAL) {
+              vals[n].l = rl;
+              fixed = 1;
+              types[n] = ONIG_TYPE_LONG;
+            }
+          }
+
+          if (fixed == 0) {
+            types[n] = (types[n] & ~ONIG_TYPE_LONG);
+            if (types[n] == ONIG_TYPE_VOID)
+              return ONIGERR_INVALID_CALLOUT_ARG;
+          }
+        }
 
         switch (types[n]) {
         case ONIG_TYPE_LONG:
-          if (cn == 0) return ONIGERR_INVALID_CALLOUT_ARG;
-          r = parse_long(enc, buf, bufend, 1, LONG_MAX, &rl);
-          if (r != ONIG_NORMAL) return r;
-          vals[n].l = rl;
           break;
 
         case ONIG_TYPE_CHAR:
@@ -6767,8 +6795,8 @@ parse_callout_of_name(Node** np, int cterm, UChar** src, UChar* end, ScanEnv* en
   Node*  node;
   CalloutListEntry* e;
   RegexExt* ext;
-  OnigType  types[ONIG_CALLOUT_MAX_ARGS_NUM];
-  OnigValue vals[ONIG_CALLOUT_MAX_ARGS_NUM];
+  unsigned int types[ONIG_CALLOUT_MAX_ARGS_NUM];
+  OnigValue    vals[ONIG_CALLOUT_MAX_ARGS_NUM];
   OnigEncoding enc = env->enc;
   UChar* p = *src;
 
index af5bb0d97b0f58775eb8d3a2b6237020d5124f30..3f0df0676fdd5fece52c10705b4ec1e76c0a7f6c 100644 (file)
@@ -39,7 +39,7 @@ init(void)
     OnigEncoding enc;
     char* name;
     OnigType t_long;
-    OnigType args[4];
+    unsigned int args[4];
     OnigValue opts[4];
 
     enc = ONIG_ENCODING_UTF16_BE;
@@ -60,9 +60,9 @@ init(void)
     BC_B_O(name, total_count, 1, args, 1, opts);
 
     name = "\000C\000M\000P\000\000";
-    args[0] = ONIG_TYPE_TAG;
+    args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG;
     args[1] = ONIG_TYPE_STRING;
-    args[2] = ONIG_TYPE_TAG;
+    args[2] = ONIG_TYPE_TAG | ONIG_TYPE_LONG;
     BC_P(name, cmp, 3, args);
 
 #endif /* USE_CALLOUT */
index 725b835bf739e061f659ed6fa8174721495b3818..3ed968f8fcaeecbdbe6576f9b13ab32c9ecc7129 100644 (file)
@@ -37,8 +37,8 @@ init(void)
     OnigEncoding enc;
     char* name;
     OnigType t_long;
-    OnigType  args[4];
-    OnigValue opts[4];
+    unsigned int args[4];
+    OnigValue    opts[4];
 
     enc = ONIG_ENCODING_UTF16_LE;
     t_long = ONIG_TYPE_LONG;
@@ -58,9 +58,9 @@ init(void)
     BC_B_O(name, total_count, 1, args, 1, opts);
 
     name = "C\000M\000P\000\000\000";
-    args[0] = ONIG_TYPE_TAG;
+    args[0] = ONIG_TYPE_TAG | ONIG_TYPE_LONG;
     args[1] = ONIG_TYPE_STRING;
-    args[2] = ONIG_TYPE_TAG;
+    args[2] = ONIG_TYPE_TAG | ONIG_TYPE_LONG;
     BC_P(name, cmp, 3, args);
 
 #endif /* USE_CALLOUT */