/[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 1072 by chpe, Tue Oct 16 15:54:40 2012 UTC revision 1305 by ph10, Mon Apr 1 14:50:45 2013 UTC
# 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,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
88      int, int, int *, int *, branch_chain *, compile_data *, int *);      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,
89        compile_data *, int *);
90    
91    
92    
# Line 121  overrun before it actually does run off Line 122  overrun before it actually does run off
122    
123  /* Private flags added to firstchar and reqchar. */  /* Private flags added to firstchar and reqchar. */
124    
125  #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */  #define REQ_CASELESS    (1 << 0)        /* Indicates caselessness */
126  #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */  #define REQ_VARY        (1 << 1)        /* Reqchar followed non-literal item */
127  #define REQ_MASK       (REQ_CASELESS | REQ_VARY)  /* Negative values for the firstchar and reqchar flags */
128    #define REQ_UNSET       (-2)
129    #define REQ_NONE        (-1)
130    
131  /* Repeated character flags. */  /* Repeated character flags. */
132    
# Line 645  static const pcre_uint8 ebcdic_chartab[] Line 648  static const pcre_uint8 ebcdic_chartab[]
648    
649    
650    
   
651  /*************************************************  /*************************************************
652  *            Find an error text                  *  *            Find an error text                  *
653  *************************************************/  *************************************************/
# Line 665  find_error_text(int n) Line 667  find_error_text(int n)
667  const char *s = error_texts;  const char *s = error_texts;
668  for (; n > 0; n--)  for (; n > 0; n--)
669    {    {
670    while (*s++ != 0) {};    while (*s++ != CHAR_NULL) {};
671    if (*s == 0) return "Error text not found (please report)";    if (*s == CHAR_NULL) return "Error text not found (please report)";
672    }    }
673  return s;  return s;
674  }  }
# Line 771  Returns:         zero => a data characte Line 773  Returns:         zero => a data characte
773  */  */
774    
775  static int  static int
776  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
777    int bracount, int options, BOOL isclass)    int bracount, int options, BOOL isclass)
778  {  {
779  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
# Line 786  ptr--;                            /* Set Line 788  ptr--;                            /* Set
788    
789  /* If backslash is at the end of the pattern, it's an error. */  /* If backslash is at the end of the pattern, it's an error. */
790    
791  if (c == 0) *errorcodeptr = ERR1;  if (c == CHAR_NULL) *errorcodeptr = ERR1;
792    
793  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup
794  in a table. A non-zero result is something that can be returned immediately.  in a table. A non-zero result is something that can be returned immediately.
# Line 795  Otherwise further processing may be requ Line 797  Otherwise further processing may be requ
797  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
798  /* Not alphanumeric */  /* Not alphanumeric */
799  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
800  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)
801      { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
802    
803  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
804  /* Not alphanumeric */  /* Not alphanumeric */
# Line 845  else Line 848  else
848            }            }
849    
850  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
851          if (c > (utf ? 0x10ffff : 0xff))          if (c > (utf ? 0x10ffffU : 0xffU))
852  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
853          if (c > (utf ? 0x10ffff : 0xffff))          if (c > (utf ? 0x10ffffU : 0xffffU))
854  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
855          if (utf && c > 0x10ffff)          if (utf && c > 0x10ffffU)
856  #endif  #endif
857            {            {
858            *errorcodeptr = ERR76;            *errorcodeptr = ERR76;
# Line 896  else Line 899  else
899      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
900        {        {
901        const pcre_uchar *p;        const pcre_uchar *p;
902        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)        for (p = ptr+2; *p != CHAR_NULL && *p != CHAR_RIGHT_CURLY_BRACKET; p++)
903          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
904        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != CHAR_NULL && *p != CHAR_RIGHT_CURLY_BRACKET)
905          {          {
906          escape = ESC_k;          escape = ESC_k;
907          break;          break;
# Line 1083  else Line 1086  else
1086  #endif  #endif
1087    
1088  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
1089          if (c > (utf ? 0x10ffff : 0xff)) { overflow = TRUE; break; }          if (c > (utf ? 0x10ffffU : 0xffU)) { overflow = TRUE; break; }
1090  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
1091          if (c > (utf ? 0x10ffff : 0xffff)) { overflow = TRUE; break; }          if (c > (utf ? 0x10ffffU : 0xffffU)) { overflow = TRUE; break; }
1092  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
1093          if (utf && c > 0x10ffff) { overflow = TRUE; break; }          if (utf && c > 0x10ffffU) { overflow = TRUE; break; }
1094  #endif  #endif
1095          }          }
1096    
# Line 1132  else Line 1135  else
1135    
1136      case CHAR_c:      case CHAR_c:
1137      c = *(++ptr);      c = *(++ptr);
1138      if (c == 0)      if (c == CHAR_NULL)
1139        {        {
1140        *errorcodeptr = ERR2;        *errorcodeptr = ERR2;
1141        break;        break;
# Line 1201  escape sequence. Line 1204  escape sequence.
1204  Argument:  Argument:
1205    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
1206    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
1207    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
1208      pdataptr       points to an unsigned int that is set to the detailed property value
1209    errorcodeptr   points to the error code variable    errorcodeptr   points to the error code variable
1210    
1211  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
1212  */  */
1213    
1214  static int  static BOOL
1215  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1216      unsigned int *pdataptr, int *errorcodeptr)
1217  {  {
1218  pcre_uchar c;  pcre_uchar c;
1219  int i, bot, top;  int i, bot, top;
# Line 1216  const pcre_uchar *ptr = *ptrptr; Line 1221  const pcre_uchar *ptr = *ptrptr;
1221  pcre_uchar name[32];  pcre_uchar name[32];
1222    
1223  c = *(++ptr);  c = *(++ptr);
1224  if (c == 0) goto ERROR_RETURN;  if (c == CHAR_NULL) goto ERROR_RETURN;
1225    
1226  *negptr = FALSE;  *negptr = FALSE;
1227    
# Line 1233  if (c == CHAR_LEFT_CURLY_BRACKET) Line 1238  if (c == CHAR_LEFT_CURLY_BRACKET)
1238    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)
1239      {      {
1240      c = *(++ptr);      c = *(++ptr);
1241      if (c == 0) goto ERROR_RETURN;      if (c == CHAR_NULL) goto ERROR_RETURN;
1242      if (c == CHAR_RIGHT_CURLY_BRACKET) break;      if (c == CHAR_RIGHT_CURLY_BRACKET) break;
1243      name[i] = c;      name[i] = c;
1244      }      }
# Line 1263  while (bot < top) Line 1268  while (bot < top)
1268    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);
1269    if (r == 0)    if (r == 0)
1270      {      {
1271      *dptr = PRIV(utt)[i].value;      *ptypeptr = PRIV(utt)[i].type;
1272      return PRIV(utt)[i].type;      *pdataptr = PRIV(utt)[i].value;
1273        return TRUE;
1274      }      }
1275    if (r > 0) bot = i + 1; else top = i;    if (r > 0) bot = i + 1; else top = i;
1276    }    }
1277    
1278  *errorcodeptr = ERR47;  *errorcodeptr = ERR47;
1279  *ptrptr = ptr;  *ptrptr = ptr;
1280  return -1;  return FALSE;
1281    
1282  ERROR_RETURN:  ERROR_RETURN:
1283  *errorcodeptr = ERR46;  *errorcodeptr = ERR46;
1284  *ptrptr = ptr;  *ptrptr = ptr;
1285  return -1;  return FALSE;
1286  }  }
1287  #endif  #endif
1288    
# Line 1403  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1409  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1409    {    {
1410    /* Handle specials such as (*SKIP) or (*UTF8) etc. */    /* Handle specials such as (*SKIP) or (*UTF8) etc. */
1411    
1412    if (ptr[1] == CHAR_ASTERISK) ptr += 2;    if (ptr[1] == CHAR_ASTERISK)
1413        {
1414        ptr += 2;
1415        while (ptr < cd->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1416        }
1417    
1418    /* Handle a normal, unnamed capturing parenthesis. */    /* Handle a normal, unnamed capturing parenthesis. */
1419    
# Line 1427  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1437  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1437    
1438    else if (ptr[2] == CHAR_NUMBER_SIGN)    else if (ptr[2] == CHAR_NUMBER_SIGN)
1439      {      {
1440      for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break;      for (ptr += 3; *ptr != CHAR_NULL; ptr++)
1441          if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
1442      goto FAIL_EXIT;      goto FAIL_EXIT;
1443      }      }
1444    
# Line 1440  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1451  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1451      ptr += 2;      ptr += 2;
1452      if (ptr[1] != CHAR_QUESTION_MARK)      if (ptr[1] != CHAR_QUESTION_MARK)
1453        {        {
1454        while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;        while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1455        if (*ptr != 0) ptr++;        if (*ptr != CHAR_NULL) ptr++;
1456        }        }
1457      }      }
1458    
# Line 1484  for (; ptr < cd->end_pattern; ptr++) Line 1495  for (; ptr < cd->end_pattern; ptr++)
1495    
1496    if (*ptr == CHAR_BACKSLASH)    if (*ptr == CHAR_BACKSLASH)
1497      {      {
1498      if (*(++ptr) == 0) goto FAIL_EXIT;      if (*(++ptr) == CHAR_NULL) goto FAIL_EXIT;
1499      if (*ptr == CHAR_Q) for (;;)      if (*ptr == CHAR_Q) for (;;)
1500        {        {
1501        while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};        while (*(++ptr) != CHAR_NULL && *ptr != CHAR_BACKSLASH) {};
1502        if (*ptr == 0) goto FAIL_EXIT;        if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1503        if (*(++ptr) == CHAR_E) break;        if (*(++ptr) == CHAR_E) break;
1504        }        }
1505      continue;      continue;
# Line 1532  for (; ptr < cd->end_pattern; ptr++) Line 1543  for (; ptr < cd->end_pattern; ptr++)
1543    
1544      while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)      while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)
1545        {        {
1546        if (*ptr == 0) return -1;        if (*ptr == CHAR_NULL) return -1;
1547        if (*ptr == CHAR_BACKSLASH)        if (*ptr == CHAR_BACKSLASH)
1548          {          {
1549          if (*(++ptr) == 0) goto FAIL_EXIT;          if (*(++ptr) == CHAR_NULL) goto FAIL_EXIT;
1550          if (*ptr == CHAR_Q) for (;;)          if (*ptr == CHAR_Q) for (;;)
1551            {            {
1552            while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};            while (*(++ptr) != CHAR_NULL && *ptr != CHAR_BACKSLASH) {};
1553            if (*ptr == 0) goto FAIL_EXIT;            if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1554            if (*(++ptr) == CHAR_E) break;            if (*(++ptr) == CHAR_E) break;
1555            }            }
1556          continue;          continue;
# Line 1553  for (; ptr < cd->end_pattern; ptr++) Line 1564  for (; ptr < cd->end_pattern; ptr++)
1564    if (xmode && *ptr == CHAR_NUMBER_SIGN)    if (xmode && *ptr == CHAR_NUMBER_SIGN)
1565      {      {
1566      ptr++;      ptr++;
1567      while (*ptr != 0)      while (*ptr != CHAR_NULL)
1568        {        {
1569        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1570        ptr++;        ptr++;
# Line 1561  for (; ptr < cd->end_pattern; ptr++) Line 1572  for (; ptr < cd->end_pattern; ptr++)
1572        if (utf) FORWARDCHAR(ptr);        if (utf) FORWARDCHAR(ptr);
1573  #endif  #endif
1574        }        }
1575      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1576      continue;      continue;
1577      }      }
1578    
# Line 1571  for (; ptr < cd->end_pattern; ptr++) Line 1582  for (; ptr < cd->end_pattern; ptr++)
1582      {      {
1583      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);
1584      if (rc > 0) return rc;      if (rc > 0) return rc;
1585      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1586      }      }
1587    
1588    else if (*ptr == CHAR_RIGHT_PARENTHESIS)    else if (*ptr == CHAR_RIGHT_PARENTHESIS)
# Line 1636  matching closing parens. That is why we Line 1647  matching closing parens. That is why we
1647  for (;;)  for (;;)
1648    {    {
1649    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);
1650    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == CHAR_NULL) break;
1651    }    }
1652    
1653  return rc;  return rc;
# Line 1852  for (;;) Line 1863  for (;;)
1863      case OP_NOTI:      case OP_NOTI:
1864      branchlength++;      branchlength++;
1865      cc += 2;      cc += 2;
1866  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1867      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1868  #endif  #endif
1869      break;      break;
# Line 1866  for (;;) Line 1877  for (;;)
1877      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1878      branchlength += (int)GET2(cc,1);      branchlength += (int)GET2(cc,1);
1879      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1880  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1881      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1882  #endif  #endif
1883      break;      break;
1884    
1885      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1886      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1887      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)
1888        cc += 2;        cc += 2;
1889      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1890      break;      break;
# Line 1909  for (;;) Line 1920  for (;;)
1920    
1921      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1922    
 #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  
   
1923      case OP_CLASS:      case OP_CLASS:
1924      case OP_NCLASS:      case OP_NCLASS:
1925    #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1926        case OP_XCLASS:
1927        /* The original code caused an unsigned overflow in 64 bit systems,
1928        so now we use a conditional statement. */
1929        if (op == OP_XCLASS)
1930          cc += GET(cc, 1);
1931        else
1932          cc += PRIV(OP_lengths)[OP_CLASS];
1933    #else
1934      cc += PRIV(OP_lengths)[OP_CLASS];      cc += PRIV(OP_lengths)[OP_CLASS];
1935    #endif
1936    
1937      switch (*cc)      switch (*cc)
1938        {        {
# Line 2112  for (;;) Line 2127  for (;;)
2127        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2128        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2129        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2130        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)
2131          code += 2;          code += 2;
2132        break;        break;
2133    
2134        case OP_MARK:        case OP_MARK:
2135        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2136        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2137        case OP_THEN_ARG:        case OP_THEN_ARG:
2138        code += code[1];        code += code[1];
2139        break;        break;
# Line 2232  for (;;) Line 2244  for (;;)
2244        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2245        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2246        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2247        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)
2248          code += 2;          code += 2;
2249        break;        break;
2250    
2251        case OP_MARK:        case OP_MARK:
2252        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2253        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2254        case OP_THEN_ARG:        case OP_THEN_ARG:
2255        code += code[1];        code += code[1];
2256        break;        break;
# Line 2558  for (code = first_significant_code(code Line 2567  for (code = first_significant_code(code
2567      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2568      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2569      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2570      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)
2571        code += 2;        code += 2;
2572      break;      break;
2573    
# Line 2606  for (code = first_significant_code(code Line 2615  for (code = first_significant_code(code
2615      case OP_MARK:      case OP_MARK:
2616      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
2617      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     code += code[1];  
     break;  
   
2618      case OP_THEN_ARG:      case OP_THEN_ARG:
2619      code += code[1];      code += code[1];
2620      break;      break;
# Line 2708  check_posix_syntax(const pcre_uchar *ptr Line 2714  check_posix_syntax(const pcre_uchar *ptr
2714  {  {
2715  pcre_uchar terminator;          /* Don't combine these lines; the Solaris cc */  pcre_uchar terminator;          /* Don't combine these lines; the Solaris cc */
2716  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */
2717  for (++ptr; *ptr != 0; ptr++)  for (++ptr; *ptr != CHAR_NULL; ptr++)
2718    {    {
2719    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2720      ptr++;      ptr++;
# Line 2755  register int yield = 0; Line 2761  register int yield = 0;
2761  while (posix_name_lengths[yield] != 0)  while (posix_name_lengths[yield] != 0)
2762    {    {
2763    if (len == posix_name_lengths[yield] &&    if (len == posix_name_lengths[yield] &&
2764      STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;      STRNCMP_UC_C8(ptr, pn, (unsigned int)len) == 0) return yield;
2765    pn += posix_name_lengths[yield] + 1;    pn += posix_name_lengths[yield] + 1;
2766    yield++;    yield++;
2767    }    }
# Line 2810  while ((ptr = (pcre_uchar *)find_recurse Line 2816  while ((ptr = (pcre_uchar *)find_recurse
2816    
2817    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)
2818      {      {
2819      offset = GET(hc, 0);      offset = (int)GET(hc, 0);
2820      if (cd->start_code + offset == ptr + 1)      if (cd->start_code + offset == ptr + 1)
2821        {        {
2822        PUT(hc, 0, offset + adjust);        PUT(hc, 0, offset + adjust);
# Line 2823  while ((ptr = (pcre_uchar *)find_recurse Line 2829  while ((ptr = (pcre_uchar *)find_recurse
2829    
2830    if (hc >= cd->hwm)    if (hc >= cd->hwm)
2831      {      {
2832      offset = GET(ptr, 1);      offset = (int)GET(ptr, 1);
2833      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);
2834      }      }
2835    
# Line 2893  PUT(previous_callout, 2 + LINK_SIZE, len Line 2899  PUT(previous_callout, 2 + LINK_SIZE, len
2899  /* 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
2900  with UCP support. It searches up the characters, looking for ranges of  with UCP support. It searches up the characters, looking for ranges of
2901  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
2902  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
2903  with a special return value.  with a special return value.
2904    
2905  Arguments:  Arguments:
# Line 2905  Arguments: Line 2911  Arguments:
2911  Yield:        -1 when no more  Yield:        -1 when no more
2912                 0 when a range is returned                 0 when a range is returned
2913                >0 the CASESET offset for char with multiple other cases                >0 the CASESET offset for char with multiple other cases
2914                  in this case, ocptr contains the original                  in this case, ocptr contains the original
2915  */  */
2916    
2917  static int  static int
# Line 2913  get_othercase_range(pcre_uint32 *cptr, p Line 2919  get_othercase_range(pcre_uint32 *cptr, p
2919    pcre_uint32 *odptr)    pcre_uint32 *odptr)
2920  {  {
2921  pcre_uint32 c, othercase, next;  pcre_uint32 c, othercase, next;
2922  int co;  unsigned int co;
2923    
2924  /* 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
2925  cases, return its case offset value. */  cases, return its case offset value. */
2926    
2927  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2928    {    {
2929    if ((co = UCD_CASESET(c)) != 0)    if ((co = UCD_CASESET(c)) != 0)
2930      {      {
2931      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2932      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2933      return co;      return (int)co;
2934      }      }
2935    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2936    }    }
2937    
2938  if (c > d) return -1;  /* Reached end of range */  if (c > d) return -1;  /* Reached end of range */
# Line 2964  Returns:       TRUE if auto-possessifyin Line 2970  Returns:       TRUE if auto-possessifyin
2970  */  */
2971    
2972  static BOOL  static BOOL
2973  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)
2974  {  {
2975  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2976  const pcre_uint32 *p;  const pcre_uint32 *p;
# Line 3009  switch(ptype) Line 3015  switch(ptype)
3015    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
3016            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
3017            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
3018    
3019  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3020    case PT_CLIST:    case PT_CLIST:
3021    p = PRIV(ucd_caseless_sets) + prop->caseset;    p = PRIV(ucd_caseless_sets) + prop->caseset;
3022    for (;;)    for (;;)
3023      {      {
3024      if ((unsigned int)c < *p) return !negated;      if (c < *p) return !negated;
3025      if ((unsigned int)c == *p++) return negated;      if (c == *p++) return negated;
3026      }      }
3027    break;  /* Control never reaches here */    break;  /* Control never reaches here */
3028  #endif  #endif
# Line 3053  check_auto_possessive(const pcre_uchar * Line 3059  check_auto_possessive(const pcre_uchar *
3059  pcre_uint32 c = NOTACHAR;  pcre_uint32 c = NOTACHAR;
3060  pcre_uint32 next;  pcre_uint32 next;
3061  int escape;  int escape;
3062  int op_code = *previous++;  pcre_uchar op_code = *previous++;
3063    
3064  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
3065    
# Line 3065  if ((options & PCRE_EXTENDED) != 0) Line 3071  if ((options & PCRE_EXTENDED) != 0)
3071      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
3072        {        {
3073        ptr++;        ptr++;
3074        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3075          {          {
3076          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
3077          ptr++;          ptr++;
# Line 3084  value is a character, a negative value i Line 3090  value is a character, a negative value i
3090  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3091    {    {
3092    int temperrorcode = 0;    int temperrorcode = 0;
3093    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,
3094        FALSE);
3095    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3096    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3097    }    }
# Line 3108  if ((options & PCRE_EXTENDED) != 0) Line 3115  if ((options & PCRE_EXTENDED) != 0)
3115      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
3116        {        {
3117        ptr++;        ptr++;
3118        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3119          {          {
3120          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
3121          ptr++;          ptr++;
# Line 3129  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3136  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3136    
3137  /* If the previous item is a character, get its value. */  /* If the previous item is a character, get its value. */
3138    
3139  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3140      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
   //if (escape == 0) switch(op_code)  
3141    {    {
3142  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3143    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
# Line 3147  if (escape == 0) Line 3153  if (escape == 0)
3153    {    {
3154    /* 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
3155    case, which maps to the special PT_CLIST property. Check this first. */    case, which maps to the special PT_CLIST property. Check this first. */
3156    
3157  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3158    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3159      {      {
3160      int ocs = UCD_CASESET(next);      unsigned int ocs = UCD_CASESET(next);
3161      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);
3162      }      }
3163  #endif  #endif
# Line 3163  if (escape == 0) Line 3169  if (escape == 0)
3169    
3170      /* 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
3171      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
3172      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,
3173      because multi-other-case characters are dealt with above. */      because multi-other-case characters are dealt with above. */
3174    
3175      case OP_CHARI:      case OP_CHARI:
# Line 3183  if (escape == 0) Line 3189  if (escape == 0)
3189      else      else
3190  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3191      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3192    
3193      case OP_NOT:      case OP_NOT:
3194      return c == next;      return c == next;
3195    
3196      case OP_NOTI:      case OP_NOTI:
3197      if (c == next) return TRUE;      if (c == next) return TRUE;
3198  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3230  if (escape == 0) Line 3236  if (escape == 0)
3236      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3237      switch(next)      switch(next)
3238        {        {
3239        HSPACE_CASES:        HSPACE_CASES:
3240        return op_code == OP_NOT_HSPACE;        return op_code == OP_NOT_HSPACE;
3241    
3242        default:        default:
# Line 3242  if (escape == 0) Line 3248  if (escape == 0)
3248      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
3249      switch(next)      switch(next)
3250        {        {
3251        VSPACE_CASES:        VSPACE_CASES:
3252        return op_code == OP_NOT_VSPACE;        return op_code == OP_NOT_VSPACE;
3253    
3254        default:        default:
# Line 3296  switch(op_code) Line 3302  switch(op_code)
3302      case ESC_H:      case ESC_H:
3303      switch(c)      switch(c)
3304        {        {
3305        HSPACE_CASES:        HSPACE_CASES:
3306        return escape != ESC_h;        return escape != ESC_h;
3307    
3308        default:        default:
3309        return escape == ESC_h;        return escape == ESC_h;
3310        }        }
# Line 3307  switch(op_code) Line 3313  switch(op_code)
3313      case ESC_V:      case ESC_V:
3314      switch(c)      switch(c)
3315        {        {
3316        VSPACE_CASES:        VSPACE_CASES:
3317        return escape != ESC_v;        return escape != ESC_v;
3318    
3319        default:        default:
# Line 3337  switch(op_code) Line 3343  switch(op_code)
3343      case ESC_p:      case ESC_p:
3344      case ESC_P:      case ESC_P:
3345        {        {
3346        int ptype, pdata, errorcodeptr;        unsigned int ptype = 0, pdata = 0;
3347          int errorcodeptr;
3348        BOOL negated;        BOOL negated;
3349    
3350        ptr--;      /* Make ptr point at the p or P */        ptr--;      /* Make ptr point at the p or P */
3351        ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr);        if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcodeptr))
3352        if (ptype < 0) return FALSE;          return FALSE;
3353        ptr++;      /* Point past the final curly ket */        ptr++;      /* Point past the final curly ket */
3354    
3355        /* 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 3418  switch(op_code) Line 3425  switch(op_code)
3425  *************************************************/  *************************************************/
3426    
3427  /* 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
3428  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
3429  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
3430  mutually recursive with the function immediately below.  mutually recursive with the function immediately below.
3431    
3432  Arguments:  Arguments:
3433    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3434    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3435    options       the options word    options       the options word
3436    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3437    start         start of range character    start         start of range character
3438    end           end of range character    end           end of range character
3439    
3440  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3441                  the pointer to extra data is updated                  the pointer to extra data is updated
3442  */  */
# Line 3441  add_to_class(pcre_uint8 *classbits, pcre Line 3448  add_to_class(pcre_uint8 *classbits, pcre
3448  pcre_uint32 c;  pcre_uint32 c;
3449  int n8 = 0;  int n8 = 0;
3450    
3451  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
3452  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
3453  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
3454  range. */  range. */
3455    
3456  if ((options & PCRE_CASELESS) != 0)  if ((options & PCRE_CASELESS) != 0)
3457    {    {
3458  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3459    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3460      {      {
3461      int rc;      int rc;
3462      pcre_uint32 oc, od;      pcre_uint32 oc, od;
3463    
3464      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3465      c = start;      c = start;
3466    
3467      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3468        {        {
3469        /* Handle a single character that has more than one other case. */        /* Handle a single character that has more than one other case. */
3470    
3471        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3472          PRIV(ucd_caseless_sets) + rc, oc);          PRIV(ucd_caseless_sets) + rc, oc);
3473    
3474        /* Do nothing if the other case range is within the original range. */        /* Do nothing if the other case range is within the original range. */
3475    
3476        else if (oc >= start && od <= end) continue;        else if (oc >= start && od <= end) continue;
3477    
3478        /* 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
3479        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
3480        range. Otherwise, use a recursive call to add the additional range. */        range. Otherwise, use a recursive call to add the additional range. */
3481    
3482        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3483        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3484        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
# Line 3481  if ((options & PCRE_CASELESS) != 0) Line 3488  if ((options & PCRE_CASELESS) != 0)
3488  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3489    
3490    /* Not UTF-mode, or no UCP */    /* Not UTF-mode, or no UCP */
3491    
3492    for (c = start; c <= end && c < 256; c++)    for (c = start; c <= end && c < 256; c++)
3493      {      {
3494      SETBIT(classbits, cd->fcc[c]);      SETBIT(classbits, cd->fcc[c]);
3495      n8++;      n8++;
3496      }      }
3497    }    }
3498    
3499  /* 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
3500  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
3501  in all cases. */  in all cases. */
# Line 3514  if (end < 0x100) Line 3521  if (end < 0x100)
3521    {    {
3522    for (c = start; c <= end; c++)    for (c = start; c <= end; c++)
3523      {      {
3524      n8++;      n8++;
3525      SETBIT(classbits, c);      SETBIT(classbits, c);
3526      }      }
3527    }    }
3528    
3529  else  else
3530    {    {
3531    pcre_uchar *uchardata = *uchardptr;    pcre_uchar *uchardata = *uchardptr;
3532    
3533  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3534    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3535      {      {
3536      if (start < end)      if (start < end)
3537        {        {
3538        *uchardata++ = XCL_RANGE;        *uchardata++ = XCL_RANGE;
3539        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3540        uchardata += PRIV(ord2utf)(end, uchardata);        uchardata += PRIV(ord2utf)(end, uchardata);
3541        }        }
3542      else if (start == end)      else if (start == end)
3543        {        {
3544        *uchardata++ = XCL_SINGLE;        *uchardata++ = XCL_SINGLE;
3545        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3546        }        }
3547      }      }
3548    else    else
3549  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3550    
3551    /* Without UTF support, character values are constrained by the bit length,    /* Without UTF support, character values are constrained by the bit length,
3552    and can only be > 256 for 16-bit and 32-bit libraries. */    and can only be > 256 for 16-bit and 32-bit libraries. */
3553    
3554  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3555      {}      {}
3556  #else  #else
3557    if (start < end)    if (start < end)
3558      {      {
3559      *uchardata++ = XCL_RANGE;      *uchardata++ = XCL_RANGE;
# Line 3557  else Line 3564  else
3564      {      {
3565      *uchardata++ = XCL_SINGLE;      *uchardata++ = XCL_SINGLE;
3566      *uchardata++ = start;      *uchardata++ = start;
3567      }      }
3568  #endif  #endif
3569    
3570    *uchardptr = uchardata;   /* Updata extra data pointer */    *uchardptr = uchardata;   /* Updata extra data pointer */
3571    }    }
3572    
3573  return n8;    /* Number of 8-bit characters */  return n8;    /* Number of 8-bit characters */
3574  }  }
3575    
3576    
3577    
3578    
3579  /*************************************************  /*************************************************
3580  *        Add a list of characters to a class     *  *        Add a list of characters to a class     *
3581  *************************************************/  *************************************************/
3582    
3583  /* 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
3584  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
3585  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
3586  handled appropriately. This function is mutually recursive with the function  handled appropriately. This function is mutually recursive with the function
# Line 3583  Arguments: Line 3590  Arguments:
3590    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3591    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3592    options       the options word    options       the options word
3593    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3594    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3595    except        character to omit; this is used when adding lists of    except        character to omit; this is used when adding lists of
3596                    case-equivalent characters to avoid including the one we                    case-equivalent characters to avoid including the one we
3597                    already know about                    already know about
3598    
3599  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3600                  the pointer to extra data is updated                  the pointer to extra data is updated
3601  */  */
# Line 3602  while (p[0] < NOTACHAR) Line 3609  while (p[0] < NOTACHAR)
3609    {    {
3610    int n = 0;    int n = 0;
3611    if (p[0] != except)    if (p[0] != except)
3612      {      {
3613      while(p[n+1] == p[0] + n + 1) n++;      while(p[n+1] == p[0] + n + 1) n++;
3614      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3615      }      }
3616    p += n + 1;    p += n + 1;
3617    }    }
3618  return n8;  return n8;
3619  }  }
3620    
3621    
3622    
# Line 3624  Arguments: Line 3631  Arguments:
3631    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3632    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3633    options       the options word    options       the options word
3634    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3635    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3636    
3637  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3638                  the pointer to extra data is updated                  the pointer to extra data is updated
3639  */  */
3640    
3641  static int  static int
3642  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3643    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3644  {  {
3645  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
# Line 3644  while (p[0] < NOTACHAR) Line 3651  while (p[0] < NOTACHAR)
3651    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3652    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3653      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3654    p++;    p++;
3655    }    }
3656  return n8;  return n8;
3657  }  }
3658    
3659    
3660    
# Line 3666  Arguments: Line 3673  Arguments:
3673    codeptr        points to the pointer to the current code point    codeptr        points to the pointer to the current code point
3674    ptrptr         points to the current pattern pointer    ptrptr         points to the current pattern pointer
3675    errorcodeptr   points to error code variable    errorcodeptr   points to error code variable
3676    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr    place to put the first required character
3677    reqcharptr     set to the last literal character required, else < 0    firstcharflagsptr place to put the first character flags, or a negative number
3678      reqcharptr     place to put the last required character
3679      reqcharflagsptr place to put the last required character flags, or a negative number
3680    bcptr          points to current branch chain    bcptr          points to current branch chain
3681    cond_depth     conditional nesting depth    cond_depth     conditional nesting depth
3682    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
# Line 3680  Returns:         TRUE on success Line 3689  Returns:         TRUE on success
3689    
3690  static BOOL  static BOOL
3691  compile_branch(int *optionsptr, pcre_uchar **codeptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3692    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,    const pcre_uchar **ptrptr, int *errorcodeptr,
3693    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,    pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
3694      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
3695      branch_chain *bcptr, int cond_depth,
3696    compile_data *cd, int *lengthptr)    compile_data *cd, int *lengthptr)
3697  {  {
3698  int repeat_type, op_type;  int repeat_type, op_type;
3699  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3700  int bravalue = 0;  int bravalue = 0;
3701  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3702  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
3703  pcre_int32 zeroreqchar, zerofirstchar;  pcre_int32 firstcharflags, reqcharflags;
3704    pcre_uint32 zeroreqchar, zerofirstchar;
3705    pcre_int32 zeroreqcharflags, zerofirstcharflags;
3706  pcre_int32 req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3707  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3708  int after_manual_callout = 0;  int after_manual_callout = 0;
# Line 3717  dynamically as we process the pattern. * Line 3730  dynamically as we process the pattern. *
3730  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3731  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3732  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3733    #ifndef COMPILE_PCRE32
3734  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3735    #endif
3736  #else  #else
3737  BOOL utf = FALSE;  BOOL utf = FALSE;
3738  #endif  #endif
3739    
3740  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3741  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,
3742  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
3743  alternative calls for the different cases. */  alternative calls for the different cases. */
3744    
3745  pcre_uchar *class_uchardata;  pcre_uchar *class_uchardata;
# Line 3752  to take the zero repeat into account. Th Line 3767  to take the zero repeat into account. Th
3767  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3768  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3769    
3770  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = 0;
3771    firstcharflags = reqcharflags = zerofirstcharflags = zeroreqcharflags = REQ_UNSET;
3772    
3773  /* The variable req_caseopt contains either the REQ_CASELESS value  /* The variable req_caseopt contains either the REQ_CASELESS value
3774  or zero, according to the current setting of the caseless flag. The  or zero, according to the current setting of the caseless flag. The
# Line 3778  for (;; ptr++) Line 3794  for (;; ptr++)
3794    int recno;    int recno;
3795    int refsign;    int refsign;
3796    int skipbytes;    int skipbytes;
3797    int subreqchar;    pcre_uint32 subreqchar, subfirstchar;
3798    int subfirstchar;    pcre_int32 subreqcharflags, subfirstcharflags;
3799    int terminator;    int terminator;
3800    int mclength;    unsigned int mclength;
3801    int tempbracount;    unsigned int tempbracount;
3802    int ec; // FIXMEchpe pcre_uint32    pcre_uint32 ec;
3803    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3804    
3805    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 3793  for (;; ptr++) Line 3809  for (;; ptr++)
3809    /* If we are at the end of a nested substitution, revert to the outer level    /* If we are at the end of a nested substitution, revert to the outer level
3810    string. Nesting only happens one level deep. */    string. Nesting only happens one level deep. */
3811    
3812    if (c == 0 && nestptr != NULL)    if (c == CHAR_NULL && nestptr != NULL)
3813      {      {
3814      ptr = nestptr;      ptr = nestptr;
3815      nestptr = NULL;      nestptr = NULL;
# Line 3868  for (;; ptr++) Line 3884  for (;; ptr++)
3884    
3885    /* If in \Q...\E, check for the end; if not, we have a literal */    /* If in \Q...\E, check for the end; if not, we have a literal */
3886    
3887    if (inescq && c != 0)    if (inescq && c != CHAR_NULL)
3888      {      {
3889      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)
3890        {        {
# Line 3916  for (;; ptr++) Line 3932  for (;; ptr++)
3932      if (c == CHAR_NUMBER_SIGN)      if (c == CHAR_NUMBER_SIGN)
3933        {        {
3934        ptr++;        ptr++;
3935        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3936          {          {
3937          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3938          ptr++;          ptr++;
# Line 3924  for (;; ptr++) Line 3940  for (;; ptr++)
3940          if (utf) FORWARDCHAR(ptr);          if (utf) FORWARDCHAR(ptr);
3941  #endif  #endif
3942          }          }
3943        if (*ptr != 0) continue;        if (*ptr != CHAR_NULL) continue;
3944    
3945        /* Else fall through to handle end of string */        /* Else fall through to handle end of string */
3946        c = 0;        c = 0;
# Line 3946  for (;; ptr++) Line 3962  for (;; ptr++)
3962      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3963      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3964      *firstcharptr = firstchar;      *firstcharptr = firstchar;
3965        *firstcharflagsptr = firstcharflags;
3966      *reqcharptr = reqchar;      *reqcharptr = reqchar;
3967        *reqcharflagsptr = reqcharflags;
3968      *codeptr = code;      *codeptr = code;
3969      *ptrptr = ptr;      *ptrptr = ptr;
3970      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3970  for (;; ptr++) Line 3988  for (;; ptr++)
3988      previous = NULL;      previous = NULL;
3989      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3990        {        {
3991        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
3992        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3993        }        }
3994      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3985  for (;; ptr++) Line 4003  for (;; ptr++)
4003      repeats. The value of reqchar doesn't change either. */      repeats. The value of reqchar doesn't change either. */
4004    
4005      case CHAR_DOT:      case CHAR_DOT:
4006      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4007      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4008        zerofirstcharflags = firstcharflags;
4009      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4010        zeroreqcharflags = reqcharflags;
4011      previous = code;      previous = code;
4012      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
4013      break;      break;
# Line 4061  for (;; ptr++) Line 4081  for (;; ptr++)
4081          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
4082        {        {
4083        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
4084        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4085        zerofirstchar = firstchar;        zerofirstchar = firstchar;
4086          zerofirstcharflags = firstcharflags;
4087        break;        break;
4088        }        }
4089    
# Line 4097  for (;; ptr++) Line 4118  for (;; ptr++)
4118      means that an initial ] is taken as a data character. At the start of the      means that an initial ] is taken as a data character. At the start of the
4119      loop, c contains the first byte of the character. */      loop, c contains the first byte of the character. */
4120    
4121      if (c != 0) do      if (c != CHAR_NULL) do
4122        {        {
4123        const pcre_uchar *oldptr;        const pcre_uchar *oldptr;
4124    
4125  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4126        if (utf && HAS_EXTRALEN(c))        if (utf && HAS_EXTRALEN(c))
4127          {                           /* Braces are required because the */          {                           /* Braces are required because the */
4128          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
# Line 4112  for (;; ptr++) Line 4133  for (;; ptr++)
4133        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
4134        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
4135        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
4136        (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,
4137        however. */        however. */
4138    
4139        if (lengthptr != NULL && class_uchardata > class_uchardata_base)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
# Line 4176  for (;; ptr++) Line 4197  for (;; ptr++)
4197          alpha. This relies on the fact that the class table starts with          alpha. This relies on the fact that the class table starts with
4198          alpha, lower, upper as the first 3 entries. */          alpha, lower, upper as the first 3 entries. */
4199    
4200          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)
4201            posix_class = 0;            posix_class = 0;
4202    
4203          /* 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 4253  for (;; ptr++) Line 4274  for (;; ptr++)
4274    
4275        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4276          {          {
4277          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,
4278              TRUE);
4279          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4280            if (escape == 0) c = ec;
         if (escape == 0)  
           c = ec;  
4281          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 */
4282          else if (escape == ESC_N)            /* \N is not supported in a class */          else if (escape == ESC_N)          /* \N is not supported in a class */
4283            {            {
4284            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4285            goto FAILED;            goto FAILED;
# Line 4332  for (;; ptr++) Line 4351  for (;; ptr++)
4351              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4352              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4353              continue;              continue;
4354    
4355              /* The rest apply in both UCP and non-UCP cases. */              /* The rest apply in both UCP and non-UCP cases. */
4356    
4357              case ESC_h:              case ESC_h:
4358              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4359                PRIV(hspace_list), NOTACHAR);                PRIV(hspace_list), NOTACHAR);
4360              continue;              continue;
4361    
4362              case ESC_H:              case ESC_H:
4363              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4364                cd, PRIV(hspace_list));                cd, PRIV(hspace_list));
4365              continue;              continue;
4366    
4367              case ESC_v:              case ESC_v:
4368              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4369                PRIV(vspace_list), NOTACHAR);                PRIV(vspace_list), NOTACHAR);
4370              continue;              continue;
4371    
4372              case ESC_V:              case ESC_V:
4373              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4374                cd, PRIV(vspace_list));                cd, PRIV(vspace_list));
4375              continue;              continue;
4376    
4377  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4360  for (;; ptr++) Line 4379  for (;; ptr++)
4379              case ESC_P:              case ESC_P:
4380                {                {
4381                BOOL negated;                BOOL negated;
4382                int pdata;                unsigned int ptype = 0, pdata = 0;
4383                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
4384                if (ptype < 0) goto FAILED;                  goto FAILED;
4385                *class_uchardata++ = ((escape == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4386                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4387                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
# Line 4390  for (;; ptr++) Line 4409  for (;; ptr++)
4409    
4410          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4411          This may be greater than 256. */          This may be greater than 256. */
4412    
4413          escape = 0;          escape = 0;
4414    
4415          }   /* End of backslash handling */          }   /* End of backslash handling */
# Line 4416  for (;; ptr++) Line 4435  for (;; ptr++)
4435    
4436        if (!inescq && ptr[1] == CHAR_MINUS)        if (!inescq && ptr[1] == CHAR_MINUS)
4437          {          {
4438          int d;          pcre_uint32 d;
4439          ptr += 2;          ptr += 2;
4440          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;
4441    
# Line 4431  for (;; ptr++) Line 4450  for (;; ptr++)
4450            inescq = TRUE;            inescq = TRUE;
4451            break;            break;
4452            }            }
4453    
4454          /* 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
4455          back the pointer and jump to handle the character that preceded it. */          back the pointer and jump to handle the character that preceded it. */
4456    
4457          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))          if (*ptr == CHAR_NULL || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))
4458            {            {
4459            ptr = oldptr;            ptr = oldptr;
4460            goto CLASS_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4461            }            }
4462    
4463          /* Otherwise, we have a potential range; pick up the next character */          /* Otherwise, we have a potential range; pick up the next character */
4464    
4465  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 4487  for (;; ptr++) Line 4506  for (;; ptr++)
4506          /* We have found a character range, so single character optimizations          /* We have found a character range, so single character optimizations
4507          cannot be done anymore. Any value greater than 1 indicates that there          cannot be done anymore. Any value greater than 1 indicates that there
4508          is more than one character. */          is more than one character. */
4509    
4510          class_one_char = 2;          class_one_char = 2;
4511    
4512          /* 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. */
4513    
4514          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4515    
4516          class_has_8bitchar +=          class_has_8bitchar +=
4517            add_to_class(classbits, &class_uchardata, options, cd, c, d);            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4518    
4519          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4520          }          }
4521    
4522        /* 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
4523        char, or after \ that introduces a single character or for an apparent        char, or after \ that introduces a single character or for an apparent
4524        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
4525        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
4526        with a zillion characters in it. */        with a zillion characters in it. */
4527    
4528        CLASS_SINGLE_CHARACTER:        CLASS_SINGLE_CHARACTER:
# Line 4522  for (;; ptr++) Line 4541  for (;; ptr++)
4541          {          {
4542          ptr++;          ptr++;
4543          zeroreqchar = reqchar;          zeroreqchar = reqchar;
4544            zeroreqcharflags = reqcharflags;
4545    
4546          if (negate_class)          if (negate_class)
4547            {            {
4548  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
             // FIXMEchpe pcreuint32?  
4549            int d;            int d;
4550  #endif  #endif
4551            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4552            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4553              zerofirstcharflags = firstcharflags;
4554    
4555            /* For caseless UTF-8 mode when UCP support is available, check            /* For caseless UTF-8 mode when UCP support is available, check
4556            whether this character has more than one other case. If so, generate            whether this character has more than one other case. If so, generate
4557            a special OP_NOTPROP item instead of OP_NOTI. */            a special OP_NOTPROP item instead of OP_NOTI. */
4558    
4559  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4560            if (utf && (options & PCRE_CASELESS) != 0 &&            if (utf && (options & PCRE_CASELESS) != 0 &&
4561                (d = UCD_CASESET(c)) != 0)                (d = UCD_CASESET(c)) != 0)
4562              {              {
4563              *code++ = OP_NOTPROP;              *code++ = OP_NOTPROP;
4564              *code++ = PT_CLIST;              *code++ = PT_CLIST;
4565              *code++ = d;              *code++ = d;
4566              }              }
4567            else            else
4568  #endif  #endif
4569            /* Char has only one other case, or UCP not available */            /* Char has only one other case, or UCP not available */
4570    
# Line 4557  for (;; ptr++) Line 4577  for (;; ptr++)
4577  #endif  #endif
4578                *code++ = c;                *code++ = c;
4579              }              }
4580    
4581            /* We are finished with this character class */            /* We are finished with this character class */
4582    
4583            goto END_CLASS;            goto END_CLASS;
4584            }            }
4585    
# Line 4577  for (;; ptr++) Line 4597  for (;; ptr++)
4597            }            }
4598          goto ONE_CHAR;          goto ONE_CHAR;
4599          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4600    
4601        /* 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
4602        has been generated. Add this character to the class. */        has been generated. Add this character to the class. */
4603    
4604        class_has_8bitchar +=        class_has_8bitchar +=
4605          add_to_class(classbits, &class_uchardata, options, cd, c, c);          add_to_class(classbits, &class_uchardata, options, cd, c, c);
4606        }        }
4607    
# Line 4589  for (;; ptr++) Line 4609  for (;; ptr++)
4609      If we are at the end of an internal nested string, revert to the outer      If we are at the end of an internal nested string, revert to the outer
4610      string. */      string. */
4611    
4612      while (((c = *(++ptr)) != 0 ||      while (((c = *(++ptr)) != CHAR_NULL ||
4613             (nestptr != NULL &&             (nestptr != NULL &&
4614               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != 0)) &&               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != CHAR_NULL)) &&
4615             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));
4616    
4617      /* Check for missing terminating ']' */      /* Check for missing terminating ']' */
4618    
4619      if (c == 0)      if (c == CHAR_NULL)
4620        {        {
4621        *errorcodeptr = ERR6;        *errorcodeptr = ERR6;
4622        goto FAILED;        goto FAILED;
4623        }        }
4624    
4625      /* 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
4626      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
4627      phase, class_uchardata gets emptied to prevent workspace overflow, so it      phase, class_uchardata gets emptied to prevent workspace overflow, so it
4628      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
4629      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
4630      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
4631      instead of just doing a test on class_uchardata below. */      instead of just doing a test on class_uchardata below. */
4632    
4633  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4634      if (class_uchardata > class_uchardata_base) xclass = TRUE;      if (class_uchardata > class_uchardata_base) xclass = TRUE;
4635  #endif  #endif
# Line 4618  for (;; ptr++) Line 4638  for (;; ptr++)
4638      setting, whatever the repeat count. Any reqchar setting must remain      setting, whatever the repeat count. Any reqchar setting must remain
4639      unchanged after any kind of repeat. */      unchanged after any kind of repeat. */
4640    
4641      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4642      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4643        zerofirstcharflags = firstcharflags;
4644      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4645        zeroreqcharflags = reqcharflags;
4646    
4647      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4648      extended class, with its own opcode, unless there was a negated special      extended class, with its own opcode, unless there was a negated special
# Line 4676  for (;; ptr++) Line 4698  for (;; ptr++)
4698        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4699        }        }
4700      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4701    
4702      END_CLASS:      END_CLASS:
4703      break;      break;
4704    
# Line 4715  for (;; ptr++) Line 4737  for (;; ptr++)
4737      if (repeat_min == 0)      if (repeat_min == 0)
4738        {        {
4739        firstchar = zerofirstchar;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4740          firstcharflags = zerofirstcharflags;
4741        reqchar = zeroreqchar;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4742          reqcharflags = zeroreqcharflags;
4743        }        }
4744    
4745      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4818  for (;; ptr++) Line 4842  for (;; ptr++)
4842          {          {
4843          c = code[-1];          c = code[-1];
4844          if (*previous <= OP_CHARI && repeat_min > 1)          if (*previous <= OP_CHARI && repeat_min > 1)
4845            reqchar = c | req_caseopt | cd->req_varyopt;            {
4846              reqchar = c;
4847              reqcharflags = req_caseopt | cd->req_varyopt;
4848              }
4849          }          }
4850    
4851        /* If the repetition is unlimited, it pays to see if the next thing on        /* If the repetition is unlimited, it pays to see if the next thing on
# Line 4875  for (;; ptr++) Line 4902  for (;; ptr++)
4902    
4903        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
4904    
       /*--------------------------------------------------------------------*/  
       /* 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; */  
       /*--------------------------------------------------------------------*/  
   
4905        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
4906    
4907        repeat_type += op_type;        repeat_type += op_type;
# Line 5031  for (;; ptr++) Line 5048  for (;; ptr++)
5048          goto END_REPEAT;          goto END_REPEAT;
5049          }          }
5050    
       /*--------------------------------------------------------------------*/  
       /* 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; */  
       /*--------------------------------------------------------------------*/  
   
5051        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
5052          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
5053        else if (repeat_min == 1 && repeat_max == -1)        else if (repeat_min == 1 && repeat_max == -1)
# Line 5200  for (;; ptr++) Line 5207  for (;; ptr++)
5207    
5208            else            else
5209              {              {
5210              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;              if (groupsetfirstchar && reqcharflags < 0)
5211                  {
5212                  reqchar = firstchar;
5213                  reqcharflags = firstcharflags;
5214                  }
5215    
5216              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5217                {                {
# Line 5479  for (;; ptr++) Line 5490  for (;; ptr++)
5490        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5491          {          {
5492          tempcode += PRIV(OP_lengths)[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5493  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
5494          if (utf && HAS_EXTRALEN(tempcode[-1]))          if (utf && HAS_EXTRALEN(tempcode[-1]))
5495            tempcode += GET_EXTRALEN(tempcode[-1]);            tempcode += GET_EXTRALEN(tempcode[-1]);
5496  #endif  #endif
# Line 5575  for (;; ptr++) Line 5586  for (;; ptr++)
5586        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
5587          {          {
5588          arg = ++ptr;          arg = ++ptr;
5589          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5590          arglen = (int)(ptr - arg);          arglen = (int)(ptr - arg);
5591          if ((unsigned int)arglen > MAX_MARK)          if ((unsigned int)arglen > MAX_MARK)
5592            {            {
# Line 5620  for (;; ptr++) Line 5631  for (;; ptr++)
5631                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5632    
5633              /* Do not set firstchar after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5634              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;              if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
5635              }              }
5636    
5637            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5689  for (;; ptr++) Line 5700  for (;; ptr++)
5700          {          {
5701          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */
5702          ptr++;          ptr++;
5703          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5704          if (*ptr == 0)          if (*ptr == CHAR_NULL)
5705            {            {
5706            *errorcodeptr = ERR18;            *errorcodeptr = ERR18;
5707            goto FAILED;            goto FAILED;
# Line 5713  for (;; ptr++) Line 5724  for (;; ptr++)
5724          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5725          case CHAR_LEFT_PARENTHESIS:          case CHAR_LEFT_PARENTHESIS:
5726          bravalue = OP_COND;       /* Conditional group */          bravalue = OP_COND;       /* Conditional group */
5727            tempptr = ptr;
5728    
5729          /* A condition can be an assertion, a number (referring to a numbered          /* A condition can be an assertion, a number (referring to a numbered
5730          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 5725  for (;; ptr++) Line 5737  for (;; ptr++)
5737          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
5738          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.
5739          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
5740          cases. */          cases.
5741    
5742            For compatibility with auto-callouts, we allow a callout to be
5743            specified before a condition that is an assertion. First, check for the
5744            syntax of a callout; if found, adjust the temporary pointer that is
5745            used to check for an assertion condition. That's all that is needed! */
5746    
5747            if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)
5748              {
5749              for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
5750              if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
5751                tempptr += i + 1;
5752              }
5753    
5754          /* For conditions that are assertions, check the syntax, and then exit          /* For conditions that are assertions, check the syntax, and then exit
5755          the switch. This will take control down to where bracketed groups,          the switch. This will take control down to where bracketed groups,
5756          including assertions, are processed. */          including assertions, are processed. */
5757    
5758          if (ptr[1] == CHAR_QUESTION_MARK && (ptr[2] == CHAR_EQUALS_SIGN ||          if (tempptr[1] == CHAR_QUESTION_MARK &&
5759              ptr[2] == CHAR_EXCLAMATION_MARK || ptr[2] == CHAR_LESS_THAN_SIGN))                (tempptr[2] == CHAR_EQUALS_SIGN ||
5760                   tempptr[2] == CHAR_EXCLAMATION_MARK ||
5761                   tempptr[2] == CHAR_LESS_THAN_SIGN))
5762            break;            break;
5763    
5764          /* 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 5766  for (;; ptr++) Line 5792  for (;; ptr++)
5792            }            }
5793          else          else
5794            {            {
5795            terminator = 0;            terminator = CHAR_NULL;
5796            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);
5797            }            }
5798    
# Line 5786  for (;; ptr++) Line 5812  for (;; ptr++)
5812          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)
5813            {            {
5814            if (recno >= 0)            if (recno >= 0)
5815              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;              recno = (IS_DIGIT(*ptr))? recno * 10 + (int)(*ptr - CHAR_0) : -1;
5816            ptr++;            ptr++;
5817            }            }
5818          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
5819    
5820          if ((terminator > 0 && *ptr++ != terminator) ||          if ((terminator > 0 && *ptr++ != (pcre_uchar)terminator) ||
5821              *ptr++ != CHAR_RIGHT_PARENTHESIS)              *ptr++ != CHAR_RIGHT_PARENTHESIS)
5822            {            {
5823            ptr--;      /* Error offset */            ptr--;      /* Error offset */
# Line 5856  for (;; ptr++) Line 5882  for (;; ptr++)
5882            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
5883            }            }
5884    
5885          /* If terminator == 0 it means that the name followed directly after          /* If terminator == CHAR_NULL it means that the name followed directly
5886          the opening parenthesis [e.g. (?(abc)...] and in this case there are          after the opening parenthesis [e.g. (?(abc)...] and in this case there
5887          some further alternatives to try. For the cases where terminator != 0          are some further alternatives to try. For the cases where terminator !=
5888          [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have          0 [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have
5889          now checked all the possibilities, so give an error. */          now checked all the possibilities, so give an error. */
5890    
5891          else if (terminator != 0)          else if (terminator != CHAR_NULL)
5892            {            {
5893            *errorcodeptr = ERR15;            *errorcodeptr = ERR15;
5894            goto FAILED;            goto FAILED;
# Line 6031  for (;; ptr++) Line 6057  for (;; ptr++)
6057    
6058            if (lengthptr != NULL)            if (lengthptr != NULL)
6059              {              {
6060              if (*ptr != terminator)              if (*ptr != (pcre_uchar)terminator)
6061                {                {
6062                *errorcodeptr = ERR42;                *errorcodeptr = ERR42;
6063                goto FAILED;                goto FAILED;
# Line 6173  for (;; ptr++) Line 6199  for (;; ptr++)
6199              *errorcodeptr = ERR62;              *errorcodeptr = ERR62;
6200              goto FAILED;              goto FAILED;
6201              }              }
6202            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6203              {              {
6204              *errorcodeptr = ERR42;              *errorcodeptr = ERR42;
6205              goto FAILED;              goto FAILED;
# Line 6279  for (;; ptr++) Line 6305  for (;; ptr++)
6305            while(IS_DIGIT(*ptr))            while(IS_DIGIT(*ptr))
6306              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6307    
6308            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6309              {              {
6310              *errorcodeptr = ERR29;              *errorcodeptr = ERR29;
6311              goto FAILED;              goto FAILED;
# Line 6383  for (;; ptr++) Line 6409  for (;; ptr++)
6409    
6410          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6411    
6412          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6413          continue;          continue;
6414    
6415    
# Line 6517  for (;; ptr++) Line 6543  for (;; ptr++)
6543           cond_depth +           cond_depth +
6544             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6545           &subfirstchar,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6546             &subfirstcharflags,
6547           &subreqchar,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6548             &subreqcharflags,
6549           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6550           cd,                              /* Tables block */           cd,                              /* Tables block */
6551           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 6578  for (;; ptr++) Line 6606  for (;; ptr++)
6606            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6607            goto FAILED;            goto FAILED;
6608            }            }
6609          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;          if (condcount == 1) subfirstcharflags = subreqcharflags = REQ_NONE;
6610          }          }
6611        }        }
6612    
# Line 6627  for (;; ptr++) Line 6655  for (;; ptr++)
6655      back off. */      back off. */
6656    
6657      zeroreqchar = reqchar;      zeroreqchar = reqchar;
6658        zeroreqcharflags = reqcharflags;
6659      zerofirstchar = firstchar;      zerofirstchar = firstchar;
6660        zerofirstcharflags = firstcharflags;
6661      groupsetfirstchar = FALSE;      groupsetfirstchar = FALSE;
6662    
6663      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
# Line 6638  for (;; ptr++) Line 6668  for (;; ptr++)
6668        no firstchar, set "none" for the whole branch. In both cases, a zero        no firstchar, set "none" for the whole branch. In both cases, a zero
6669        repeat forces firstchar to "none". */        repeat forces firstchar to "none". */
6670    
6671        if (firstchar == REQ_UNSET)        if (firstcharflags == REQ_UNSET)
6672          {          {
6673          if (subfirstchar >= 0)          if (subfirstcharflags >= 0)
6674            {            {
6675            firstchar = subfirstchar;            firstchar = subfirstchar;
6676              firstcharflags = subfirstcharflags;
6677            groupsetfirstchar = TRUE;            groupsetfirstchar = TRUE;
6678            }            }
6679          else firstchar = REQ_NONE;          else firstcharflags = REQ_NONE;
6680          zerofirstchar = REQ_NONE;          zerofirstcharflags = REQ_NONE;
6681          }          }
6682    
6683        /* If firstchar was previously set, convert the subpattern's firstchar        /* If firstchar was previously set, convert the subpattern's firstchar
6684        into reqchar if there wasn't one, using the vary flag that was in        into reqchar if there wasn't one, using the vary flag that was in
6685        existence beforehand. */        existence beforehand. */
6686    
6687        else if (subfirstchar >= 0 && subreqchar < 0)        else if (subfirstcharflags >= 0 && subreqcharflags < 0)
6688          subreqchar = subfirstchar | tempreqvary;          {
6689            subreqchar = subfirstchar;
6690            subreqcharflags = subfirstcharflags | tempreqvary;
6691            }
6692    
6693        /* 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
6694        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6695    
6696        if (subreqchar >= 0) reqchar = subreqchar;        if (subreqcharflags >= 0)
6697            {
6698            reqchar = subreqchar;
6699            reqcharflags = subreqcharflags;
6700            }
6701        }        }
6702    
6703      /* For a forward assertion, we take the reqchar, if set. This can be      /* For a forward assertion, we take the reqchar, if set. This can be
# Line 6670  for (;; ptr++) Line 6708  for (;; ptr++)
6708      of a firstchar. This is overcome by a scan at the end if there's no      of a firstchar. This is overcome by a scan at the end if there's no
6709      firstchar, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6710    
6711      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;      else if (bravalue == OP_ASSERT && subreqcharflags >= 0)
6712          {
6713          reqchar = subreqchar;
6714          reqcharflags = subreqcharflags;
6715          }
6716      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6717    
6718    
# Line 6686  for (;; ptr++) Line 6728  for (;; ptr++)
6728      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6729      tempptr = ptr;      tempptr = ptr;
6730      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
   
6731      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6732    
6733      if (escape == 0)      if (escape == 0)                  /* The escape coded a single character */
6734        c = ec;        c = ec;
6735      else      else
6736        {        {
# Line 6706  for (;; ptr++) Line 6747  for (;; ptr++)
6747        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6748        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6749    
6750        if (firstchar == REQ_UNSET && escape > ESC_b && escape < ESC_Z)        if (firstcharflags == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6751          firstchar = REQ_NONE;          firstcharflags = REQ_NONE;
6752    
6753        /* Set values to reset to if this is followed by a zero repeat. */        /* Set values to reset to if this is followed by a zero repeat. */
6754    
6755        zerofirstchar = firstchar;        zerofirstchar = firstchar;
6756          zerofirstcharflags = firstcharflags;
6757        zeroreqchar = reqchar;        zeroreqchar = reqchar;
6758          zeroreqcharflags = reqcharflags;
6759    
6760        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
6761        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
# Line 6741  for (;; ptr++) Line 6784  for (;; ptr++)
6784          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)
6785            {            {
6786            BOOL is_a_number = TRUE;            BOOL is_a_number = TRUE;
6787            for (p = ptr + 1; *p != 0 && *p != terminator; p++)            for (p = ptr + 1; *p != CHAR_NULL && *p != (pcre_uchar)terminator; p++)
6788              {              {
6789              if (!MAX_255(*p)) { is_a_number = FALSE; break; }              if (!MAX_255(*p)) { is_a_number = FALSE; break; }
6790              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;
6791              if ((cd->ctypes[*p] & ctype_word) == 0) break;              if ((cd->ctypes[*p] & ctype_word) == 0) break;
6792              }              }
6793            if (*p != terminator)            if (*p != (pcre_uchar)terminator)
6794              {              {
6795              *errorcodeptr = ERR57;              *errorcodeptr = ERR57;
6796              break;              break;
# Line 6765  for (;; ptr++) Line 6808  for (;; ptr++)
6808    
6809          p = ptr + 2;          p = ptr + 2;
6810          while (IS_DIGIT(*p)) p++;          while (IS_DIGIT(*p)) p++;
6811          if (*p != terminator)          if (*p != (pcre_uchar)terminator)
6812            {            {
6813            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
6814            break;            break;
# Line 6802  for (;; ptr++) Line 6845  for (;; ptr++)
6845          recno = -escape;          recno = -escape;
6846    
6847          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6848          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6849          previous = code;          previous = code;
6850          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6851          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6829  for (;; ptr++) Line 6872  for (;; ptr++)
6872        else if (escape == ESC_P || escape == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6873          {          {
6874          BOOL negated;          BOOL negated;
6875          int pdata;          unsigned int ptype = 0, pdata = 0;
6876          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
6877          if (ptype < 0) goto FAILED;            goto FAILED;
6878          previous = code;          previous = code;
6879          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6880          *code++ = ptype;          *code++ = ptype;
# Line 6853  for (;; ptr++) Line 6896  for (;; ptr++)
6896        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
6897        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
6898        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6899        lookbehind. */        lookbehind, and \A also behaves as if it does. */
6900    
6901        else        else
6902          {          {
6903          if ((escape == ESC_b || escape == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&
6904                 cd->max_lookbehind == 0)
6905            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6906  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6907          if (escape >= ESC_DU && escape <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
# Line 6905  for (;; ptr++) Line 6949  for (;; ptr++)
6949      mclength = 1;      mclength = 1;
6950      mcbuffer[0] = c;      mcbuffer[0] = c;
6951    
6952  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
6953      if (utf && HAS_EXTRALEN(c))      if (utf && HAS_EXTRALEN(c))
6954        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));
6955  #endif  #endif
# Line 6915  for (;; ptr++) Line 6959  for (;; ptr++)
6959    
6960      ONE_CHAR:      ONE_CHAR:
6961      previous = code;      previous = code;
6962    
6963      /* For caseless UTF-8 mode when UCP support is available, check whether      /* For caseless UTF-8 mode when UCP support is available, check whether
6964      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
6965      OP_PROP item instead of OP_CHARI. */      OP_PROP item instead of OP_CHARI. */
6966    
6967  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6968      if (utf && (options & PCRE_CASELESS) != 0)      if (utf && (options & PCRE_CASELESS) != 0)
6969        {        {
# Line 6929  for (;; ptr++) Line 6973  for (;; ptr++)
6973          *code++ = OP_PROP;          *code++ = OP_PROP;
6974          *code++ = PT_CLIST;          *code++ = PT_CLIST;
6975          *code++ = c;          *code++ = c;
6976          if (firstchar == REQ_UNSET) firstchar = zerofirstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;
6977          break;          break;
6978          }          }
6979        }        }
6980  #endif  #endif
6981    
6982      /* Caseful matches, or not one of the multicase characters. */      /* Caseful matches, or not one of the multicase characters. */
6983    
6984      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6985      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6986    
# Line 6950  for (;; ptr++) Line 6994  for (;; ptr++)
6994      Otherwise, leave the firstchar value alone, and don't change it on a zero      Otherwise, leave the firstchar value alone, and don't change it on a zero
6995      repeat. */      repeat. */
6996    
6997      if (firstchar == REQ_UNSET)      if (firstcharflags == REQ_UNSET)
6998        {        {
6999        zerofirstchar = REQ_NONE;        zerofirstcharflags = REQ_NONE;
7000        zeroreqchar = reqchar;        zeroreqchar = reqchar;
7001          zeroreqcharflags = reqcharflags;
7002    
7003        /* If the character is more than one byte long, we can set firstchar        /* If the character is more than one byte long, we can set firstchar
7004        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
# Line 6961  for (;; ptr++) Line 7006  for (;; ptr++)
7006        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
7007          {          {
7008          firstchar = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
7009          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;          firstchar = mcbuffer[0];
7010            firstcharflags = req_caseopt;
7011    
7012            if (mclength != 1)
7013              {
7014              reqchar = code[-1];
7015              reqcharflags = cd->req_varyopt;
7016              }
7017          }          }
7018        else firstchar = reqchar = REQ_NONE;        else firstcharflags = reqcharflags = REQ_NONE;
7019        }        }
7020    
7021      /* firstchar was previously set; we can set reqchar only if the length is      /* firstchar was previously set; we can set reqchar only if the length is
# Line 6972  for (;; ptr++) Line 7024  for (;; ptr++)
7024      else      else
7025        {        {
7026        zerofirstchar = firstchar;        zerofirstchar = firstchar;
7027          zerofirstcharflags = firstcharflags;
7028        zeroreqchar = reqchar;        zeroreqchar = reqchar;
7029          zeroreqcharflags = reqcharflags;
7030        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
7031          reqchar = code[-1] | req_caseopt | cd->req_varyopt;          {
7032            reqchar = code[-1];
7033            reqcharflags = req_caseopt | cd->req_varyopt;
7034            }
7035        }        }
7036    
7037      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6993  return FALSE; Line 7050  return FALSE;
7050    
7051    
7052    
   
7053  /*************************************************  /*************************************************
7054  *     Compile sequence of alternatives           *  *     Compile sequence of alternatives           *
7055  *************************************************/  *************************************************/
# Line 7014  Arguments: Line 7070  Arguments:
7070    reset_bracount TRUE to reset the count for each branch    reset_bracount TRUE to reset the count for each branch
7071    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes      skip this many bytes at start (for brackets and OP_COND)
7072    cond_depth     depth of nesting for conditional subpatterns    cond_depth     depth of nesting for conditional subpatterns
7073    firstcharptr   place to put the first required character, or a negative number    firstcharptr    place to put the first required character
7074    reqcharptr     place to put the last required character, or a negative number    firstcharflagsptr place to put the first character flags, or a negative number
7075      reqcharptr     place to put the last required character
7076      reqcharflagsptr place to put the last required character flags, or a negative number
7077    bcptr          pointer to the chain of currently open branches    bcptr          pointer to the chain of currently open branches
7078    cd             points to the data block with tables pointers etc.    cd             points to the data block with tables pointers etc.
7079    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
# Line 7027  Returns:         TRUE on success Line 7085  Returns:         TRUE on success
7085  static BOOL  static BOOL
7086  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
7087    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
7088    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,    int cond_depth,
7089      pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
7090      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
7091    branch_chain *bcptr, compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
7092  {  {
7093  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
# Line 7037  pcre_uchar *start_bracket = code; Line 7097  pcre_uchar *start_bracket = code;
7097  pcre_uchar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
7098  open_capitem capitem;  open_capitem capitem;
7099  int capnumber = 0;  int capnumber = 0;
7100  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
7101  pcre_int32 branchfirstchar, branchreqchar;  pcre_int32 firstcharflags, reqcharflags;
7102    pcre_uint32 branchfirstchar, branchreqchar;
7103    pcre_int32 branchfirstcharflags, branchreqcharflags;
7104  int length;  int length;
7105  int orig_bracount;  unsigned int orig_bracount;
7106  int max_bracount;  unsigned int max_bracount;
7107  branch_chain bc;  branch_chain bc;
7108    
7109  bc.outer = bcptr;  bc.outer = bcptr;
7110  bc.current_branch = code;  bc.current_branch = code;
7111    
7112  firstchar = reqchar = REQ_UNSET;  firstchar = reqchar = 0;
7113    firstcharflags = reqcharflags = REQ_UNSET;
7114    
7115  /* Accumulate the length for use in the pre-compile phase. Start with the  /* Accumulate the length for use in the pre-compile phase. Start with the
7116  length of the BRA and KET and any extra bytes that are required at the  length of the BRA and KET and any extra bytes that are required at the
# Line 7107  for (;;) Line 7170  for (;;)
7170    into the length. */    into the length. */
7171    
7172    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
7173          &branchreqchar, &bc, cond_depth, cd,          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,
7174          (lengthptr == NULL)? NULL : &length))          cond_depth, cd, (lengthptr == NULL)? NULL : &length))
7175      {      {
7176      *ptrptr = ptr;      *ptrptr = ptr;
7177      return FALSE;      return FALSE;
# Line 7129  for (;;) Line 7192  for (;;)
7192      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
7193        {        {
7194        firstchar = branchfirstchar;        firstchar = branchfirstchar;
7195          firstcharflags = branchfirstcharflags;
7196        reqchar = branchreqchar;        reqchar = branchreqchar;
7197          reqcharflags = branchreqcharflags;
7198        }        }
7199    
7200      /* If this is not the first branch, the first char and reqchar have to      /* If this is not the first branch, the first char and reqchar have to
# Line 7143  for (;;) Line 7208  for (;;)
7208        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
7209        previously no reqchar, it takes on the value of the old firstchar. */        previously no reqchar, it takes on the value of the old firstchar. */
7210    
7211        if (firstchar >= 0 && firstchar != branchfirstchar)        if (firstcharflags >= 0 &&
7212              (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))
7213          {          {
7214          if (reqchar < 0) reqchar = firstchar;          if (reqcharflags < 0)
7215          firstchar = REQ_NONE;            {
7216              reqchar = firstchar;
7217              reqcharflags = firstcharflags;
7218              }
7219            firstcharflags = REQ_NONE;
7220          }          }
7221    
7222        /* If we (now or from before) have no firstchar, a firstchar from the        /* If we (now or from before) have no firstchar, a firstchar from the
7223        branch becomes a reqchar if there isn't a branch reqchar. */        branch becomes a reqchar if there isn't a branch reqchar. */
7224    
7225        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)        if (firstcharflags < 0 && branchfirstcharflags >= 0 && branchreqcharflags < 0)
7226            branchreqchar = branchfirstchar;          {
7227            branchreqchar = branchfirstchar;
7228            branchreqcharflags = branchfirstcharflags;
7229            }
7230    
7231        /* Now ensure that the reqchars match */        /* Now ensure that the reqchars match */
7232    
7233        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))        if (((reqcharflags & ~REQ_VARY) != (branchreqcharflags & ~REQ_VARY)) ||
7234          reqchar = REQ_NONE;            reqchar != branchreqchar)
7235        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */          reqcharflags = REQ_NONE;
7236          else
7237            {
7238            reqchar = branchreqchar;
7239            reqcharflags |= branchreqcharflags; /* To "or" REQ_VARY */
7240            }
7241        }        }
7242    
7243      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
# Line 7255  for (;;) Line 7333  for (;;)
7333      *codeptr = code;      *codeptr = code;
7334      *ptrptr = ptr;      *ptrptr = ptr;
7335      *firstcharptr = firstchar;      *firstcharptr = firstchar;
7336        *firstcharflagsptr = firstcharflags;
7337      *reqcharptr = reqchar;      *reqcharptr = reqchar;
7338        *reqcharflagsptr = reqcharflags;
7339      if (lengthptr != NULL)      if (lengthptr != NULL)
7340        {        {
7341        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 7490  do { Line 7570  do {
7570       {       {
7571       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7572       }       }
7573    
7574     /* Atomic brackets */     /* Atomic brackets */
7575    
7576     else if (op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
# Line 7542  we return that char, otherwise -1. Line 7622  we return that char, otherwise -1.
7622    
7623  Arguments:  Arguments:
7624    code       points to start of expression (the bracket)    code       points to start of expression (the bracket)
7625      flags       points to the first char flags, or to REQ_NONE
7626    inassert   TRUE if in an assertion    inassert   TRUE if in an assertion
7627    
7628  Returns:     -1 or the fixed first char  Returns:     the fixed first char, or 0 with REQ_NONE in flags
7629  */  */
7630    
7631  static int  static pcre_uint32
7632  find_firstassertedchar(const pcre_uchar *code, BOOL inassert)  find_firstassertedchar(const pcre_uchar *code, pcre_int32 *flags,
7633      BOOL inassert)
7634  {  {
7635  register int c = -1;  register pcre_uint32 c = 0;
7636    int cflags = REQ_NONE;
7637    
7638    *flags = REQ_NONE;
7639  do {  do {
7640     int d;     pcre_uint32 d;
7641       int dflags;
7642     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||
7643               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;
7644     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,
7645       TRUE);       TRUE);
7646     register int op = *scode;     register pcre_uchar op = *scode;
7647    
7648     switch(op)     switch(op)
7649       {       {
7650       default:       default:
7651       return -1;       return 0;
7652    
7653       case OP_BRA:       case OP_BRA:
7654       case OP_BRAPOS:       case OP_BRAPOS:
# Line 7574  do { Line 7660  do {
7660       case OP_ONCE:       case OP_ONCE:
7661       case OP_ONCE_NC:       case OP_ONCE_NC:
7662       case OP_COND:       case OP_COND:
7663       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       d = find_firstassertedchar(scode, &dflags, op == OP_ASSERT);
7664         return -1;       if (dflags < 0)
7665       if (c < 0) c = d; else if (c != d) return -1;         return 0;
7666         if (cflags < 0) { c = d; cflags = dflags; } else if (c != d || cflags != dflags) return 0;
7667       break;       break;
7668    
7669       case OP_EXACT:       case OP_EXACT:
# Line 7587  do { Line 7674  do {
7674       case OP_PLUS:       case OP_PLUS:
7675       case OP_MINPLUS:       case OP_MINPLUS:
7676       case OP_POSPLUS:       case OP_POSPLUS:
7677       if (!inassert) return -1;       if (!inassert) return 0;
7678       if (c < 0) c = scode[1];       if (cflags < 0) { c = scode[1]; cflags = 0; }
7679         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7680       break;       break;
7681    
7682       case OP_EXACTI:       case OP_EXACTI:
# Line 7600  do { Line 7687  do {
7687       case OP_PLUSI:       case OP_PLUSI:
7688       case OP_MINPLUSI:       case OP_MINPLUSI:
7689       case OP_POSPLUSI:       case OP_POSPLUSI:
7690       if (!inassert) return -1;       if (!inassert) return 0;
7691       if (c < 0) c = scode[1] | REQ_CASELESS;       if (cflags < 0) { c = scode[1]; cflags = REQ_CASELESS; }
7692         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7693       break;       break;
7694       }       }
7695    
7696     code += GET(code, 1);     code += GET(code, 1);
7697     }     }
7698  while (*code == OP_ALT);  while (*code == OP_ALT);
7699    
7700    *flags = cflags;
7701  return c;  return c;
7702  }  }
7703    
# Line 7676  pcre32_compile2(PCRE_SPTR32 pattern, int Line 7765  pcre32_compile2(PCRE_SPTR32 pattern, int
7765  {  {
7766  REAL_PCRE *re;  REAL_PCRE *re;
7767  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7768  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
7769    pcre_int32 firstcharflags, reqcharflags;
7770  int newline;  int newline;
7771  int errorcode = 0;  int errorcode = 0;
7772  int skipatstart = 0;  int skipatstart = 0;
# Line 7749  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7839  while (ptr[skipatstart] == CHAR_LEFT_PAR
7839    int newnl = 0;    int newnl = 0;
7840    int newbsr = 0;    int newbsr = 0;
7841    
7842    /* For completeness and backward compatibility, (*UTFn) is supported in the
7843    relevant libraries, but (*UTF) is generic and always supported. Note that
7844    PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */
7845    
7846  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
7847    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
7848      { skipatstart += 7; options |= PCRE_UTF8; continue; }      { skipatstart += 7; options |= PCRE_UTF8; continue; }
7849  #endif  #endif
7850  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
7851    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF16_RIGHTPAR, 6) == 0)
7852      { skipatstart += 8; options |= PCRE_UTF16; continue; }      { skipatstart += 8; options |= PCRE_UTF16; continue; }
7853  #endif  #endif
7854  #ifdef COMPILE_PCRE32  #ifdef COMPILE_PCRE32
7855    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF32_RIGHTPAR, 6) == 0)
7856      { skipatstart += 8; options |= PCRE_UTF32; continue; }      { skipatstart += 8; options |= PCRE_UTF32; continue; }
7857  #endif  #endif
7858    
7859      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)
7860        { skipatstart += 6; options |= PCRE_UTF8; continue; }
7861    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)
7862      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7863    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)
# Line 7926  ptr += skipatstart; Line 8023  ptr += skipatstart;
8023  code = cworkspace;  code = cworkspace;
8024  *code = OP_BRA;  *code = OP_BRA;
8025  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,
8026    FALSE, 0, 0, &firstchar, &reqchar, NULL, cd, &length);    FALSE, 0, 0, &firstchar, &firstcharflags, &reqchar, &reqcharflags, NULL,
8027      cd, &length);
8028  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
8029    
8030  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,
# Line 8004  ptr = (const pcre_uchar *)pattern + skip Line 8102  ptr = (const pcre_uchar *)pattern + skip
8102  code = (pcre_uchar *)codestart;  code = (pcre_uchar *)codestart;
8103  *code = OP_BRA;  *code = OP_BRA;
8104  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,
8105    &firstchar, &reqchar, NULL, cd, NULL);    &firstchar, &firstcharflags, &reqchar, &reqcharflags, NULL, cd, NULL);
8106  re->top_bracket = cd->bracount;  re->top_bracket = cd->bracount;
8107  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
8108  re->max_lookbehind = cd->max_lookbehind;  re->max_lookbehind = cd->max_lookbehind;
8109  re->flags = cd->external_flags | PCRE_MODE;  re->flags = cd->external_flags | PCRE_MODE;
8110    
8111  if (cd->had_accept) reqchar = REQ_NONE;   /* Must disable after (*ACCEPT) */  if (cd->had_accept)
8112      {
8113      reqchar = 0;              /* Must disable after (*ACCEPT) */
8114      reqcharflags = REQ_NONE;
8115      }
8116    
8117  /* If not reached end of pattern on success, there's an excess bracket. */  /* If not reached end of pattern on success, there's an excess bracket. */
8118    
8119  if (errorcode == 0 && *ptr != 0) errorcode = ERR22;  if (errorcode == 0 && *ptr != CHAR_NULL) errorcode = ERR22;
8120    
8121  /* Fill in the terminating state and check for disastrous overflow, but  /* Fill in the terminating state and check for disastrous overflow, but
8122  if debugging, leave the test till after things are printed out. */  if debugging, leave the test till after things are printed out. */
# Line 8025  if debugging, leave the test till after Line 8127  if debugging, leave the test till after
8127  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
8128  #endif  #endif
8129    
8130    #ifdef SUPPORT_VALGRIND
8131    /* If the estimated length exceeds the really used length, mark the extra
8132    allocated memory as unadressable, so that any out-of-bound reads can be
8133    detected. */
8134    VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
8135    #endif
8136    
8137  /* Fill in any forward references that are required. There may be repeated  /* Fill in any forward references that are required. There may be repeated
8138  references; optimize for them, as searching a large regex takes time. */  references; optimize for them, as searching a large regex takes time. */
8139    
# Line 8060  if (errorcode == 0 && re->top_backref > Line 8169  if (errorcode == 0 && re->top_backref >
8169    
8170  /* If there were any lookbehind assertions that contained OP_RECURSE  /* If there were any lookbehind assertions that contained OP_RECURSE
8171  (recursions or subroutine calls), a flag is set for them to be checked here,  (recursions or subroutine calls), a flag is set for them to be checked here,
8172  because they may contain forward references. Actual recursions can't be fixed  because they may contain forward references. Actual recursions cannot be fixed
8173  length, but subroutine calls can. It is done like this so that those without  length, but subroutine calls can. It is done like this so that those without
8174  OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The  OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The
8175  exceptional ones forgo this. We scan the pattern to check that they are fixed  exceptional ones forgo this. We scan the pattern to check that they are fixed
# Line 8131  if ((re->options & PCRE_ANCHORED) == 0) Line 8240  if ((re->options & PCRE_ANCHORED) == 0)
8240    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;
8241    else    else
8242      {      {
8243      if (firstchar < 0)      if (firstcharflags < 0)
8244        firstchar = find_firstassertedchar(codestart, FALSE);        firstchar = find_firstassertedchar(codestart, &firstcharflags, FALSE);
8245      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */      if (firstcharflags >= 0)   /* Remove caseless flag for non-caseable chars */
8246        {        {
8247  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
8248        re->first_char = firstchar & 0xff;        re->first_char = firstchar & 0xff;
8249  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
8250        re->first_char = firstchar & 0xffff;        re->first_char = firstchar & 0xffff;
8251  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
8252        re->first_char = firstchar & ~REQ_MASK;        re->first_char = firstchar;
8253  #endif  #endif
8254        if ((firstchar & REQ_CASELESS) != 0)        if ((firstcharflags & REQ_CASELESS) != 0)
8255          {          {
8256  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
8257          /* We ignore non-ASCII first chars in 8 bit mode. */          /* We ignore non-ASCII first chars in 8 bit mode. */
# Line 8174  if ((re->options & PCRE_ANCHORED) == 0) Line 8283  if ((re->options & PCRE_ANCHORED) == 0)
8283  variable length item in the regex. Remove the caseless flag for non-caseable  variable length item in the regex. Remove the caseless flag for non-caseable
8284  bytes. */  bytes. */
8285    
8286  if (reqchar >= 0 &&  if (reqcharflags >= 0 &&
8287       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))       ((re->options & PCRE_ANCHORED) == 0 || (reqcharflags & REQ_VARY) != 0))
8288    {    {
8289  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
8290    re->req_char = reqchar & 0xff;    re->req_char = reqchar & 0xff;
8291  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
8292    re->req_char = reqchar & 0xffff;    re->req_char = reqchar & 0xffff;
8293  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
8294    re->req_char = reqchar & ~REQ_MASK;    re->req_char = reqchar;
8295  #endif  #endif
8296    if ((reqchar & REQ_CASELESS) != 0)    if ((reqcharflags & REQ_CASELESS) != 0)
8297      {      {
8298  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
8299      /* We ignore non-ASCII first chars in 8 bit mode. */      /* We ignore non-ASCII first chars in 8 bit mode. */

Legend:
Removed from v.1072  
changed lines
  Added in v.1305

  ViewVC Help
Powered by ViewVC 1.1.5