/[pcre]/code/trunk/pcre_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_compile.c

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

revision 1219 by ph10, Sun Nov 11 18:04:37 2012 UTC revision 1313 by ph10, Wed Apr 24 12:07:09 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 80  to check them every time. */ Line 80  to check them every time. */
80  /* Definitions to allow mutual recursion */  /* Definitions to allow mutual recursion */
81    
82  static int  static int
83    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84      const pcre_uint32 *, unsigned int);      const pcre_uint32 *, unsigned int);
85    
86  static BOOL  static BOOL
87    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
88      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,
89      compile_data *, int *);      compile_data *, int *);
90    
91    
# Line 487  static const char error_texts[] = Line 487  static const char error_texts[] =
487    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
488    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
489    /* 60 */    /* 60 */
490    "(*VERB) not recognized\0"    "(*VERB) not recognized or malformed\0"
491    "number is too big\0"    "number is too big\0"
492    "subpattern name expected\0"    "subpattern name expected\0"
493    "digit expected after (?+\0"    "digit expected after (?+\0"
# Line 508  static const char error_texts[] = Line 508  static const char error_texts[] =
508    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
509    "character value in \\u.... sequence is too large\0"    "character value in \\u.... sequence is too large\0"
510    "invalid UTF-32 string\0"    "invalid UTF-32 string\0"
511      "setting UTF is disabled by the application\0"
512    ;    ;
513    
514  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 773  Returns:         zero => a data characte Line 774  Returns:         zero => a data characte
774  */  */
775    
776  static int  static int
777  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
778    int bracount, int options, BOOL isclass)    int bracount, int options, BOOL isclass)
779  {  {
780  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
# Line 797  Otherwise further processing may be requ Line 798  Otherwise further processing may be requ
798  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
799  /* Not alphanumeric */  /* Not alphanumeric */
800  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
801  else if ((i = escapes[c - CHAR_0]) != 0) { if (i > 0) c = (pcre_uint32)i; else escape = -i; }  else if ((i = escapes[c - CHAR_0]) != 0)
802      { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
803    
804  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
805  /* Not alphanumeric */  /* Not alphanumeric */
# Line 847  else Line 849  else
849            }            }
850    
851  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
852          if (c > (utf ? 0x10ffff : 0xff))          if (c > (utf ? 0x10ffffU : 0xffU))
853  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
854          if (c > (utf ? 0x10ffff : 0xffff))          if (c > (utf ? 0x10ffffU : 0xffffU))
855  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
856          if (utf && c > 0x10ffff)          if (utf && c > 0x10ffffU)
857  #endif  #endif
858            {            {
859            *errorcodeptr = ERR76;            *errorcodeptr = ERR76;
# Line 1085  else Line 1087  else
1087  #endif  #endif
1088    
1089  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
1090          if (c > (utf ? 0x10ffff : 0xff)) { overflow = TRUE; break; }          if (c > (utf ? 0x10ffffU : 0xffU)) { overflow = TRUE; break; }
1091  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
1092          if (c > (utf ? 0x10ffff : 0xffff)) { overflow = TRUE; break; }          if (c > (utf ? 0x10ffffU : 0xffffU)) { overflow = TRUE; break; }
1093  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
1094          if (utf && c > 0x10ffff) { overflow = TRUE; break; }          if (utf && c > 0x10ffffU) { overflow = TRUE; break; }
1095  #endif  #endif
1096          }          }
1097    
# Line 1211  Returns:         TRUE if the type value Line 1213  Returns:         TRUE if the type value
1213  */  */
1214    
1215  static BOOL  static BOOL
1216  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1217    unsigned int *pdataptr, int *errorcodeptr)    unsigned int *pdataptr, int *errorcodeptr)
1218  {  {
1219  pcre_uchar c;  pcre_uchar c;
# Line 1408  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1410  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1410    {    {
1411    /* Handle specials such as (*SKIP) or (*UTF8) etc. */    /* Handle specials such as (*SKIP) or (*UTF8) etc. */
1412    
1413    if (ptr[1] == CHAR_ASTERISK) ptr += 2;    if (ptr[1] == CHAR_ASTERISK)
1414        {
1415        ptr += 2;
1416        while (ptr < cd->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1417        }
1418    
1419    /* Handle a normal, unnamed capturing parenthesis. */    /* Handle a normal, unnamed capturing parenthesis. */
1420    
# Line 1432  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1438  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1438    
1439    else if (ptr[2] == CHAR_NUMBER_SIGN)    else if (ptr[2] == CHAR_NUMBER_SIGN)
1440      {      {
1441      for (ptr += 3; *ptr != CHAR_NULL; ptr++)      for (ptr += 3; *ptr != CHAR_NULL; ptr++)
1442        if (*ptr == CHAR_RIGHT_PARENTHESIS) break;        if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
1443      goto FAIL_EXIT;      goto FAIL_EXIT;
1444      }      }
# Line 1879  for (;;) Line 1885  for (;;)
1885    
1886      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1887      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1888      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)
1889        cc += 2;        cc += 2;
1890      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1891      break;      break;
# Line 2122  for (;;) Line 2128  for (;;)
2128        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2129        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2130        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2131        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2132          code += 2;          code += 2;
2133        break;        break;
2134    
2135        case OP_MARK:        case OP_MARK:
2136        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2137        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2138        case OP_THEN_ARG:        case OP_THEN_ARG:
2139        code += code[1];        code += code[1];
2140        break;        break;
# Line 2242  for (;;) Line 2245  for (;;)
2245        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2246        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2247        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2248        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2249          code += 2;          code += 2;
2250        break;        break;
2251    
2252        case OP_MARK:        case OP_MARK:
2253        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2254        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2255        case OP_THEN_ARG:        case OP_THEN_ARG:
2256        code += code[1];        code += code[1];
2257        break;        break;
# Line 2568  for (code = first_significant_code(code Line 2568  for (code = first_significant_code(code
2568      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2569      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2570      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2571      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2572        code += 2;        code += 2;
2573      break;      break;
2574    
# Line 2616  for (code = first_significant_code(code Line 2616  for (code = first_significant_code(code
2616      case OP_MARK:      case OP_MARK:
2617      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
2618      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     code += code[1];  
     break;  
   
2619      case OP_THEN_ARG:      case OP_THEN_ARG:
2620      code += code[1];      code += code[1];
2621      break;      break;
# Line 2903  PUT(previous_callout, 2 + LINK_SIZE, len Line 2900  PUT(previous_callout, 2 + LINK_SIZE, len
2900  /* This function is passed the start and end of a class range, in UTF-8 mode  /* This function is passed the start and end of a class range, in UTF-8 mode
2901  with UCP support. It searches up the characters, looking for ranges of  with UCP support. It searches up the characters, looking for ranges of
2902  characters in the "other" case. Each call returns the next one, updating the  characters in the "other" case. Each call returns the next one, updating the
2903  start address. A character with multiple other cases is returned on its own  start address. A character with multiple other cases is returned on its own
2904  with a special return value.  with a special return value.
2905    
2906  Arguments:  Arguments:
# Line 2915  Arguments: Line 2912  Arguments:
2912  Yield:        -1 when no more  Yield:        -1 when no more
2913                 0 when a range is returned                 0 when a range is returned
2914                >0 the CASESET offset for char with multiple other cases                >0 the CASESET offset for char with multiple other cases
2915                  in this case, ocptr contains the original                  in this case, ocptr contains the original
2916  */  */
2917    
2918  static int  static int
# Line 2925  get_othercase_range(pcre_uint32 *cptr, p Line 2922  get_othercase_range(pcre_uint32 *cptr, p
2922  pcre_uint32 c, othercase, next;  pcre_uint32 c, othercase, next;
2923  unsigned int co;  unsigned int co;
2924    
2925  /* 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
2926  cases, return its case offset value. */  cases, return its case offset value. */
2927    
2928  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2929    {    {
2930    if ((co = UCD_CASESET(c)) != 0)    if ((co = UCD_CASESET(c)) != 0)
2931      {      {
2932      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2933      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2934      return (int)co;      return (int)co;
2935      }      }
2936    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2937    }    }
2938    
2939  if (c > d) return -1;  /* Reached end of range */  if (c > d) return -1;  /* Reached end of range */
# Line 3019  switch(ptype) Line 3016  switch(ptype)
3016    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
3017            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
3018            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
3019    
3020  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3021    case PT_CLIST:    case PT_CLIST:
3022    p = PRIV(ucd_caseless_sets) + prop->caseset;    p = PRIV(ucd_caseless_sets) + prop->caseset;
# Line 3094  value is a character, a negative value i Line 3091  value is a character, a negative value i
3091  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3092    {    {
3093    int temperrorcode = 0;    int temperrorcode = 0;
3094    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,
3095        FALSE);
3096    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3097    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3098    }    }
# Line 3139  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3137  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3137    
3138  /* If the previous item is a character, get its value. */  /* If the previous item is a character, get its value. */
3139    
3140  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3141      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
3142    {    {
3143  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3156  if (escape == 0) Line 3154  if (escape == 0)
3154    {    {
3155    /* For a caseless UTF match, the next character may have more than one other    /* For a caseless UTF match, the next character may have more than one other
3156    case, which maps to the special PT_CLIST property. Check this first. */    case, which maps to the special PT_CLIST property. Check this first. */
3157    
3158  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3159    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3160      {      {
# Line 3172  if (escape == 0) Line 3170  if (escape == 0)
3170    
3171      /* For CHARI (caseless character) we must check the other case. If we have      /* For CHARI (caseless character) we must check the other case. If we have
3172      Unicode property support, we can use it to test the other case of      Unicode property support, we can use it to test the other case of
3173      high-valued characters. We know that next can have only one other case,      high-valued characters. We know that next can have only one other case,
3174      because multi-other-case characters are dealt with above. */      because multi-other-case characters are dealt with above. */
3175    
3176      case OP_CHARI:      case OP_CHARI:
# Line 3192  if (escape == 0) Line 3190  if (escape == 0)
3190      else      else
3191  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3192      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3193    
3194      case OP_NOT:      case OP_NOT:
3195      return c == next;      return c == next;
3196    
3197      case OP_NOTI:      case OP_NOTI:
3198      if (c == next) return TRUE;      if (c == next) return TRUE;
3199  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3239  if (escape == 0) Line 3237  if (escape == 0)
3237      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3238      switch(next)      switch(next)
3239        {        {
3240        HSPACE_CASES:        HSPACE_CASES:
3241        return op_code == OP_NOT_HSPACE;        return op_code == OP_NOT_HSPACE;
3242    
3243        default:        default:
# Line 3251  if (escape == 0) Line 3249  if (escape == 0)
3249      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
3250      switch(next)      switch(next)
3251        {        {
3252        VSPACE_CASES:        VSPACE_CASES:
3253        return op_code == OP_NOT_VSPACE;        return op_code == OP_NOT_VSPACE;
3254    
3255        default:        default:
# Line 3305  switch(op_code) Line 3303  switch(op_code)
3303      case ESC_H:      case ESC_H:
3304      switch(c)      switch(c)
3305        {        {
3306        HSPACE_CASES:        HSPACE_CASES:
3307        return escape != ESC_h;        return escape != ESC_h;
3308    
3309        default:        default:
3310        return escape == ESC_h;        return escape == ESC_h;
3311        }        }
# Line 3316  switch(op_code) Line 3314  switch(op_code)
3314      case ESC_V:      case ESC_V:
3315      switch(c)      switch(c)
3316        {        {
3317        VSPACE_CASES:        VSPACE_CASES:
3318        return escape != ESC_v;        return escape != ESC_v;
3319    
3320        default:        default:
# Line 3428  switch(op_code) Line 3426  switch(op_code)
3426  *************************************************/  *************************************************/
3427    
3428  /* This function packages up the logic of adding a character or range of  /* This function packages up the logic of adding a character or range of
3429  characters to a class. The character values in the arguments will be within the  characters to a class. The character values in the arguments will be within the
3430  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3431  mutually recursive with the function immediately below.  mutually recursive with the function immediately below.
3432    
3433  Arguments:  Arguments:
3434    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3435    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3436    options       the options word    options       the options word
3437    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3438    start         start of range character    start         start of range character
3439    end           end of range character    end           end of range character
3440    
3441  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3442                  the pointer to extra data is updated                  the pointer to extra data is updated
3443  */  */
# Line 3451  add_to_class(pcre_uint8 *classbits, pcre Line 3449  add_to_class(pcre_uint8 *classbits, pcre
3449  pcre_uint32 c;  pcre_uint32 c;
3450  int n8 = 0;  int n8 = 0;
3451    
3452  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
3453  cases. In Unicode, there are 8-bit characters that have alternate cases that  cases. In Unicode, there are 8-bit characters that have alternate cases that
3454  are greater than 255 and vice-versa. Sometimes we can just extend the original  are greater than 255 and vice-versa. Sometimes we can just extend the original
3455  range. */  range. */
3456    
3457  if ((options & PCRE_CASELESS) != 0)  if ((options & PCRE_CASELESS) != 0)
3458    {    {
3459  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3460    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3461      {      {
3462      int rc;      int rc;
3463      pcre_uint32 oc, od;      pcre_uint32 oc, od;
3464    
3465      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3466      c = start;      c = start;
3467    
3468      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3469        {        {
3470        /* Handle a single character that has more than one other case. */        /* Handle a single character that has more than one other case. */
3471    
3472        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3473          PRIV(ucd_caseless_sets) + rc, oc);          PRIV(ucd_caseless_sets) + rc, oc);
3474    
3475        /* Do nothing if the other case range is within the original range. */        /* Do nothing if the other case range is within the original range. */
3476    
3477        else if (oc >= start && od <= end) continue;        else if (oc >= start && od <= end) continue;
3478    
3479        /* Extend the original range if there is overlap, noting that if oc < c, we        /* Extend the original range if there is overlap, noting that if oc < c, we
3480        can't have od > end because a subrange is always shorter than the basic        can't have od > end because a subrange is always shorter than the basic
3481        range. Otherwise, use a recursive call to add the additional range. */        range. Otherwise, use a recursive call to add the additional range. */
3482    
3483        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3484        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3485        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
# Line 3491  if ((options & PCRE_CASELESS) != 0) Line 3489  if ((options & PCRE_CASELESS) != 0)
3489  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3490    
3491    /* Not UTF-mode, or no UCP */    /* Not UTF-mode, or no UCP */
3492    
3493    for (c = start; c <= end && c < 256; c++)    for (c = start; c <= end && c < 256; c++)
3494      {      {
3495      SETBIT(classbits, cd->fcc[c]);      SETBIT(classbits, cd->fcc[c]);
3496      n8++;      n8++;
3497      }      }
3498    }    }
3499    
3500  /* Now handle the original range. Adjust the final value according to the bit  /* Now handle the original range. Adjust the final value according to the bit
3501  length - this means that the same lists of (e.g.) horizontal spaces can be used  length - this means that the same lists of (e.g.) horizontal spaces can be used
3502  in all cases. */  in all cases. */
# Line 3524  if (end < 0x100) Line 3522  if (end < 0x100)
3522    {    {
3523    for (c = start; c <= end; c++)    for (c = start; c <= end; c++)
3524      {      {
3525      n8++;      n8++;
3526      SETBIT(classbits, c);      SETBIT(classbits, c);
3527      }      }
3528    }    }
3529    
3530  else  else
3531    {    {
3532    pcre_uchar *uchardata = *uchardptr;    pcre_uchar *uchardata = *uchardptr;
3533    
3534  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3535    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3536      {      {
3537      if (start < end)      if (start < end)
3538        {        {
3539        *uchardata++ = XCL_RANGE;        *uchardata++ = XCL_RANGE;
3540        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3541        uchardata += PRIV(ord2utf)(end, uchardata);        uchardata += PRIV(ord2utf)(end, uchardata);
3542        }        }
3543      else if (start == end)      else if (start == end)
3544        {        {
3545        *uchardata++ = XCL_SINGLE;        *uchardata++ = XCL_SINGLE;
3546        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3547        }        }
3548      }      }
3549    else    else
3550  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3551    
3552    /* Without UTF support, character values are constrained by the bit length,    /* Without UTF support, character values are constrained by the bit length,
3553    and can only be > 256 for 16-bit and 32-bit libraries. */    and can only be > 256 for 16-bit and 32-bit libraries. */
3554    
3555  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3556      {}      {}
3557  #else  #else
3558    if (start < end)    if (start < end)
3559      {      {
3560      *uchardata++ = XCL_RANGE;      *uchardata++ = XCL_RANGE;
# Line 3567  else Line 3565  else
3565      {      {
3566      *uchardata++ = XCL_SINGLE;      *uchardata++ = XCL_SINGLE;
3567      *uchardata++ = start;      *uchardata++ = start;
3568      }      }
3569  #endif  #endif
3570    
3571    *uchardptr = uchardata;   /* Updata extra data pointer */    *uchardptr = uchardata;   /* Updata extra data pointer */
3572    }    }
3573    
3574  return n8;    /* Number of 8-bit characters */  return n8;    /* Number of 8-bit characters */
3575  }  }
3576    
3577    
3578    
3579    
3580  /*************************************************  /*************************************************
3581  *        Add a list of characters to a class     *  *        Add a list of characters to a class     *
3582  *************************************************/  *************************************************/
3583    
3584  /* This function is used for adding a list of case-equivalent characters to a  /* This function is used for adding a list of case-equivalent characters to a
3585  class, and also for adding a list of horizontal or vertical whitespace. If the  class, and also for adding a list of horizontal or vertical whitespace. If the
3586  list is in order (which it should be), ranges of characters are detected and  list is in order (which it should be), ranges of characters are detected and
3587  handled appropriately. This function is mutually recursive with the function  handled appropriately. This function is mutually recursive with the function
# Line 3593  Arguments: Line 3591  Arguments:
3591    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3592    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3593    options       the options word    options       the options word
3594    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3595    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3596    except        character to omit; this is used when adding lists of    except        character to omit; this is used when adding lists of
3597                    case-equivalent characters to avoid including the one we                    case-equivalent characters to avoid including the one we
3598                    already know about                    already know about
3599    
3600  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3601                  the pointer to extra data is updated                  the pointer to extra data is updated
3602  */  */
# Line 3612  while (p[0] < NOTACHAR) Line 3610  while (p[0] < NOTACHAR)
3610    {    {
3611    int n = 0;    int n = 0;
3612    if (p[0] != except)    if (p[0] != except)
3613      {      {
3614      while(p[n+1] == p[0] + n + 1) n++;      while(p[n+1] == p[0] + n + 1) n++;
3615      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3616      }      }
3617    p += n + 1;    p += n + 1;
3618    }    }
3619  return n8;  return n8;
3620  }  }
3621    
3622    
3623    
# Line 3634  Arguments: Line 3632  Arguments:
3632    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3633    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3634    options       the options word    options       the options word
3635    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3636    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3637    
3638  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3639                  the pointer to extra data is updated                  the pointer to extra data is updated
3640  */  */
3641    
3642  static int  static int
3643  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3644    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3645  {  {
3646  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
# Line 3654  while (p[0] < NOTACHAR) Line 3652  while (p[0] < NOTACHAR)
3652    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3653    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3654      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3655    p++;    p++;
3656    }    }
3657  return n8;  return n8;
3658  }  }
3659    
3660    
3661    
# Line 3741  BOOL utf = FALSE; Line 3739  BOOL utf = FALSE;
3739  #endif  #endif
3740    
3741  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3742  class_uchardata always so that it can be passed to add_to_class() always,  class_uchardata always so that it can be passed to add_to_class() always,
3743  though it will not be used in non-UTF 8-bit cases. This avoids having to supply  though it will not be used in non-UTF 8-bit cases. This avoids having to supply
3744  alternative calls for the different cases. */  alternative calls for the different cases. */
3745    
3746  pcre_uchar *class_uchardata;  pcre_uchar *class_uchardata;
# Line 4136  for (;; ptr++) Line 4134  for (;; ptr++)
4134        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
4135        data and reset the pointer. This is so that very large classes that        data and reset the pointer. This is so that very large classes that
4136        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
4137        (which is on the stack). We have to remember that there was XCLASS data,        (which is on the stack). We have to remember that there was XCLASS data,
4138        however. */        however. */
4139    
4140        if (lengthptr != NULL && class_uchardata > class_uchardata_base)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
# Line 4200  for (;; ptr++) Line 4198  for (;; ptr++)
4198          alpha. This relies on the fact that the class table starts with          alpha. This relies on the fact that the class table starts with
4199          alpha, lower, upper as the first 3 entries. */          alpha, lower, upper as the first 3 entries. */
4200    
4201          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)
4202            posix_class = 0;            posix_class = 0;
4203    
4204          /* When PCRE_UCP is set, some of the POSIX classes are converted to          /* When PCRE_UCP is set, some of the POSIX classes are converted to
# Line 4277  for (;; ptr++) Line 4275  for (;; ptr++)
4275    
4276        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4277          {          {
4278          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,
4279              TRUE);
4280          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4281            if (escape == 0) c = ec;
         if (escape == 0)  
           c = ec;  
4282          else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */          else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */
4283          else if (escape == ESC_N)            /* \N is not supported in a class */          else if (escape == ESC_N)          /* \N is not supported in a class */
4284            {            {
4285            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4286            goto FAILED;            goto FAILED;
# Line 4356  for (;; ptr++) Line 4352  for (;; ptr++)
4352              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4353              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4354              continue;              continue;
4355    
4356              /* The rest apply in both UCP and non-UCP cases. */              /* The rest apply in both UCP and non-UCP cases. */
4357    
4358              case ESC_h:              case ESC_h:
4359              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4360                PRIV(hspace_list), NOTACHAR);                PRIV(hspace_list), NOTACHAR);
4361              continue;              continue;
4362    
4363              case ESC_H:              case ESC_H:
4364              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4365                cd, PRIV(hspace_list));                cd, PRIV(hspace_list));
4366              continue;              continue;
4367    
4368              case ESC_v:              case ESC_v:
4369              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4370                PRIV(vspace_list), NOTACHAR);                PRIV(vspace_list), NOTACHAR);
4371              continue;              continue;
4372    
4373              case ESC_V:              case ESC_V:
4374              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4375                cd, PRIV(vspace_list));                cd, PRIV(vspace_list));
4376              continue;              continue;
4377    
4378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4414  for (;; ptr++) Line 4410  for (;; ptr++)
4410    
4411          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4412          This may be greater than 256. */          This may be greater than 256. */
4413    
4414          escape = 0;          escape = 0;
4415    
4416          }   /* End of backslash handling */          }   /* End of backslash handling */
# Line 4455  for (;; ptr++) Line 4451  for (;; ptr++)
4451            inescq = TRUE;            inescq = TRUE;
4452            break;            break;
4453            }            }
4454    
4455          /* Minus (hyphen) at the end of a class is treated as a literal, so put          /* Minus (hyphen) at the end of a class is treated as a literal, so put
4456          back the pointer and jump to handle the character that preceded it. */          back the pointer and jump to handle the character that preceded it. */
4457    
# Line 4464  for (;; ptr++) Line 4460  for (;; ptr++)
4460            ptr = oldptr;            ptr = oldptr;
4461            goto CLASS_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4462            }            }
4463    
4464          /* Otherwise, we have a potential range; pick up the next character */          /* Otherwise, we have a potential range; pick up the next character */
4465    
4466  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 4511  for (;; ptr++) Line 4507  for (;; ptr++)
4507          /* We have found a character range, so single character optimizations          /* We have found a character range, so single character optimizations
4508          cannot be done anymore. Any value greater than 1 indicates that there          cannot be done anymore. Any value greater than 1 indicates that there
4509          is more than one character. */          is more than one character. */
4510    
4511          class_one_char = 2;          class_one_char = 2;
4512    
4513          /* Remember an explicit \r or \n, and add the range to the class. */          /* Remember an explicit \r or \n, and add the range to the class. */
4514    
4515          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4516    
4517          class_has_8bitchar +=          class_has_8bitchar +=
4518            add_to_class(classbits, &class_uchardata, options, cd, c, d);            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4519    
4520          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4521          }          }
4522    
4523        /* Handle a single character - we can get here for a normal non-escape        /* Handle a single character - we can get here for a normal non-escape
4524        char, or after \ that introduces a single character or for an apparent        char, or after \ that introduces a single character or for an apparent
4525        range that isn't. Only the value 1 matters for class_one_char, so don't        range that isn't. Only the value 1 matters for class_one_char, so don't
4526        increase it if it is already 2 or more ... just in case there's a class        increase it if it is already 2 or more ... just in case there's a class
4527        with a zillion characters in it. */        with a zillion characters in it. */
4528    
4529        CLASS_SINGLE_CHARACTER:        CLASS_SINGLE_CHARACTER:
# Line 4550  for (;; ptr++) Line 4546  for (;; ptr++)
4546    
4547          if (negate_class)          if (negate_class)
4548            {            {
4549  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4550            int d;            int d;
4551  #endif  #endif
4552            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4553            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4554            zerofirstcharflags = firstcharflags;            zerofirstcharflags = firstcharflags;
# Line 4560  for (;; ptr++) Line 4556  for (;; ptr++)
4556            /* For caseless UTF-8 mode when UCP support is available, check            /* For caseless UTF-8 mode when UCP support is available, check
4557            whether this character has more than one other case. If so, generate            whether this character has more than one other case. If so, generate
4558            a special OP_NOTPROP item instead of OP_NOTI. */            a special OP_NOTPROP item instead of OP_NOTI. */
4559    
4560  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4561            if (utf && (options & PCRE_CASELESS) != 0 &&            if (utf && (options & PCRE_CASELESS) != 0 &&
4562                (d = UCD_CASESET(c)) != 0)                (d = UCD_CASESET(c)) != 0)
4563              {              {
4564              *code++ = OP_NOTPROP;              *code++ = OP_NOTPROP;
4565              *code++ = PT_CLIST;              *code++ = PT_CLIST;
4566              *code++ = d;              *code++ = d;
4567              }              }
4568            else            else
4569  #endif  #endif
4570            /* Char has only one other case, or UCP not available */            /* Char has only one other case, or UCP not available */
4571    
# Line 4582  for (;; ptr++) Line 4578  for (;; ptr++)
4578  #endif  #endif
4579                *code++ = c;                *code++ = c;
4580              }              }
4581    
4582            /* We are finished with this character class */            /* We are finished with this character class */
4583    
4584            goto END_CLASS;            goto END_CLASS;
4585            }            }
4586    
# Line 4602  for (;; ptr++) Line 4598  for (;; ptr++)
4598            }            }
4599          goto ONE_CHAR;          goto ONE_CHAR;
4600          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4601    
4602        /* There is more than one character in the class, or an XCLASS item        /* There is more than one character in the class, or an XCLASS item
4603        has been generated. Add this character to the class. */        has been generated. Add this character to the class. */
4604    
4605        class_has_8bitchar +=        class_has_8bitchar +=
4606          add_to_class(classbits, &class_uchardata, options, cd, c, c);          add_to_class(classbits, &class_uchardata, options, cd, c, c);
4607        }        }
4608    
# Line 4627  for (;; ptr++) Line 4623  for (;; ptr++)
4623        goto FAILED;        goto FAILED;
4624        }        }
4625    
4626      /* We will need an XCLASS if data has been placed in class_uchardata. In      /* We will need an XCLASS if data has been placed in class_uchardata. In
4627      the second phase this is a sufficient test. However, in the pre-compile      the second phase this is a sufficient test. However, in the pre-compile
4628      phase, class_uchardata gets emptied to prevent workspace overflow, so it      phase, class_uchardata gets emptied to prevent workspace overflow, so it
4629      only if the very last character in the class needs XCLASS will it contain      only if the very last character in the class needs XCLASS will it contain
4630      anything at this point. For this reason, xclass gets set TRUE above when      anything at this point. For this reason, xclass gets set TRUE above when
4631      uchar_classdata is emptied, and that's why this code is the way it is here      uchar_classdata is emptied, and that's why this code is the way it is here
4632      instead of just doing a test on class_uchardata below. */      instead of just doing a test on class_uchardata below. */
4633    
4634  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4635      if (class_uchardata > class_uchardata_base) xclass = TRUE;      if (class_uchardata > class_uchardata_base) xclass = TRUE;
4636  #endif  #endif
# Line 4703  for (;; ptr++) Line 4699  for (;; ptr++)
4699        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4700        }        }
4701      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4702    
4703      END_CLASS:      END_CLASS:
4704      break;      break;
4705    
# Line 4907  for (;; ptr++) Line 4903  for (;; ptr++)
4903    
4904        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
4905    
       /*--------------------------------------------------------------------*/  
       /* This code is obsolete from release 8.00; the restriction was finally  
       removed: */  
   
       /* All real repeats make it impossible to handle partial matching (maybe  
       one day we will be able to remove this restriction). */  
   
       /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */  
       /*--------------------------------------------------------------------*/  
   
4906        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
4907    
4908        repeat_type += op_type;        repeat_type += op_type;
# Line 5063  for (;; ptr++) Line 5049  for (;; ptr++)
5049          goto END_REPEAT;          goto END_REPEAT;
5050          }          }
5051    
       /*--------------------------------------------------------------------*/  
       /* This code is obsolete from release 8.00; the restriction was finally  
       removed: */  
   
       /* All real repeats make it impossible to handle partial matching (maybe  
       one day we will be able to remove this restriction). */  
   
       /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */  
       /*--------------------------------------------------------------------*/  
   
5052        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
5053          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
5054        else if (repeat_min == 1 && repeat_max == -1)        else if (repeat_min == 1 && repeat_max == -1)
# Line 5749  for (;; ptr++) Line 5725  for (;; ptr++)
5725          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5726          case CHAR_LEFT_PARENTHESIS:          case CHAR_LEFT_PARENTHESIS:
5727          bravalue = OP_COND;       /* Conditional group */          bravalue = OP_COND;       /* Conditional group */
5728            tempptr = ptr;
5729    
5730          /* A condition can be an assertion, a number (referring to a numbered          /* A condition can be an assertion, a number (referring to a numbered
5731          group), a name (referring to a named group), or 'R', referring to          group), a name (referring to a named group), or 'R', referring to
# Line 5761  for (;; ptr++) Line 5738  for (;; ptr++)
5738          be the recursive thing or the name 'R' (and similarly for 'R' followed          be the recursive thing or the name 'R' (and similarly for 'R' followed
5739          by digits), and (b) a number could be a name that consists of digits.          by digits), and (b) a number could be a name that consists of digits.
5740          In both cases, we look for a name first; if not found, we try the other          In both cases, we look for a name first; if not found, we try the other
5741          cases. */          cases.
5742    
5743            For compatibility with auto-callouts, we allow a callout to be
5744            specified before a condition that is an assertion. First, check for the
5745            syntax of a callout; if found, adjust the temporary pointer that is
5746            used to check for an assertion condition. That's all that is needed! */
5747    
5748            if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)
5749              {
5750              for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
5751              if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
5752                tempptr += i + 1;
5753              }
5754    
5755          /* For conditions that are assertions, check the syntax, and then exit          /* For conditions that are assertions, check the syntax, and then exit
5756          the switch. This will take control down to where bracketed groups,          the switch. This will take control down to where bracketed groups,
5757          including assertions, are processed. */          including assertions, are processed. */
5758    
5759          if (ptr[1] == CHAR_QUESTION_MARK && (ptr[2] == CHAR_EQUALS_SIGN ||          if (tempptr[1] == CHAR_QUESTION_MARK &&
5760              ptr[2] == CHAR_EXCLAMATION_MARK || ptr[2] == CHAR_LESS_THAN_SIGN))                (tempptr[2] == CHAR_EQUALS_SIGN ||
5761                   tempptr[2] == CHAR_EXCLAMATION_MARK ||
5762                   tempptr[2] == CHAR_LESS_THAN_SIGN))
5763            break;            break;
5764    
5765          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
# Line 6703  for (;; ptr++) Line 6694  for (;; ptr++)
6694        /* If the subpattern set a required byte (or set a first byte that isn't        /* If the subpattern set a required byte (or set a first byte that isn't
6695        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6696    
6697        if (subreqcharflags >= 0)        if (subreqcharflags >= 0)
6698          {          {
6699          reqchar = subreqchar;          reqchar = subreqchar;
6700          reqcharflags = subreqcharflags;          reqcharflags = subreqcharflags;
# Line 6738  for (;; ptr++) Line 6729  for (;; ptr++)
6729      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6730      tempptr = ptr;      tempptr = ptr;
6731      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
   
6732      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6733    
6734      if (escape == 0)      if (escape == 0)                  /* The escape coded a single character */
6735        c = ec;        c = ec;
6736      else      else
6737        {        {
# Line 6907  for (;; ptr++) Line 6897  for (;; ptr++)
6897        can obtain the OP value by negating the escape value in the default        can obtain the OP value by negating the escape value in the default
6898        situation when PCRE_UCP is not set. When it *is* set, we substitute        situation when PCRE_UCP is not set. When it *is* set, we substitute
6899        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6900        lookbehind. */        lookbehind, and \A also behaves as if it does. */
6901    
6902        else        else
6903          {          {
6904          if ((escape == ESC_b || escape == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&
6905                 cd->max_lookbehind == 0)
6906            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6907  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6908          if (escape >= ESC_DU && escape <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
# Line 6969  for (;; ptr++) Line 6960  for (;; ptr++)
6960    
6961      ONE_CHAR:      ONE_CHAR:
6962      previous = code;      previous = code;
6963    
6964      /* For caseless UTF-8 mode when UCP support is available, check whether      /* For caseless UTF-8 mode when UCP support is available, check whether
6965      this character has more than one other case. If so, generate a special      this character has more than one other case. If so, generate a special
6966      OP_PROP item instead of OP_CHARI. */      OP_PROP item instead of OP_CHARI. */
6967    
6968  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6969      if (utf && (options & PCRE_CASELESS) != 0)      if (utf && (options & PCRE_CASELESS) != 0)
6970        {        {
# Line 6983  for (;; ptr++) Line 6974  for (;; ptr++)
6974          *code++ = OP_PROP;          *code++ = OP_PROP;
6975          *code++ = PT_CLIST;          *code++ = PT_CLIST;
6976          *code++ = c;          *code++ = c;
6977          if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;
6978          break;          break;
6979          }          }
6980        }        }
6981  #endif  #endif
6982    
6983      /* Caseful matches, or not one of the multicase characters. */      /* Caseful matches, or not one of the multicase characters. */
6984    
6985      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6986      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6987    
# Line 7180  for (;;) Line 7171  for (;;)
7171    into the length. */    into the length. */
7172    
7173    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
7174          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,
7175          cond_depth, cd, (lengthptr == NULL)? NULL : &length))          cond_depth, cd, (lengthptr == NULL)? NULL : &length))
7176      {      {
7177      *ptrptr = ptr;      *ptrptr = ptr;
# Line 7218  for (;;) Line 7209  for (;;)
7209        we have to abandon the firstchar for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
7210        previously no reqchar, it takes on the value of the old firstchar. */        previously no reqchar, it takes on the value of the old firstchar. */
7211    
7212        if (firstcharflags >= 0 &&        if (firstcharflags >= 0 &&
7213            (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))            (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))
7214          {          {
7215          if (reqcharflags < 0)          if (reqcharflags < 0)
7216            {            {
7217            reqchar = firstchar;            reqchar = firstchar;
7218            reqcharflags = firstcharflags;            reqcharflags = firstcharflags;
# Line 7580  do { Line 7571  do {
7571       {       {
7572       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7573       }       }
7574    
7575     /* Atomic brackets */     /* Atomic brackets */
7576    
7577     else if (op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
# Line 7775  pcre32_compile2(PCRE_SPTR32 pattern, int Line 7766  pcre32_compile2(PCRE_SPTR32 pattern, int
7766  {  {
7767  REAL_PCRE *re;  REAL_PCRE *re;
7768  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
 pcre_uint32 firstchar, reqchar;  
7769  pcre_int32 firstcharflags, reqcharflags;  pcre_int32 firstcharflags, reqcharflags;
7770    pcre_uint32 firstchar, reqchar;
7771    pcre_uint32 limit_match = PCRE_UINT32_MAX;
7772    pcre_uint32 limit_recursion = PCRE_UINT32_MAX;
7773  int newline;  int newline;
7774  int errorcode = 0;  int errorcode = 0;
7775  int skipatstart = 0;  int skipatstart = 0;
7776  BOOL utf;  BOOL utf;
7777    BOOL never_utf = FALSE;
7778  size_t size;  size_t size;
7779  pcre_uchar *code;  pcre_uchar *code;
7780  const pcre_uchar *codestart;  const pcre_uchar *codestart;
# Line 7840  if ((options & ~PUBLIC_COMPILE_OPTIONS) Line 7834  if ((options & ~PUBLIC_COMPILE_OPTIONS)
7834    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
7835    }    }
7836    
7837    /* If PCRE_NEVER_UTF is set, remember it. */
7838    
7839    if ((options & PCRE_NEVER_UTF) != 0) never_utf = TRUE;
7840    
7841  /* Check for global one-time settings at the start of the pattern, and remember  /* Check for global one-time settings at the start of the pattern, and remember
7842  the offset for later. */  the offset for later. */
7843    
7844    cd->external_flags = 0;   /* Initialize here for LIMIT_MATCH/RECURSION */
7845    
7846  while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS &&  while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS &&
7847         ptr[skipatstart+1] == CHAR_ASTERISK)         ptr[skipatstart+1] == CHAR_ASTERISK)
7848    {    {
7849    int newnl = 0;    int newnl = 0;
7850    int newbsr = 0;    int newbsr = 0;
7851    
7852  /* For completeness and backward compatibility, (*UTFn) is supported in the  /* For completeness and backward compatibility, (*UTFn) is supported in the
7853  relevant libraries, but (*UTF) is generic and always supported. Note that  relevant libraries, but (*UTF) is generic and always supported. Note that
7854  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */
7855    
7856  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
7857    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
# Line 7867  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. * Line 7867  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. *
7867  #endif  #endif
7868    
7869    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)
7870      { skipatstart += 6; options |= PCRE_UTF8; continue; }      { skipatstart += 6; options |= PCRE_UTF8; continue; }
7871    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
7872      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7873    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
7874      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }
7875    
7876      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LIMIT_MATCH_EQ, 12) == 0)
7877        {
7878        pcre_uint32 c = 0;
7879        int p = skipatstart + 14;
7880        while (isdigit(ptr[p]))
7881          {
7882          if (c > PCRE_UINT32_MAX / 10 - 1) break;   /* Integer overflow */
7883          c = c*10 + ptr[p++] - CHAR_0;
7884          }
7885        if (ptr[p++] != CHAR_RIGHT_PARENTHESIS) break;
7886        if (c < limit_match)
7887          {
7888          limit_match = c;
7889          cd->external_flags |= PCRE_MLSET;
7890          }
7891        skipatstart = p;
7892        continue;
7893        }
7894    
7895      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LIMIT_RECURSION_EQ, 16) == 0)
7896        {
7897        pcre_uint32 c = 0;
7898        int p = skipatstart + 18;
7899        while (isdigit(ptr[p]))
7900          {
7901          if (c > PCRE_UINT32_MAX / 10 - 1) break;   /* Integer overflow check */
7902          c = c*10 + ptr[p++] - CHAR_0;
7903          }
7904        if (ptr[p++] != CHAR_RIGHT_PARENTHESIS) break;
7905        if (c < limit_recursion)
7906          {
7907          limit_recursion = c;
7908          cd->external_flags |= PCRE_RLSET;
7909          }
7910        skipatstart = p;
7911        continue;
7912        }
7913    
7914    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)
7915      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
7916    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)
# Line 7898  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. * Line 7936  PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. *
7936    
7937  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */
7938  utf = (options & PCRE_UTF8) != 0;  utf = (options & PCRE_UTF8) != 0;
7939    if (utf && never_utf)
7940      {
7941      errorcode = ERR78;
7942      goto PCRE_EARLY_ERROR_RETURN2;
7943      }
7944    
7945  /* Can't support UTF unless PCRE has been compiled to include the code. The  /* Can't support UTF unless PCRE has been compiled to include the code. The
7946  return of an error code from PRIV(valid_utf)() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
# Line 8020  cd->req_varyopt = 0; Line 8063  cd->req_varyopt = 0;
8063  cd->assert_depth = 0;  cd->assert_depth = 0;
8064  cd->max_lookbehind = 0;  cd->max_lookbehind = 0;
8065  cd->external_options = options;  cd->external_options = options;
 cd->external_flags = 0;  
8066  cd->open_caps = NULL;  cd->open_caps = NULL;
8067    
8068  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we
# Line 8070  re->magic_number = MAGIC_NUMBER; Line 8112  re->magic_number = MAGIC_NUMBER;
8112  re->size = (int)size;  re->size = (int)size;
8113  re->options = cd->external_options;  re->options = cd->external_options;
8114  re->flags = cd->external_flags;  re->flags = cd->external_flags;
8115    re->limit_match = limit_match;
8116    re->limit_recursion = limit_recursion;
8117  re->first_char = 0;  re->first_char = 0;
8118  re->req_char = 0;  re->req_char = 0;
8119  re->name_table_offset = sizeof(REAL_PCRE) / sizeof(pcre_uchar);  re->name_table_offset = sizeof(REAL_PCRE) / sizeof(pcre_uchar);
# Line 8079  re->ref_count = 0; Line 8123  re->ref_count = 0;
8123  re->tables = (tables == PRIV(default_tables))? NULL : tables;  re->tables = (tables == PRIV(default_tables))? NULL : tables;
8124  re->nullpad = NULL;  re->nullpad = NULL;
8125  #ifdef COMPILE_PCRE32  #ifdef COMPILE_PCRE32
8126  re->dummy1 = re->dummy2 = 0;  re->dummy = 0;
8127    #else
8128    re->dummy1 = re->dummy2 = re->dummy3 = 0;
8129  #endif  #endif
8130    
8131  /* The starting points of the name/number translation table and of the code are  /* The starting points of the name/number translation table and of the code are
# Line 8139  if (code - codestart > length) errorcode Line 8185  if (code - codestart > length) errorcode
8185    
8186  #ifdef SUPPORT_VALGRIND  #ifdef SUPPORT_VALGRIND
8187  /* If the estimated length exceeds the really used length, mark the extra  /* If the estimated length exceeds the really used length, mark the extra
8188  allocated memory as unadressable, so that any out-of-bound reads can be  allocated memory as unadressable, so that any out-of-bound reads can be
8189  detected. */  detected. */
8190  VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));  VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
8191  #endif  #endif

Legend:
Removed from v.1219  
changed lines
  Added in v.1313

  ViewVC Help
Powered by ViewVC 1.1.5