/[pcre]/code/tags/pcre-8.33/pcre_compile.c
ViewVC logotype

Diff of /code/tags/pcre-8.33/pcre_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1120 by chpe, Tue Oct 16 15:57:38 2012 UTC revision 1152 by chpe, Sun Oct 21 16:53:51 2012 UTC
# Line 1203  escape sequence. Line 1203  escape sequence.
1203  Argument:  Argument:
1204    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
1205    negptr         points to a boolean that is set TRUE for negation else FALSE    negptr         points to a boolean that is set TRUE for negation else FALSE
1206    dptr           points to an int that is set to the detailed property value    ptypeptr       points to an unsigned int that is set to the type value
1207      pdataptr       points to an unsigned int that is set to the detailed property value
1208    errorcodeptr   points to the error code variable    errorcodeptr   points to the error code variable
1209    
1210  Returns:         type value from ucp_type_table, or -1 for an invalid type  Returns:         TRUE if the type value was found, or FALSE for an invalid type
1211  */  */
1212    
1213  static int  static BOOL
1214  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1215      unsigned int *pdataptr, int *errorcodeptr)
1216  {  {
1217  pcre_uchar c;  pcre_uchar c;
1218  int i, bot, top;  int i, bot, top;
# Line 1265  while (bot < top) Line 1267  while (bot < top)
1267    r = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);    r = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);
1268    if (r == 0)    if (r == 0)
1269      {      {
1270      *dptr = PRIV(utt)[i].value;      *ptypeptr = PRIV(utt)[i].type;
1271      return PRIV(utt)[i].type;      *pdataptr = PRIV(utt)[i].value;
1272        return TRUE;
1273      }      }
1274    if (r > 0) bot = i + 1; else top = i;    if (r > 0) bot = i + 1; else top = i;
1275    }    }
1276    
1277  *errorcodeptr = ERR47;  *errorcodeptr = ERR47;
1278  *ptrptr = ptr;  *ptrptr = ptr;
1279  return -1;  return FALSE;
1280    
1281  ERROR_RETURN:  ERROR_RETURN:
1282  *errorcodeptr = ERR46;  *errorcodeptr = ERR46;
1283  *ptrptr = ptr;  *ptrptr = ptr;
1284  return -1;  return FALSE;
1285  }  }
1286  #endif  #endif
1287    
# Line 1911  for (;;) Line 1914  for (;;)
1914    
1915      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1916    
 #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32  
     case OP_XCLASS:  
     cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];  
     /* Fall through */  
 #endif  
   
1917      case OP_CLASS:      case OP_CLASS:
1918      case OP_NCLASS:      case OP_NCLASS:
1919    #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1920        case OP_XCLASS:
1921        /* The original code caused an unsigned overflow in 64 bit systems,
1922        so now we use a conditional statement. */
1923        if (op == OP_XCLASS)
1924          cc += GET(cc, 1);
1925        else
1926          cc += PRIV(OP_lengths)[OP_CLASS];
1927    #else
1928      cc += PRIV(OP_lengths)[OP_CLASS];      cc += PRIV(OP_lengths)[OP_CLASS];
1929    #endif
1930    
1931      switch (*cc)      switch (*cc)
1932        {        {
# Line 2915  get_othercase_range(pcre_uint32 *cptr, p Line 2922  get_othercase_range(pcre_uint32 *cptr, p
2922    pcre_uint32 *odptr)    pcre_uint32 *odptr)
2923  {  {
2924  pcre_uint32 c, othercase, next;  pcre_uint32 c, othercase, next;
2925  int co;  unsigned int co;
2926    
2927  /* Find the first character that has an other case. If it has multiple other  /* Find the first character that has an other case. If it has multiple other
2928  cases, return its case offset value. */  cases, return its case offset value. */
# Line 2926  for (c = *cptr; c <= d; c++) Line 2933  for (c = *cptr; c <= d; c++)
2933      {      {
2934      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2935      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2936      return co;      return (int)co;
2937      }      }
2938    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2939    }    }
# Line 2966  Returns:       TRUE if auto-possessifyin Line 2973  Returns:       TRUE if auto-possessifyin
2973  */  */
2974    
2975  static BOOL  static BOOL
2976  check_char_prop(pcre_uint32 c, int ptype, int pdata, BOOL negated)  check_char_prop(pcre_uint32 c, unsigned int ptype, unsigned int pdata, BOOL negated)
2977  {  {
2978  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2979  const pcre_uint32 *p;  const pcre_uint32 *p;
# Line 3133  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3140  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3140    
3141  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3142      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
   //if (escape == 0) switch(op_code)  
3143    {    {
3144  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3145    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
# Line 3153  if (escape == 0) Line 3159  if (escape == 0)
3159  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3160    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3161      {      {
3162      int ocs = UCD_CASESET(next);      unsigned int ocs = UCD_CASESET(next);
3163      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);      if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);
3164      }      }
3165  #endif  #endif
# Line 3253  if (escape == 0) Line 3259  if (escape == 0)
3259    
3260  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3261      case OP_PROP:      case OP_PROP:
3262      return check_char_prop(next, (int)previous[0], (int)previous[1], FALSE);      return check_char_prop(next, previous[0], previous[1], FALSE);
3263    
3264      case OP_NOTPROP:      case OP_NOTPROP:
3265      return check_char_prop(next, (int)previous[0], (int)previous[1], TRUE);      return check_char_prop(next, previous[0], previous[1], TRUE);
3266  #endif  #endif
3267    
3268      default:      default:
# Line 3339  switch(op_code) Line 3345  switch(op_code)
3345      case ESC_p:      case ESC_p:
3346      case ESC_P:      case ESC_P:
3347        {        {
3348        int ptype, pdata, errorcodeptr;        unsigned int ptype = 0, pdata = 0;
3349          int errorcodeptr;
3350        BOOL negated;        BOOL negated;
3351    
3352        ptr--;      /* Make ptr point at the p or P */        ptr--;      /* Make ptr point at the p or P */
3353        ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr);        if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcodeptr))
3354        if (ptype < 0) return FALSE;          return FALSE;
3355        ptr++;      /* Point past the final curly ket */        ptr++;      /* Point past the final curly ket */
3356    
3357        /* If the property item is optional, we have to give up. (When generated        /* If the property item is optional, we have to give up. (When generated
# Line 3792  for (;; ptr++) Line 3799  for (;; ptr++)
3799    pcre_uint32 subreqchar, subfirstchar;    pcre_uint32 subreqchar, subfirstchar;
3800    pcre_int32 subreqcharflags, subfirstcharflags;    pcre_int32 subreqcharflags, subfirstcharflags;
3801    int terminator;    int terminator;
3802    int mclength;    unsigned int mclength;
3803    int tempbracount;    unsigned int tempbracount;
3804    pcre_uint32 ec;    pcre_uint32 ec;
3805    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3806    
# Line 4376  for (;; ptr++) Line 4383  for (;; ptr++)
4383              case ESC_P:              case ESC_P:
4384                {                {
4385                BOOL negated;                BOOL negated;
4386                int pdata;                unsigned int ptype = 0, pdata = 0;
4387                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
4388                if (ptype < 0) goto FAILED;                  goto FAILED;
4389                *class_uchardata++ = ((escape == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4390                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4391                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
# Line 5819  for (;; ptr++) Line 5826  for (;; ptr++)
5826            }            }
5827          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
5828    
5829          if ((terminator > 0 && *ptr++ != terminator) ||          if ((terminator > 0 && *ptr++ != (pcre_uchar)terminator) ||
5830              *ptr++ != CHAR_RIGHT_PARENTHESIS)              *ptr++ != CHAR_RIGHT_PARENTHESIS)
5831            {            {
5832            ptr--;      /* Error offset */            ptr--;      /* Error offset */
# Line 6059  for (;; ptr++) Line 6066  for (;; ptr++)
6066    
6067            if (lengthptr != NULL)            if (lengthptr != NULL)
6068              {              {
6069              if (*ptr != terminator)              if (*ptr != (pcre_uchar)terminator)
6070                {                {
6071                *errorcodeptr = ERR42;                *errorcodeptr = ERR42;
6072                goto FAILED;                goto FAILED;
# Line 6201  for (;; ptr++) Line 6208  for (;; ptr++)
6208              *errorcodeptr = ERR62;              *errorcodeptr = ERR62;
6209              goto FAILED;              goto FAILED;
6210              }              }
6211            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6212              {              {
6213              *errorcodeptr = ERR42;              *errorcodeptr = ERR42;
6214              goto FAILED;              goto FAILED;
# Line 6307  for (;; ptr++) Line 6314  for (;; ptr++)
6314            while(IS_DIGIT(*ptr))            while(IS_DIGIT(*ptr))
6315              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6316    
6317            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6318              {              {
6319              *errorcodeptr = ERR29;              *errorcodeptr = ERR29;
6320              goto FAILED;              goto FAILED;
# Line 6787  for (;; ptr++) Line 6794  for (;; ptr++)
6794          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)
6795            {            {
6796            BOOL is_a_number = TRUE;            BOOL is_a_number = TRUE;
6797            for (p = ptr + 1; *p != 0 && *p != terminator; p++)            for (p = ptr + 1; *p != 0 && *p != (pcre_uchar)terminator; p++)
6798              {              {
6799              if (!MAX_255(*p)) { is_a_number = FALSE; break; }              if (!MAX_255(*p)) { is_a_number = FALSE; break; }
6800              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;
6801              if ((cd->ctypes[*p] & ctype_word) == 0) break;              if ((cd->ctypes[*p] & ctype_word) == 0) break;
6802              }              }
6803            if (*p != terminator)            if (*p != (pcre_uchar)terminator)
6804              {              {
6805              *errorcodeptr = ERR57;              *errorcodeptr = ERR57;
6806              break;              break;
# Line 6811  for (;; ptr++) Line 6818  for (;; ptr++)
6818    
6819          p = ptr + 2;          p = ptr + 2;
6820          while (IS_DIGIT(*p)) p++;          while (IS_DIGIT(*p)) p++;
6821          if (*p != terminator)          if (*p != (pcre_uchar)terminator)
6822            {            {
6823            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
6824            break;            break;
# Line 6875  for (;; ptr++) Line 6882  for (;; ptr++)
6882        else if (escape == ESC_P || escape == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6883          {          {
6884          BOOL negated;          BOOL negated;
6885          int pdata;          unsigned int ptype = 0, pdata = 0;
6886          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
6887          if (ptype < 0) goto FAILED;            goto FAILED;
6888          previous = code;          previous = code;
6889          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6890          *code++ = ptype;          *code++ = ptype;
# Line 7104  pcre_int32 firstcharflags, reqcharflags; Line 7111  pcre_int32 firstcharflags, reqcharflags;
7111  pcre_uint32 branchfirstchar, branchreqchar;  pcre_uint32 branchfirstchar, branchreqchar;
7112  pcre_int32 branchfirstcharflags, branchreqcharflags;  pcre_int32 branchfirstcharflags, branchreqcharflags;
7113  int length;  int length;
7114  int orig_bracount;  unsigned int orig_bracount;
7115  int max_bracount;  unsigned int max_bracount;
7116  branch_chain bc;  branch_chain bc;
7117    
7118  bc.outer = bcptr;  bc.outer = bcptr;
# Line 8122  if debugging, leave the test till after Line 8129  if debugging, leave the test till after
8129  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
8130  #endif  #endif
8131    
8132    #ifdef SUPPORT_VALGRIND
8133    /* If the estimated length exceeds the really used length, mark the extra
8134    allocated memory as unadressable, so that any out-of-bound reads can be
8135    detected. */
8136    VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
8137    #endif
8138    
8139  /* Fill in any forward references that are required. There may be repeated  /* Fill in any forward references that are required. There may be repeated
8140  references; optimize for them, as searching a large regex takes time. */  references; optimize for them, as searching a large regex takes time. */
8141    

Legend:
Removed from v.1120  
changed lines
  Added in v.1152

  ViewVC Help
Powered by ViewVC 1.1.5