/[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 1067 by chpe, Tue Oct 16 15:54:22 2012 UTC revision 1309 by ph10, Fri Apr 5 15:35:59 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 80  to check them every time. */ Line 80  to check them every time. */
80  /* Definitions to allow mutual recursion */  /* Definitions to allow mutual recursion */
81    
82  static int  static int
83    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84      const pcre_uint32 *, unsigned int);      const pcre_uint32 *, unsigned int);
85    
86  static BOOL  static BOOL
87    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL,    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 505  static const char error_texts[] = Line 508  static const char error_texts[] =
508    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
509    "character value in \\u.... sequence is too large\0"    "character value in \\u.... sequence is too large\0"
510    "invalid UTF-32 string\0"    "invalid UTF-32 string\0"
511      "setting UTF is disabled by the application\0"
512    ;    ;
513    
514  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 645  static const pcre_uint8 ebcdic_chartab[] Line 649  static const pcre_uint8 ebcdic_chartab[]
649    
650    
651    
   
652  /*************************************************  /*************************************************
653  *            Find an error text                  *  *            Find an error text                  *
654  *************************************************/  *************************************************/
# Line 665  find_error_text(int n) Line 668  find_error_text(int n)
668  const char *s = error_texts;  const char *s = error_texts;
669  for (; n > 0; n--)  for (; n > 0; n--)
670    {    {
671    while (*s++ != 0) {};    while (*s++ != CHAR_NULL) {};
672    if (*s == 0) return "Error text not found (please report)";    if (*s == CHAR_NULL) return "Error text not found (please report)";
673    }    }
674  return s;  return s;
675  }  }
# Line 771  Returns:         zero => a data characte Line 774  Returns:         zero => a data characte
774  */  */
775    
776  static int  static int
777  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
778    int bracount, int options, BOOL isclass)    int bracount, int options, BOOL isclass)
779  {  {
780  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
# Line 786  ptr--;                            /* Set Line 789  ptr--;                            /* Set
789    
790  /* 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. */
791    
792  if (c == 0) *errorcodeptr = ERR1;  if (c == CHAR_NULL) *errorcodeptr = ERR1;
793    
794  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup
795  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 798  Otherwise further processing may be requ
798  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
799  /* Not alphanumeric */  /* Not alphanumeric */
800  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
801  else if ((i = escapes[c - CHAR_0]) != 0) { if (i > 0) c = (pcre_uint32)i; else escape = -i; }  else if ((i = escapes[c - CHAR_0]) != 0)
802      { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
803    
804  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
805  /* Not alphanumeric */  /* Not alphanumeric */
# Line 845  else Line 849  else
849            }            }
850    
851  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
852          if (c > (utf ? 0x10ffff : 0xff))          if (c > (utf ? 0x10ffffU : 0xffU))
853  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
854          if (c > (utf ? 0x10ffff : 0xffff))          if (c > (utf ? 0x10ffffU : 0xffffU))
855  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
856          if (utf && c > 0x10ffff)          if (utf && c > 0x10ffffU)
857  #endif  #endif
858            {            {
859            *errorcodeptr = ERR76;            *errorcodeptr = ERR76;
# Line 896  else Line 900  else
900      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
901        {        {
902        const pcre_uchar *p;        const pcre_uchar *p;
903        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++)
904          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
905        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != CHAR_NULL && *p != CHAR_RIGHT_CURLY_BRACKET)
906          {          {
907          escape = ESC_k;          escape = ESC_k;
908          break;          break;
# Line 1083  else Line 1087  else
1087  #endif  #endif
1088    
1089  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
1090          if (c > (utf ? 0x10ffff : 0xff)) { overflow = TRUE; break; }          if (c > (utf ? 0x10ffffU : 0xffU)) { overflow = TRUE; break; }
1091  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
1092          if (c > (utf ? 0x10ffff : 0xffff)) { overflow = TRUE; break; }          if (c > (utf ? 0x10ffffU : 0xffffU)) { overflow = TRUE; break; }
1093  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
1094          if (utf && c > 0x10ffff) { overflow = TRUE; break; }          if (utf && c > 0x10ffffU) { overflow = TRUE; break; }
1095  #endif  #endif
1096          }          }
1097    
# Line 1132  else Line 1136  else
1136    
1137      case CHAR_c:      case CHAR_c:
1138      c = *(++ptr);      c = *(++ptr);
1139      if (c == 0)      if (c == CHAR_NULL)
1140        {        {
1141        *errorcodeptr = ERR2;        *errorcodeptr = ERR2;
1142        break;        break;
# Line 1201  escape sequence. Line 1205  escape sequence.
1205  Argument:  Argument:
1206    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
1207    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
1208    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
1209      pdataptr       points to an unsigned int that is set to the detailed property value
1210    errorcodeptr   points to the error code variable    errorcodeptr   points to the error code variable
1211    
1212  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
1213  */  */
1214    
1215  static int  static BOOL
1216  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1217      unsigned int *pdataptr, int *errorcodeptr)
1218  {  {
1219  pcre_uchar c;  pcre_uchar c;
1220  int i, bot, top;  int i, bot, top;
# Line 1216  const pcre_uchar *ptr = *ptrptr; Line 1222  const pcre_uchar *ptr = *ptrptr;
1222  pcre_uchar name[32];  pcre_uchar name[32];
1223    
1224  c = *(++ptr);  c = *(++ptr);
1225  if (c == 0) goto ERROR_RETURN;  if (c == CHAR_NULL) goto ERROR_RETURN;
1226    
1227  *negptr = FALSE;  *negptr = FALSE;
1228    
# Line 1233  if (c == CHAR_LEFT_CURLY_BRACKET) Line 1239  if (c == CHAR_LEFT_CURLY_BRACKET)
1239    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)
1240      {      {
1241      c = *(++ptr);      c = *(++ptr);
1242      if (c == 0) goto ERROR_RETURN;      if (c == CHAR_NULL) goto ERROR_RETURN;
1243      if (c == CHAR_RIGHT_CURLY_BRACKET) break;      if (c == CHAR_RIGHT_CURLY_BRACKET) break;
1244      name[i] = c;      name[i] = c;
1245      }      }
# Line 1263  while (bot < top) Line 1269  while (bot < top)
1269    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);
1270    if (r == 0)    if (r == 0)
1271      {      {
1272      *dptr = PRIV(utt)[i].value;      *ptypeptr = PRIV(utt)[i].type;
1273      return PRIV(utt)[i].type;      *pdataptr = PRIV(utt)[i].value;
1274        return TRUE;
1275      }      }
1276    if (r > 0) bot = i + 1; else top = i;    if (r > 0) bot = i + 1; else top = i;
1277    }    }
1278    
1279  *errorcodeptr = ERR47;  *errorcodeptr = ERR47;
1280  *ptrptr = ptr;  *ptrptr = ptr;
1281  return -1;  return FALSE;
1282    
1283  ERROR_RETURN:  ERROR_RETURN:
1284  *errorcodeptr = ERR46;  *errorcodeptr = ERR46;
1285  *ptrptr = ptr;  *ptrptr = ptr;
1286  return -1;  return FALSE;
1287  }  }
1288  #endif  #endif
1289    
# Line 1403  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1410  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1410    {    {
1411    /* Handle specials such as (*SKIP) or (*UTF8) etc. */    /* Handle specials such as (*SKIP) or (*UTF8) etc. */
1412    
1413    if (ptr[1] == CHAR_ASTERISK) ptr += 2;    if (ptr[1] == CHAR_ASTERISK)
1414        {
1415        ptr += 2;
1416        while (ptr < cd->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1417        }
1418    
1419    /* Handle a normal, unnamed capturing parenthesis. */    /* Handle a normal, unnamed capturing parenthesis. */
1420    
# Line 1427  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1438  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1438    
1439    else if (ptr[2] == CHAR_NUMBER_SIGN)    else if (ptr[2] == CHAR_NUMBER_SIGN)
1440      {      {
1441      for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break;      for (ptr += 3; *ptr != CHAR_NULL; ptr++)
1442          if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
1443      goto FAIL_EXIT;      goto FAIL_EXIT;
1444      }      }
1445    
# Line 1440  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1452  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1452      ptr += 2;      ptr += 2;
1453      if (ptr[1] != CHAR_QUESTION_MARK)      if (ptr[1] != CHAR_QUESTION_MARK)
1454        {        {
1455        while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;        while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1456        if (*ptr != 0) ptr++;        if (*ptr != CHAR_NULL) ptr++;
1457        }        }
1458      }      }
1459    
# Line 1484  for (; ptr < cd->end_pattern; ptr++) Line 1496  for (; ptr < cd->end_pattern; ptr++)
1496    
1497    if (*ptr == CHAR_BACKSLASH)    if (*ptr == CHAR_BACKSLASH)
1498      {      {
1499      if (*(++ptr) == 0) goto FAIL_EXIT;      if (*(++ptr) == CHAR_NULL) goto FAIL_EXIT;
1500      if (*ptr == CHAR_Q) for (;;)      if (*ptr == CHAR_Q) for (;;)
1501        {        {
1502        while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};        while (*(++ptr) != CHAR_NULL && *ptr != CHAR_BACKSLASH) {};
1503        if (*ptr == 0) goto FAIL_EXIT;        if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1504        if (*(++ptr) == CHAR_E) break;        if (*(++ptr) == CHAR_E) break;
1505        }        }
1506      continue;      continue;
# Line 1532  for (; ptr < cd->end_pattern; ptr++) Line 1544  for (; ptr < cd->end_pattern; ptr++)
1544    
1545      while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)      while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)
1546        {        {
1547        if (*ptr == 0) return -1;        if (*ptr == CHAR_NULL) return -1;
1548        if (*ptr == CHAR_BACKSLASH)        if (*ptr == CHAR_BACKSLASH)
1549          {          {
1550          if (*(++ptr) == 0) goto FAIL_EXIT;          if (*(++ptr) == CHAR_NULL) goto FAIL_EXIT;
1551          if (*ptr == CHAR_Q) for (;;)          if (*ptr == CHAR_Q) for (;;)
1552            {            {
1553            while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};            while (*(++ptr) != CHAR_NULL && *ptr != CHAR_BACKSLASH) {};
1554            if (*ptr == 0) goto FAIL_EXIT;            if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1555            if (*(++ptr) == CHAR_E) break;            if (*(++ptr) == CHAR_E) break;
1556            }            }
1557          continue;          continue;
# Line 1553  for (; ptr < cd->end_pattern; ptr++) Line 1565  for (; ptr < cd->end_pattern; ptr++)
1565    if (xmode && *ptr == CHAR_NUMBER_SIGN)    if (xmode && *ptr == CHAR_NUMBER_SIGN)
1566      {      {
1567      ptr++;      ptr++;
1568      while (*ptr != 0)      while (*ptr != CHAR_NULL)
1569        {        {
1570        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1571        ptr++;        ptr++;
# Line 1561  for (; ptr < cd->end_pattern; ptr++) Line 1573  for (; ptr < cd->end_pattern; ptr++)
1573        if (utf) FORWARDCHAR(ptr);        if (utf) FORWARDCHAR(ptr);
1574  #endif  #endif
1575        }        }
1576      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1577      continue;      continue;
1578      }      }
1579    
# Line 1571  for (; ptr < cd->end_pattern; ptr++) Line 1583  for (; ptr < cd->end_pattern; ptr++)
1583      {      {
1584      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);
1585      if (rc > 0) return rc;      if (rc > 0) return rc;
1586      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1587      }      }
1588    
1589    else if (*ptr == CHAR_RIGHT_PARENTHESIS)    else if (*ptr == CHAR_RIGHT_PARENTHESIS)
# Line 1636  matching closing parens. That is why we Line 1648  matching closing parens. That is why we
1648  for (;;)  for (;;)
1649    {    {
1650    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);
1651    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == CHAR_NULL) break;
1652    }    }
1653    
1654  return rc;  return rc;
# Line 1744  for (;;) Line 1756  for (;;)
1756    {    {
1757    int d;    int d;
1758    pcre_uchar *ce, *cs;    pcre_uchar *ce, *cs;
1759    register int op = *cc;    register pcre_uchar op = *cc;
1760    
1761    switch (op)    switch (op)
1762      {      {
# Line 1852  for (;;) Line 1864  for (;;)
1864      case OP_NOTI:      case OP_NOTI:
1865      branchlength++;      branchlength++;
1866      cc += 2;      cc += 2;
1867  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1868      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1869  #endif  #endif
1870      break;      break;
# Line 1864  for (;;) Line 1876  for (;;)
1876      case OP_EXACTI:      case OP_EXACTI:
1877      case OP_NOTEXACT:      case OP_NOTEXACT:
1878      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1879      branchlength += GET2(cc,1);      branchlength += (int)GET2(cc,1);
1880      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1881  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
1882      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1883  #endif  #endif
1884      break;      break;
1885    
1886      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1887      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1888      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)
1889        cc += 2;        cc += 2;
1890      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1891      break;      break;
# Line 1909  for (;;) Line 1921  for (;;)
1921    
1922      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1923    
 #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  
   
1924      case OP_CLASS:      case OP_CLASS:
1925      case OP_NCLASS:      case OP_NCLASS:
1926    #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1927        case OP_XCLASS:
1928        /* The original code caused an unsigned overflow in 64 bit systems,
1929        so now we use a conditional statement. */
1930        if (op == OP_XCLASS)
1931          cc += GET(cc, 1);
1932        else
1933          cc += PRIV(OP_lengths)[OP_CLASS];
1934    #else
1935      cc += PRIV(OP_lengths)[OP_CLASS];      cc += PRIV(OP_lengths)[OP_CLASS];
1936    #endif
1937    
1938      switch (*cc)      switch (*cc)
1939        {        {
# Line 1932  for (;;) Line 1948  for (;;)
1948        case OP_CRRANGE:        case OP_CRRANGE:
1949        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1950        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1951        branchlength += GET2(cc,1);        branchlength += (int)GET2(cc,1);
1952        cc += 1 + 2 * IMM2_SIZE;        cc += 1 + 2 * IMM2_SIZE;
1953        break;        break;
1954    
# Line 2059  PRIV(find_bracket)(const pcre_uchar *cod Line 2075  PRIV(find_bracket)(const pcre_uchar *cod
2075  {  {
2076  for (;;)  for (;;)
2077    {    {
2078    register int c = *code;    register pcre_uchar c = *code;
2079    
2080    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
2081    
# Line 2082  for (;;) Line 2098  for (;;)
2098    else if (c == OP_CBRA || c == OP_SCBRA ||    else if (c == OP_CBRA || c == OP_SCBRA ||
2099             c == OP_CBRAPOS || c == OP_SCBRAPOS)             c == OP_CBRAPOS || c == OP_SCBRAPOS)
2100      {      {
2101      int n = GET2(code, 1+LINK_SIZE);      int n = (int)GET2(code, 1+LINK_SIZE);
2102      if (n == number) return (pcre_uchar *)code;      if (n == number) return (pcre_uchar *)code;
2103      code += PRIV(OP_lengths)[c];      code += PRIV(OP_lengths)[c];
2104      }      }
# Line 2112  for (;;) Line 2128  for (;;)
2128        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2129        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2130        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2131        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2132          code += 2;          code += 2;
2133        break;        break;
2134    
2135        case OP_MARK:        case OP_MARK:
2136        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2137        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2138        case OP_THEN_ARG:        case OP_THEN_ARG:
2139        code += code[1];        code += code[1];
2140        break;        break;
# Line 2197  find_recurse(const pcre_uchar *code, BOO Line 2210  find_recurse(const pcre_uchar *code, BOO
2210  {  {
2211  for (;;)  for (;;)
2212    {    {
2213    register int c = *code;    register pcre_uchar c = *code;
2214    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
2215    if (c == OP_RECURSE) return code;    if (c == OP_RECURSE) return code;
2216    
# Line 2232  for (;;) Line 2245  for (;;)
2245        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2246        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2247        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2248        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2249          code += 2;          code += 2;
2250        break;        break;
2251    
2252        case OP_MARK:        case OP_MARK:
2253        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2254        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2255        case OP_THEN_ARG:        case OP_THEN_ARG:
2256        code += code[1];        code += code[1];
2257        break;        break;
# Line 2351  static BOOL Line 2361  static BOOL
2361  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2362    BOOL utf, compile_data *cd)    BOOL utf, compile_data *cd)
2363  {  {
2364  register int c;  register pcre_uchar c;
2365  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
2366       code < endcode;       code < endcode;
2367       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))
# Line 2385  for (code = first_significant_code(code Line 2395  for (code = first_significant_code(code
2395      /* Test for forward reference */      /* Test for forward reference */
2396    
2397      for (scode = cd->start_workspace; scode < cd->hwm; scode += LINK_SIZE)      for (scode = cd->start_workspace; scode < cd->hwm; scode += LINK_SIZE)
2398        if (GET(scode, 0) == code + 1 - cd->start_code) return TRUE;        if ((int)GET(scode, 0) == (int)(code + 1 - cd->start_code)) return TRUE;
2399    
2400      /* Not a forward reference, test for completed backward reference */      /* Not a forward reference, test for completed backward reference */
2401    
# Line 2558  for (code = first_significant_code(code Line 2568  for (code = first_significant_code(code
2568      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2569      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2570      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2571      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2572        code += 2;        code += 2;
2573      break;      break;
2574    
# Line 2606  for (code = first_significant_code(code Line 2616  for (code = first_significant_code(code
2616      case OP_MARK:      case OP_MARK:
2617      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
2618      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     code += code[1];  
     break;  
   
2619      case OP_THEN_ARG:      case OP_THEN_ARG:
2620      code += code[1];      code += code[1];
2621      break;      break;
# Line 2706  Returns:   TRUE or FALSE Line 2713  Returns:   TRUE or FALSE
2713  static BOOL  static BOOL
2714  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)
2715  {  {
2716  int terminator;          /* Don't combine these lines; the Solaris cc */  pcre_uchar terminator;          /* Don't combine these lines; the Solaris cc */
2717  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */
2718  for (++ptr; *ptr != 0; ptr++)  for (++ptr; *ptr != CHAR_NULL; ptr++)
2719    {    {
2720    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2721      ptr++;      ptr++;
# Line 2755  register int yield = 0; Line 2762  register int yield = 0;
2762  while (posix_name_lengths[yield] != 0)  while (posix_name_lengths[yield] != 0)
2763    {    {
2764    if (len == posix_name_lengths[yield] &&    if (len == posix_name_lengths[yield] &&
2765      STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;      STRNCMP_UC_C8(ptr, pn, (unsigned int)len) == 0) return yield;
2766    pn += posix_name_lengths[yield] + 1;    pn += posix_name_lengths[yield] + 1;
2767    yield++;    yield++;
2768    }    }
# Line 2810  while ((ptr = (pcre_uchar *)find_recurse Line 2817  while ((ptr = (pcre_uchar *)find_recurse
2817    
2818    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)
2819      {      {
2820      offset = GET(hc, 0);      offset = (int)GET(hc, 0);
2821      if (cd->start_code + offset == ptr + 1)      if (cd->start_code + offset == ptr + 1)
2822        {        {
2823        PUT(hc, 0, offset + adjust);        PUT(hc, 0, offset + adjust);
# Line 2823  while ((ptr = (pcre_uchar *)find_recurse Line 2830  while ((ptr = (pcre_uchar *)find_recurse
2830    
2831    if (hc >= cd->hwm)    if (hc >= cd->hwm)
2832      {      {
2833      offset = GET(ptr, 1);      offset = (int)GET(ptr, 1);
2834      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);
2835      }      }
2836    
# Line 2893  PUT(previous_callout, 2 + LINK_SIZE, len Line 2900  PUT(previous_callout, 2 + LINK_SIZE, len
2900  /* This function is passed the start and end of a class range, in UTF-8 mode  /* This function is passed the start and end of a class range, in UTF-8 mode
2901  with UCP support. It searches up the characters, looking for ranges of  with UCP support. It searches up the characters, looking for ranges of
2902  characters in the "other" case. Each call returns the next one, updating the  characters in the "other" case. Each call returns the next one, updating the
2903  start address. A character with multiple other cases is returned on its own  start address. A character with multiple other cases is returned on its own
2904  with a special return value.  with a special return value.
2905    
2906  Arguments:  Arguments:
# Line 2905  Arguments: Line 2912  Arguments:
2912  Yield:        -1 when no more  Yield:        -1 when no more
2913                 0 when a range is returned                 0 when a range is returned
2914                >0 the CASESET offset for char with multiple other cases                >0 the CASESET offset for char with multiple other cases
2915                  in this case, ocptr contains the original                  in this case, ocptr contains the original
2916  */  */
2917    
2918  static int  static int
# Line 2913  get_othercase_range(pcre_uint32 *cptr, p Line 2920  get_othercase_range(pcre_uint32 *cptr, p
2920    pcre_uint32 *odptr)    pcre_uint32 *odptr)
2921  {  {
2922  pcre_uint32 c, othercase, next;  pcre_uint32 c, othercase, next;
2923  int co;  unsigned int co;
2924    
2925  /* Find the first character that has an other case. If it has multiple other  /* Find the first character that has an other case. If it has multiple other
2926  cases, return its case offset value. */  cases, return its case offset value. */
2927    
2928  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2929    {    {
2930    if ((co = UCD_CASESET(c)) != 0)    if ((co = UCD_CASESET(c)) != 0)
2931      {      {
2932      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2933      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2934      return co;      return (int)co;
2935      }      }
2936    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2937    }    }
2938    
2939  if (c > d) return -1;  /* Reached end of range */  if (c > d) return -1;  /* Reached end of range */
# Line 2964  Returns:       TRUE if auto-possessifyin Line 2971  Returns:       TRUE if auto-possessifyin
2971  */  */
2972    
2973  static BOOL  static BOOL
2974  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)
2975  {  {
2976  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2977  const pcre_uint32 *p;  const pcre_uint32 *p;
# Line 3009  switch(ptype) Line 3016  switch(ptype)
3016    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
3017            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
3018            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
3019    
3020  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3021    case PT_CLIST:    case PT_CLIST:
3022    p = PRIV(ucd_caseless_sets) + prop->caseset;    p = PRIV(ucd_caseless_sets) + prop->caseset;
3023    for (;;)    for (;;)
3024      {      {
3025      if ((unsigned int)c < *p) return !negated;      if (c < *p) return !negated;
3026      if ((unsigned int)c == *p++) return negated;      if (c == *p++) return negated;
3027      }      }
3028    break;  /* Control never reaches here */    break;  /* Control never reaches here */
3029  #endif  #endif
# Line 3053  check_auto_possessive(const pcre_uchar * Line 3060  check_auto_possessive(const pcre_uchar *
3060  pcre_uint32 c = NOTACHAR;  pcre_uint32 c = NOTACHAR;
3061  pcre_uint32 next;  pcre_uint32 next;
3062  int escape;  int escape;
3063  int op_code = *previous++;  pcre_uchar op_code = *previous++;
3064    
3065  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
3066    
# Line 3065  if ((options & PCRE_EXTENDED) != 0) Line 3072  if ((options & PCRE_EXTENDED) != 0)
3072      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
3073        {        {
3074        ptr++;        ptr++;
3075        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3076          {          {
3077          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
3078          ptr++;          ptr++;
# Line 3084  value is a character, a negative value i Line 3091  value is a character, a negative value i
3091  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3092    {    {
3093    int temperrorcode = 0;    int temperrorcode = 0;
3094    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,
3095        FALSE);
3096    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3097    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3098    }    }
# Line 3108  if ((options & PCRE_EXTENDED) != 0) Line 3116  if ((options & PCRE_EXTENDED) != 0)
3116      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
3117        {        {
3118        ptr++;        ptr++;
3119        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3120          {          {
3121          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
3122          ptr++;          ptr++;
# Line 3129  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3137  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3137    
3138  /* If the previous item is a character, get its value. */  /* If the previous item is a character, get its value. */
3139    
3140  if (op_code == OP_CHAR || op_code == OP_CHARI ||  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3141      op_code == OP_NOT || op_code == OP_NOTI)      op_code == OP_NOT || op_code == OP_NOTI)
   //if (escape == 0) switch(op_code)  
3142    {    {
3143  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3144    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
# Line 3147  if (escape == 0) Line 3154  if (escape == 0)
3154    {    {
3155    /* For a caseless UTF match, the next character may have more than one other    /* For a caseless UTF match, the next character may have more than one other
3156    case, which maps to the special PT_CLIST property. Check this first. */    case, which maps to the special PT_CLIST property. Check this first. */
3157    
3158  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3159    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)    if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3160      {      {
3161      int ocs = UCD_CASESET(next);      unsigned int ocs = UCD_CASESET(next);
3162      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);
3163      }      }
3164  #endif  #endif
# Line 3163  if (escape == 0) Line 3170  if (escape == 0)
3170    
3171      /* For CHARI (caseless character) we must check the other case. If we have      /* For CHARI (caseless character) we must check the other case. If we have
3172      Unicode property support, we can use it to test the other case of      Unicode property support, we can use it to test the other case of
3173      high-valued characters. We know that next can have only one other case,      high-valued characters. We know that next can have only one other case,
3174      because multi-other-case characters are dealt with above. */      because multi-other-case characters are dealt with above. */
3175    
3176      case OP_CHARI:      case OP_CHARI:
# Line 3183  if (escape == 0) Line 3190  if (escape == 0)
3190      else      else
3191  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3192      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3193    
3194      case OP_NOT:      case OP_NOT:
3195      return c == next;      return c == next;
3196    
3197      case OP_NOTI:      case OP_NOTI:
3198      if (c == next) return TRUE;      if (c == next) return TRUE;
3199  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 3230  if (escape == 0) Line 3237  if (escape == 0)
3237      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3238      switch(next)      switch(next)
3239        {        {
3240        HSPACE_CASES:        HSPACE_CASES:
3241        return op_code == OP_NOT_HSPACE;        return op_code == OP_NOT_HSPACE;
3242    
3243        default:        default:
# Line 3242  if (escape == 0) Line 3249  if (escape == 0)
3249      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
3250      switch(next)      switch(next)
3251        {        {
3252        VSPACE_CASES:        VSPACE_CASES:
3253        return op_code == OP_NOT_VSPACE;        return op_code == OP_NOT_VSPACE;
3254    
3255        default:        default:
# Line 3296  switch(op_code) Line 3303  switch(op_code)
3303      case ESC_H:      case ESC_H:
3304      switch(c)      switch(c)
3305        {        {
3306        HSPACE_CASES:        HSPACE_CASES:
3307        return escape != ESC_h;        return escape != ESC_h;
3308    
3309        default:        default:
3310        return escape == ESC_h;        return escape == ESC_h;
3311        }        }
# Line 3307  switch(op_code) Line 3314  switch(op_code)
3314      case ESC_V:      case ESC_V:
3315      switch(c)      switch(c)
3316        {        {
3317        VSPACE_CASES:        VSPACE_CASES:
3318        return escape != ESC_v;        return escape != ESC_v;
3319    
3320        default:        default:
# Line 3337  switch(op_code) Line 3344  switch(op_code)
3344      case ESC_p:      case ESC_p:
3345      case ESC_P:      case ESC_P:
3346        {        {
3347        int ptype, pdata, errorcodeptr;        unsigned int ptype = 0, pdata = 0;
3348          int errorcodeptr;
3349        BOOL negated;        BOOL negated;
3350    
3351        ptr--;      /* Make ptr point at the p or P */        ptr--;      /* Make ptr point at the p or P */
3352        ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr);        if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcodeptr))
3353        if (ptype < 0) return FALSE;          return FALSE;
3354        ptr++;      /* Point past the final curly ket */        ptr++;      /* Point past the final curly ket */
3355    
3356        /* 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 3426  switch(op_code)
3426  *************************************************/  *************************************************/
3427    
3428  /* This function packages up the logic of adding a character or range of  /* This function packages up the logic of adding a character or range of
3429  characters to a class. The character values in the arguments will be within the  characters to a class. The character values in the arguments will be within the
3430  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3431  mutually recursive with the function immediately below.  mutually recursive with the function immediately below.
3432    
3433  Arguments:  Arguments:
3434    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3435    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3436    options       the options word    options       the options word
3437    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3438    start         start of range character    start         start of range character
3439    end           end of range character    end           end of range character
3440    
3441  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3442                  the pointer to extra data is updated                  the pointer to extra data is updated
3443  */  */
# Line 3441  add_to_class(pcre_uint8 *classbits, pcre Line 3449  add_to_class(pcre_uint8 *classbits, pcre
3449  pcre_uint32 c;  pcre_uint32 c;
3450  int n8 = 0;  int n8 = 0;
3451    
3452  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
3453  cases. In Unicode, there are 8-bit characters that have alternate cases that  cases. In Unicode, there are 8-bit characters that have alternate cases that
3454  are greater than 255 and vice-versa. Sometimes we can just extend the original  are greater than 255 and vice-versa. Sometimes we can just extend the original
3455  range. */  range. */
3456    
3457  if ((options & PCRE_CASELESS) != 0)  if ((options & PCRE_CASELESS) != 0)
3458    {    {
3459  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3460    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3461      {      {
3462      int rc;      int rc;
3463      pcre_uint32 oc, od;      pcre_uint32 oc, od;
3464    
3465      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3466      c = start;      c = start;
3467    
3468      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3469        {        {
3470        /* Handle a single character that has more than one other case. */        /* Handle a single character that has more than one other case. */
3471    
3472        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3473          PRIV(ucd_caseless_sets) + rc, oc);          PRIV(ucd_caseless_sets) + rc, oc);
3474    
3475        /* Do nothing if the other case range is within the original range. */        /* Do nothing if the other case range is within the original range. */
3476    
3477        else if (oc >= start && od <= end) continue;        else if (oc >= start && od <= end) continue;
3478    
3479        /* Extend the original range if there is overlap, noting that if oc < c, we        /* Extend the original range if there is overlap, noting that if oc < c, we
3480        can't have od > end because a subrange is always shorter than the basic        can't have od > end because a subrange is always shorter than the basic
3481        range. Otherwise, use a recursive call to add the additional range. */        range. Otherwise, use a recursive call to add the additional range. */
3482    
3483        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3484        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3485        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
# Line 3481  if ((options & PCRE_CASELESS) != 0) Line 3489  if ((options & PCRE_CASELESS) != 0)
3489  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3490    
3491    /* Not UTF-mode, or no UCP */    /* Not UTF-mode, or no UCP */
3492    
3493    for (c = start; c <= end && c < 256; c++)    for (c = start; c <= end && c < 256; c++)
3494      {      {
3495      SETBIT(classbits, cd->fcc[c]);      SETBIT(classbits, cd->fcc[c]);
3496      n8++;      n8++;
3497      }      }
3498    }    }
3499    
3500  /* Now handle the original range. Adjust the final value according to the bit  /* Now handle the original range. Adjust the final value according to the bit
3501  length - this means that the same lists of (e.g.) horizontal spaces can be used  length - this means that the same lists of (e.g.) horizontal spaces can be used
3502  in all cases. */  in all cases. */
# Line 3514  if (end < 0x100) Line 3522  if (end < 0x100)
3522    {    {
3523    for (c = start; c <= end; c++)    for (c = start; c <= end; c++)
3524      {      {
3525      n8++;      n8++;
3526      SETBIT(classbits, c);      SETBIT(classbits, c);
3527      }      }
3528    }    }
3529    
3530  else  else
3531    {    {
3532    pcre_uchar *uchardata = *uchardptr;    pcre_uchar *uchardata = *uchardptr;
3533    
3534  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3535    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3536      {      {
3537      if (start < end)      if (start < end)
3538        {        {
3539        *uchardata++ = XCL_RANGE;        *uchardata++ = XCL_RANGE;
3540        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3541        uchardata += PRIV(ord2utf)(end, uchardata);        uchardata += PRIV(ord2utf)(end, uchardata);
3542        }        }
3543      else if (start == end)      else if (start == end)
3544        {        {
3545        *uchardata++ = XCL_SINGLE;        *uchardata++ = XCL_SINGLE;
3546        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3547        }        }
3548      }      }
3549    else    else
3550  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3551    
3552    /* Without UTF support, character values are constrained by the bit length,    /* Without UTF support, character values are constrained by the bit length,
3553    and can only be > 256 for 16-bit and 32-bit libraries. */    and can only be > 256 for 16-bit and 32-bit libraries. */
3554    
3555  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3556      {}      {}
3557  #else  #else
3558    if (start < end)    if (start < end)
3559      {      {
3560      *uchardata++ = XCL_RANGE;      *uchardata++ = XCL_RANGE;
# Line 3557  else Line 3565  else
3565      {      {
3566      *uchardata++ = XCL_SINGLE;      *uchardata++ = XCL_SINGLE;
3567      *uchardata++ = start;      *uchardata++ = start;
3568      }      }
3569  #endif  #endif
3570    
3571    *uchardptr = uchardata;   /* Updata extra data pointer */    *uchardptr = uchardata;   /* Updata extra data pointer */
3572    }    }
3573    
3574  return n8;    /* Number of 8-bit characters */  return n8;    /* Number of 8-bit characters */
3575  }  }
3576    
3577    
3578    
3579    
3580  /*************************************************  /*************************************************
3581  *        Add a list of characters to a class     *  *        Add a list of characters to a class     *
3582  *************************************************/  *************************************************/
3583    
3584  /* This function is used for adding a list of case-equivalent characters to a  /* This function is used for adding a list of case-equivalent characters to a
3585  class, and also for adding a list of horizontal or vertical whitespace. If the  class, and also for adding a list of horizontal or vertical whitespace. If the
3586  list is in order (which it should be), ranges of characters are detected and  list is in order (which it should be), ranges of characters are detected and
3587  handled appropriately. This function is mutually recursive with the function  handled appropriately. This function is mutually recursive with the function
# Line 3583  Arguments: Line 3591  Arguments:
3591    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3592    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3593    options       the options word    options       the options word
3594    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3595    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3596    except        character to omit; this is used when adding lists of    except        character to omit; this is used when adding lists of
3597                    case-equivalent characters to avoid including the one we                    case-equivalent characters to avoid including the one we
3598                    already know about                    already know about
3599    
3600  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3601                  the pointer to extra data is updated                  the pointer to extra data is updated
3602  */  */
# Line 3602  while (p[0] < NOTACHAR) Line 3610  while (p[0] < NOTACHAR)
3610    {    {
3611    int n = 0;    int n = 0;
3612    if (p[0] != except)    if (p[0] != except)
3613      {      {
3614      while(p[n+1] == p[0] + n + 1) n++;      while(p[n+1] == p[0] + n + 1) n++;
3615      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3616      }      }
3617    p += n + 1;    p += n + 1;
3618    }    }
3619  return n8;  return n8;
3620  }  }
3621    
3622    
3623    
# Line 3624  Arguments: Line 3632  Arguments:
3632    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3633    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3634    options       the options word    options       the options word
3635    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3636    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3637    
3638  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3639                  the pointer to extra data is updated                  the pointer to extra data is updated
3640  */  */
3641    
3642  static int  static int
3643  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3644    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3645  {  {
3646  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
# Line 3644  while (p[0] < NOTACHAR) Line 3652  while (p[0] < NOTACHAR)
3652    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3653    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3654      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3655    p++;    p++;
3656    }    }
3657  return n8;  return n8;
3658  }  }
3659    
3660    
3661    
# Line 3666  Arguments: Line 3674  Arguments:
3674    codeptr        points to the pointer to the current code point    codeptr        points to the pointer to the current code point
3675    ptrptr         points to the current pattern pointer    ptrptr         points to the current pattern pointer
3676    errorcodeptr   points to error code variable    errorcodeptr   points to error code variable
3677    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr    place to put the first required character
3678    reqcharptr     set to the last literal character required, else < 0    firstcharflagsptr place to put the first character flags, or a negative number
3679      reqcharptr     place to put the last required character
3680      reqcharflagsptr place to put the last required character flags, or a negative number
3681    bcptr          points to current branch chain    bcptr          points to current branch chain
3682    cond_depth     conditional nesting depth    cond_depth     conditional nesting depth
3683    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
# Line 3680  Returns:         TRUE on success Line 3690  Returns:         TRUE on success
3690    
3691  static BOOL  static BOOL
3692  compile_branch(int *optionsptr, pcre_uchar **codeptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3693    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,    const pcre_uchar **ptrptr, int *errorcodeptr,
3694    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,    pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
3695      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
3696      branch_chain *bcptr, int cond_depth,
3697    compile_data *cd, int *lengthptr)    compile_data *cd, int *lengthptr)
3698  {  {
3699  int repeat_type, op_type;  int repeat_type, op_type;
3700  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3701  int bravalue = 0;  int bravalue = 0;
3702  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3703  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
3704  pcre_int32 zeroreqchar, zerofirstchar;  pcre_int32 firstcharflags, reqcharflags;
3705    pcre_uint32 zeroreqchar, zerofirstchar;
3706    pcre_int32 zeroreqcharflags, zerofirstcharflags;
3707  pcre_int32 req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3708  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3709  int after_manual_callout = 0;  int after_manual_callout = 0;
# Line 3717  dynamically as we process the pattern. * Line 3731  dynamically as we process the pattern. *
3731  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3732  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3733  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3734    #ifndef COMPILE_PCRE32
3735  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3736    #endif
3737  #else  #else
3738  BOOL utf = FALSE;  BOOL utf = FALSE;
3739  #endif  #endif
3740    
3741  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3742  class_uchardata always so that it can be passed to add_to_class() always,  class_uchardata always so that it can be passed to add_to_class() always,
3743  though it will not be used in non-UTF 8-bit cases. This avoids having to supply  though it will not be used in non-UTF 8-bit cases. This avoids having to supply
3744  alternative calls for the different cases. */  alternative calls for the different cases. */
3745    
3746  pcre_uchar *class_uchardata;  pcre_uchar *class_uchardata;
# Line 3752  to take the zero repeat into account. Th Line 3768  to take the zero repeat into account. Th
3768  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3769  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3770    
3771  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = 0;
3772    firstcharflags = reqcharflags = zerofirstcharflags = zeroreqcharflags = REQ_UNSET;
3773    
3774  /* The variable req_caseopt contains either the REQ_CASELESS value  /* The variable req_caseopt contains either the REQ_CASELESS value
3775  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 3795  for (;; ptr++)
3795    int recno;    int recno;
3796    int refsign;    int refsign;
3797    int skipbytes;    int skipbytes;
3798    int subreqchar;    pcre_uint32 subreqchar, subfirstchar;
3799    int subfirstchar;    pcre_int32 subreqcharflags, subfirstcharflags;
3800    int terminator;    int terminator;
3801    int mclength;    unsigned int mclength;
3802    int tempbracount;    unsigned int tempbracount;
3803    int ec; // FIXMEchpe pcre_uint32    pcre_uint32 ec;
3804    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3805    
3806    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 3793  for (;; ptr++) Line 3810  for (;; ptr++)
3810    /* 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
3811    string. Nesting only happens one level deep. */    string. Nesting only happens one level deep. */
3812    
3813    if (c == 0 && nestptr != NULL)    if (c == CHAR_NULL && nestptr != NULL)
3814      {      {
3815      ptr = nestptr;      ptr = nestptr;
3816      nestptr = NULL;      nestptr = NULL;
# Line 3868  for (;; ptr++) Line 3885  for (;; ptr++)
3885    
3886    /* 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 */
3887    
3888    if (inescq && c != 0)    if (inescq && c != CHAR_NULL)
3889      {      {
3890      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)
3891        {        {
# Line 3916  for (;; ptr++) Line 3933  for (;; ptr++)
3933      if (c == CHAR_NUMBER_SIGN)      if (c == CHAR_NUMBER_SIGN)
3934        {        {
3935        ptr++;        ptr++;
3936        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3937          {          {
3938          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3939          ptr++;          ptr++;
# Line 3924  for (;; ptr++) Line 3941  for (;; ptr++)
3941          if (utf) FORWARDCHAR(ptr);          if (utf) FORWARDCHAR(ptr);
3942  #endif  #endif
3943          }          }
3944        if (*ptr != 0) continue;        if (*ptr != CHAR_NULL) continue;
3945    
3946        /* Else fall through to handle end of string */        /* Else fall through to handle end of string */
3947        c = 0;        c = 0;
# Line 3946  for (;; ptr++) Line 3963  for (;; ptr++)
3963      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3964      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3965      *firstcharptr = firstchar;      *firstcharptr = firstchar;
3966        *firstcharflagsptr = firstcharflags;
3967      *reqcharptr = reqchar;      *reqcharptr = reqchar;
3968        *reqcharflagsptr = reqcharflags;
3969      *codeptr = code;      *codeptr = code;
3970      *ptrptr = ptr;      *ptrptr = ptr;
3971      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3970  for (;; ptr++) Line 3989  for (;; ptr++)
3989      previous = NULL;      previous = NULL;
3990      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3991        {        {
3992        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
3993        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3994        }        }
3995      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3985  for (;; ptr++) Line 4004  for (;; ptr++)
4004      repeats. The value of reqchar doesn't change either. */      repeats. The value of reqchar doesn't change either. */
4005    
4006      case CHAR_DOT:      case CHAR_DOT:
4007      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4008      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4009        zerofirstcharflags = firstcharflags;
4010      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4011        zeroreqcharflags = reqcharflags;
4012      previous = code;      previous = code;
4013      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
4014      break;      break;
# Line 4061  for (;; ptr++) Line 4082  for (;; ptr++)
4082          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
4083        {        {
4084        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
4085        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4086        zerofirstchar = firstchar;        zerofirstchar = firstchar;
4087          zerofirstcharflags = firstcharflags;
4088        break;        break;
4089        }        }
4090    
# Line 4097  for (;; ptr++) Line 4119  for (;; ptr++)
4119      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
4120      loop, c contains the first byte of the character. */      loop, c contains the first byte of the character. */
4121    
4122      if (c != 0) do      if (c != CHAR_NULL) do
4123        {        {
4124        const pcre_uchar *oldptr;        const pcre_uchar *oldptr;
4125    
4126  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
4127        if (utf && HAS_EXTRALEN(c))        if (utf && HAS_EXTRALEN(c))
4128          {                           /* Braces are required because the */          {                           /* Braces are required because the */
4129          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
# Line 4112  for (;; ptr++) Line 4134  for (;; ptr++)
4134        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
4135        data and reset the pointer. This is so that very large classes that        data and reset the pointer. This is so that very large classes that
4136        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
4137        (which is on the stack). We have to remember that there was XCLASS data,        (which is on the stack). We have to remember that there was XCLASS data,
4138        however. */        however. */
4139    
4140        if (lengthptr != NULL && class_uchardata > class_uchardata_base)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
# Line 4176  for (;; ptr++) Line 4198  for (;; ptr++)
4198          alpha. This relies on the fact that the class table starts with          alpha. This relies on the fact that the class table starts with
4199          alpha, lower, upper as the first 3 entries. */          alpha, lower, upper as the first 3 entries. */
4200    
4201          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)          if ((options & PCRE_CASELESS) != 0 && posix_class <= 2)
4202            posix_class = 0;            posix_class = 0;
4203    
4204          /* When PCRE_UCP is set, some of the POSIX classes are converted to          /* When PCRE_UCP is set, some of the POSIX classes are converted to
# Line 4253  for (;; ptr++) Line 4275  for (;; ptr++)
4275    
4276        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4277          {          {
4278          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,
4279              TRUE);
4280          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4281            if (escape == 0) c = ec;
         if (escape == 0)  
           c = ec;  
4282          else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */          else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */
4283          else if (escape == ESC_N)            /* \N is not supported in a class */          else if (escape == ESC_N)          /* \N is not supported in a class */
4284            {            {
4285            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4286            goto FAILED;            goto FAILED;
# Line 4332  for (;; ptr++) Line 4352  for (;; ptr++)
4352              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4353              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4354              continue;              continue;
4355    
4356              /* The rest apply in both UCP and non-UCP cases. */              /* The rest apply in both UCP and non-UCP cases. */
4357    
4358              case ESC_h:              case ESC_h:
4359              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4360                PRIV(hspace_list), NOTACHAR);                PRIV(hspace_list), NOTACHAR);
4361              continue;              continue;
4362    
4363              case ESC_H:              case ESC_H:
4364              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4365                cd, PRIV(hspace_list));                cd, PRIV(hspace_list));
4366              continue;              continue;
4367    
4368              case ESC_v:              case ESC_v:
4369              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4370                PRIV(vspace_list), NOTACHAR);                PRIV(vspace_list), NOTACHAR);
4371              continue;              continue;
4372    
4373              case ESC_V:              case ESC_V:
4374              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4375                cd, PRIV(vspace_list));                cd, PRIV(vspace_list));
4376              continue;              continue;
4377    
4378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4360  for (;; ptr++) Line 4380  for (;; ptr++)
4380              case ESC_P:              case ESC_P:
4381                {                {
4382                BOOL negated;                BOOL negated;
4383                int pdata;                unsigned int ptype = 0, pdata = 0;
4384                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
4385                if (ptype < 0) goto FAILED;                  goto FAILED;
4386                *class_uchardata++ = ((escape == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4387                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4388                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
# Line 4390  for (;; ptr++) Line 4410  for (;; ptr++)
4410    
4411          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4412          This may be greater than 256. */          This may be greater than 256. */
4413    
4414          escape = 0;          escape = 0;
4415    
4416          }   /* End of backslash handling */          }   /* End of backslash handling */
# Line 4416  for (;; ptr++) Line 4436  for (;; ptr++)
4436    
4437        if (!inescq && ptr[1] == CHAR_MINUS)        if (!inescq && ptr[1] == CHAR_MINUS)
4438          {          {
4439          int d;          pcre_uint32 d;
4440          ptr += 2;          ptr += 2;
4441          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;
4442    
# Line 4431  for (;; ptr++) Line 4451  for (;; ptr++)
4451            inescq = TRUE;            inescq = TRUE;
4452            break;            break;
4453            }            }
4454    
4455          /* Minus (hyphen) at the end of a class is treated as a literal, so put          /* Minus (hyphen) at the end of a class is treated as a literal, so put
4456          back the pointer and jump to handle the character that preceded it. */          back the pointer and jump to handle the character that preceded it. */
4457    
4458          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))          if (*ptr == CHAR_NULL || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))
4459            {            {
4460            ptr = oldptr;            ptr = oldptr;
4461            goto CLASS_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4462            }            }
4463    
4464          /* Otherwise, we have a potential range; pick up the next character */          /* Otherwise, we have a potential range; pick up the next character */
4465    
4466  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 4487  for (;; ptr++) Line 4507  for (;; ptr++)
4507          /* We have found a character range, so single character optimizations          /* We have found a character range, so single character optimizations
4508          cannot be done anymore. Any value greater than 1 indicates that there          cannot be done anymore. Any value greater than 1 indicates that there
4509          is more than one character. */          is more than one character. */
4510    
4511          class_one_char = 2;          class_one_char = 2;
4512    
4513          /* Remember an explicit \r or \n, and add the range to the class. */          /* Remember an explicit \r or \n, and add the range to the class. */
4514    
4515          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4516    
4517          class_has_8bitchar +=          class_has_8bitchar +=
4518            add_to_class(classbits, &class_uchardata, options, cd, c, d);            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4519    
4520          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4521          }          }
4522    
4523        /* Handle a single character - we can get here for a normal non-escape        /* Handle a single character - we can get here for a normal non-escape
4524        char, or after \ that introduces a single character or for an apparent        char, or after \ that introduces a single character or for an apparent
4525        range that isn't. Only the value 1 matters for class_one_char, so don't        range that isn't. Only the value 1 matters for class_one_char, so don't
4526        increase it if it is already 2 or more ... just in case there's a class        increase it if it is already 2 or more ... just in case there's a class
4527        with a zillion characters in it. */        with a zillion characters in it. */
4528    
4529        CLASS_SINGLE_CHARACTER:        CLASS_SINGLE_CHARACTER:
# Line 4522  for (;; ptr++) Line 4542  for (;; ptr++)
4542          {          {
4543          ptr++;          ptr++;
4544          zeroreqchar = reqchar;          zeroreqchar = reqchar;
4545            zeroreqcharflags = reqcharflags;
4546    
4547          if (negate_class)          if (negate_class)
4548            {            {
4549  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
             // FIXMEchpe pcreuint32?  
4550            int d;            int d;
4551  #endif  #endif
4552            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4553            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4554              zerofirstcharflags = firstcharflags;
4555    
4556            /* For caseless UTF-8 mode when UCP support is available, check            /* For caseless UTF-8 mode when UCP support is available, check
4557            whether this character has more than one other case. If so, generate            whether this character has more than one other case. If so, generate
4558            a special OP_NOTPROP item instead of OP_NOTI. */            a special OP_NOTPROP item instead of OP_NOTI. */
4559    
4560  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4561            if (utf && (options & PCRE_CASELESS) != 0 &&            if (utf && (options & PCRE_CASELESS) != 0 &&
4562                (d = UCD_CASESET(c)) != 0)                (d = UCD_CASESET(c)) != 0)
4563              {              {
4564              *code++ = OP_NOTPROP;              *code++ = OP_NOTPROP;
4565              *code++ = PT_CLIST;              *code++ = PT_CLIST;
4566              *code++ = d;              *code++ = d;
4567              }              }
4568            else            else
4569  #endif  #endif
4570            /* Char has only one other case, or UCP not available */            /* Char has only one other case, or UCP not available */
4571    
# Line 4557  for (;; ptr++) Line 4578  for (;; ptr++)
4578  #endif  #endif
4579                *code++ = c;                *code++ = c;
4580              }              }
4581    
4582            /* We are finished with this character class */            /* We are finished with this character class */
4583    
4584            goto END_CLASS;            goto END_CLASS;
4585            }            }
4586    
# Line 4577  for (;; ptr++) Line 4598  for (;; ptr++)
4598            }            }
4599          goto ONE_CHAR;          goto ONE_CHAR;
4600          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4601    
4602        /* There is more than one character in the class, or an XCLASS item        /* There is more than one character in the class, or an XCLASS item
4603        has been generated. Add this character to the class. */        has been generated. Add this character to the class. */
4604    
4605        class_has_8bitchar +=        class_has_8bitchar +=
4606          add_to_class(classbits, &class_uchardata, options, cd, c, c);          add_to_class(classbits, &class_uchardata, options, cd, c, c);
4607        }        }
4608    
# Line 4589  for (;; ptr++) Line 4610  for (;; ptr++)
4610      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
4611      string. */      string. */
4612    
4613      while (((c = *(++ptr)) != 0 ||      while (((c = *(++ptr)) != CHAR_NULL ||
4614             (nestptr != NULL &&             (nestptr != NULL &&
4615               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != 0)) &&               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != CHAR_NULL)) &&
4616             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));
4617    
4618      /* Check for missing terminating ']' */      /* Check for missing terminating ']' */
4619    
4620      if (c == 0)      if (c == CHAR_NULL)
4621        {        {
4622        *errorcodeptr = ERR6;        *errorcodeptr = ERR6;
4623        goto FAILED;        goto FAILED;
4624        }        }
4625    
4626      /* We will need an XCLASS if data has been placed in class_uchardata. In      /* We will need an XCLASS if data has been placed in class_uchardata. In
4627      the second phase this is a sufficient test. However, in the pre-compile      the second phase this is a sufficient test. However, in the pre-compile
4628      phase, class_uchardata gets emptied to prevent workspace overflow, so it      phase, class_uchardata gets emptied to prevent workspace overflow, so it
4629      only if the very last character in the class needs XCLASS will it contain      only if the very last character in the class needs XCLASS will it contain
4630      anything at this point. For this reason, xclass gets set TRUE above when      anything at this point. For this reason, xclass gets set TRUE above when
4631      uchar_classdata is emptied, and that's why this code is the way it is here      uchar_classdata is emptied, and that's why this code is the way it is here
4632      instead of just doing a test on class_uchardata below. */      instead of just doing a test on class_uchardata below. */
4633    
4634  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4635      if (class_uchardata > class_uchardata_base) xclass = TRUE;      if (class_uchardata > class_uchardata_base) xclass = TRUE;
4636  #endif  #endif
# Line 4618  for (;; ptr++) Line 4639  for (;; ptr++)
4639      setting, whatever the repeat count. Any reqchar setting must remain      setting, whatever the repeat count. Any reqchar setting must remain
4640      unchanged after any kind of repeat. */      unchanged after any kind of repeat. */
4641    
4642      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4643      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4644        zerofirstcharflags = firstcharflags;
4645      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4646        zeroreqcharflags = reqcharflags;
4647    
4648      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4649      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 4699  for (;; ptr++)
4699        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4700        }        }
4701      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4702    
4703      END_CLASS:      END_CLASS:
4704      break;      break;
4705    
# Line 4715  for (;; ptr++) Line 4738  for (;; ptr++)
4738      if (repeat_min == 0)      if (repeat_min == 0)
4739        {        {
4740        firstchar = zerofirstchar;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4741          firstcharflags = zerofirstcharflags;
4742        reqchar = zeroreqchar;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4743          reqcharflags = zeroreqcharflags;
4744        }        }
4745    
4746      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4818  for (;; ptr++) Line 4843  for (;; ptr++)
4843          {          {
4844          c = code[-1];          c = code[-1];
4845          if (*previous <= OP_CHARI && repeat_min > 1)          if (*previous <= OP_CHARI && repeat_min > 1)
4846            reqchar = c | req_caseopt | cd->req_varyopt;            {
4847              reqchar = c;
4848              reqcharflags = req_caseopt | cd->req_varyopt;
4849              }
4850          }          }
4851    
4852        /* 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 4903  for (;; ptr++)
4903    
4904        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
4905    
       /*--------------------------------------------------------------------*/  
       /* This code is obsolete from release 8.00; the restriction was finally  
       removed: */  
   
       /* All real repeats make it impossible to handle partial matching (maybe  
       one day we will be able to remove this restriction). */  
   
       /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */  
       /*--------------------------------------------------------------------*/  
   
4906        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
4907    
4908        repeat_type += op_type;        repeat_type += op_type;
# Line 5031  for (;; ptr++) Line 5049  for (;; ptr++)
5049          goto END_REPEAT;          goto END_REPEAT;
5050          }          }
5051    
       /*--------------------------------------------------------------------*/  
       /* This code is obsolete from release 8.00; the restriction was finally  
       removed: */  
   
       /* All real repeats make it impossible to handle partial matching (maybe  
       one day we will be able to remove this restriction). */  
   
       /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */  
       /*--------------------------------------------------------------------*/  
   
5052        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
5053          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
5054        else if (repeat_min == 1 && repeat_max == -1)        else if (repeat_min == 1 && repeat_max == -1)
# Line 5200  for (;; ptr++) Line 5208  for (;; ptr++)
5208    
5209            else            else
5210              {              {
5211              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;              if (groupsetfirstchar && reqcharflags < 0)
5212                  {
5213                  reqchar = firstchar;
5214                  reqcharflags = firstcharflags;
5215                  }
5216    
5217              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5218                {                {
# Line 5479  for (;; ptr++) Line 5491  for (;; ptr++)
5491        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5492          {          {
5493          tempcode += PRIV(OP_lengths)[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5494  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
5495          if (utf && HAS_EXTRALEN(tempcode[-1]))          if (utf && HAS_EXTRALEN(tempcode[-1]))
5496            tempcode += GET_EXTRALEN(tempcode[-1]);            tempcode += GET_EXTRALEN(tempcode[-1]);
5497  #endif  #endif
# Line 5575  for (;; ptr++) Line 5587  for (;; ptr++)
5587        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
5588          {          {
5589          arg = ++ptr;          arg = ++ptr;
5590          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5591          arglen = (int)(ptr - arg);          arglen = (int)(ptr - arg);
5592          if ((unsigned int)arglen > MAX_MARK)          if ((unsigned int)arglen > MAX_MARK)
5593            {            {
# Line 5620  for (;; ptr++) Line 5632  for (;; ptr++)
5632                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5633    
5634              /* Do not set firstchar after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5635              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;              if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
5636              }              }
5637    
5638            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5689  for (;; ptr++) Line 5701  for (;; ptr++)
5701          {          {
5702          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */
5703          ptr++;          ptr++;
5704          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5705          if (*ptr == 0)          if (*ptr == CHAR_NULL)
5706            {            {
5707            *errorcodeptr = ERR18;            *errorcodeptr = ERR18;
5708            goto FAILED;            goto FAILED;
# Line 5713  for (;; ptr++) Line 5725  for (;; ptr++)
5725          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5726          case CHAR_LEFT_PARENTHESIS:          case CHAR_LEFT_PARENTHESIS:
5727          bravalue = OP_COND;       /* Conditional group */          bravalue = OP_COND;       /* Conditional group */
5728            tempptr = ptr;
5729    
5730          /* A condition can be an assertion, a number (referring to a numbered          /* A condition can be an assertion, a number (referring to a numbered
5731          group), a name (referring to a named group), or 'R', referring to          group), a name (referring to a named group), or 'R', referring to
# Line 5725  for (;; ptr++) Line 5738  for (;; ptr++)
5738          be the recursive thing or the name 'R' (and similarly for 'R' followed          be the recursive thing or the name 'R' (and similarly for 'R' followed
5739          by digits), and (b) a number could be a name that consists of digits.          by digits), and (b) a number could be a name that consists of digits.
5740          In both cases, we look for a name first; if not found, we try the other          In both cases, we look for a name first; if not found, we try the other
5741          cases. */          cases.
5742    
5743            For compatibility with auto-callouts, we allow a callout to be
5744            specified before a condition that is an assertion. First, check for the
5745            syntax of a callout; if found, adjust the temporary pointer that is
5746            used to check for an assertion condition. That's all that is needed! */
5747    
5748            if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)
5749              {
5750              for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
5751              if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
5752                tempptr += i + 1;
5753              }
5754    
5755          /* For conditions that are assertions, check the syntax, and then exit          /* For conditions that are assertions, check the syntax, and then exit
5756          the switch. This will take control down to where bracketed groups,          the switch. This will take control down to where bracketed groups,
5757          including assertions, are processed. */          including assertions, are processed. */
5758    
5759          if (ptr[1] == CHAR_QUESTION_MARK && (ptr[2] == CHAR_EQUALS_SIGN ||          if (tempptr[1] == CHAR_QUESTION_MARK &&
5760              ptr[2] == CHAR_EXCLAMATION_MARK || ptr[2] == CHAR_LESS_THAN_SIGN))                (tempptr[2] == CHAR_EQUALS_SIGN ||
5761                   tempptr[2] == CHAR_EXCLAMATION_MARK ||
5762                   tempptr[2] == CHAR_LESS_THAN_SIGN))
5763            break;            break;
5764    
5765          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
# Line 5766  for (;; ptr++) Line 5793  for (;; ptr++)
5793            }            }
5794          else          else
5795            {            {
5796            terminator = 0;            terminator = CHAR_NULL;
5797            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);
5798            }            }
5799    
# Line 5786  for (;; ptr++) Line 5813  for (;; ptr++)
5813          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)
5814            {            {
5815            if (recno >= 0)            if (recno >= 0)
5816              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;              recno = (IS_DIGIT(*ptr))? recno * 10 + (int)(*ptr - CHAR_0) : -1;
5817            ptr++;            ptr++;
5818            }            }
5819          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
5820    
5821          if ((terminator > 0 && *ptr++ != terminator) ||          if ((terminator > 0 && *ptr++ != (pcre_uchar)terminator) ||
5822              *ptr++ != CHAR_RIGHT_PARENTHESIS)              *ptr++ != CHAR_RIGHT_PARENTHESIS)
5823            {            {
5824            ptr--;      /* Error offset */            ptr--;      /* Error offset */
# Line 5856  for (;; ptr++) Line 5883  for (;; ptr++)
5883            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
5884            }            }
5885    
5886          /* If terminator == 0 it means that the name followed directly after          /* If terminator == CHAR_NULL it means that the name followed directly
5887          the opening parenthesis [e.g. (?(abc)...] and in this case there are          after the opening parenthesis [e.g. (?(abc)...] and in this case there
5888          some further alternatives to try. For the cases where terminator != 0          are some further alternatives to try. For the cases where terminator !=
5889          [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have          0 [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have
5890          now checked all the possibilities, so give an error. */          now checked all the possibilities, so give an error. */
5891    
5892          else if (terminator != 0)          else if (terminator != CHAR_NULL)
5893            {            {
5894            *errorcodeptr = ERR15;            *errorcodeptr = ERR15;
5895            goto FAILED;            goto FAILED;
# Line 6031  for (;; ptr++) Line 6058  for (;; ptr++)
6058    
6059            if (lengthptr != NULL)            if (lengthptr != NULL)
6060              {              {
6061              if (*ptr != terminator)              if (*ptr != (pcre_uchar)terminator)
6062                {                {
6063                *errorcodeptr = ERR42;                *errorcodeptr = ERR42;
6064                goto FAILED;                goto FAILED;
# Line 6173  for (;; ptr++) Line 6200  for (;; ptr++)
6200              *errorcodeptr = ERR62;              *errorcodeptr = ERR62;
6201              goto FAILED;              goto FAILED;
6202              }              }
6203            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6204              {              {
6205              *errorcodeptr = ERR42;              *errorcodeptr = ERR42;
6206              goto FAILED;              goto FAILED;
# Line 6279  for (;; ptr++) Line 6306  for (;; ptr++)
6306            while(IS_DIGIT(*ptr))            while(IS_DIGIT(*ptr))
6307              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6308    
6309            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6310              {              {
6311              *errorcodeptr = ERR29;              *errorcodeptr = ERR29;
6312              goto FAILED;              goto FAILED;
# Line 6383  for (;; ptr++) Line 6410  for (;; ptr++)
6410    
6411          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6412    
6413          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6414          continue;          continue;
6415    
6416    
# Line 6517  for (;; ptr++) Line 6544  for (;; ptr++)
6544           cond_depth +           cond_depth +
6545             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6546           &subfirstchar,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6547             &subfirstcharflags,
6548           &subreqchar,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6549             &subreqcharflags,
6550           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6551           cd,                              /* Tables block */           cd,                              /* Tables block */
6552           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 6578  for (;; ptr++) Line 6607  for (;; ptr++)
6607            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6608            goto FAILED;            goto FAILED;
6609            }            }
6610          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;          if (condcount == 1) subfirstcharflags = subreqcharflags = REQ_NONE;
6611          }          }
6612        }        }
6613    
# Line 6627  for (;; ptr++) Line 6656  for (;; ptr++)
6656      back off. */      back off. */
6657    
6658      zeroreqchar = reqchar;      zeroreqchar = reqchar;
6659        zeroreqcharflags = reqcharflags;
6660      zerofirstchar = firstchar;      zerofirstchar = firstchar;
6661        zerofirstcharflags = firstcharflags;
6662      groupsetfirstchar = FALSE;      groupsetfirstchar = FALSE;
6663    
6664      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
# Line 6638  for (;; ptr++) Line 6669  for (;; ptr++)
6669        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
6670        repeat forces firstchar to "none". */        repeat forces firstchar to "none". */
6671    
6672        if (firstchar == REQ_UNSET)        if (firstcharflags == REQ_UNSET)
6673          {          {
6674          if (subfirstchar >= 0)          if (subfirstcharflags >= 0)
6675            {            {
6676            firstchar = subfirstchar;            firstchar = subfirstchar;
6677              firstcharflags = subfirstcharflags;
6678            groupsetfirstchar = TRUE;            groupsetfirstchar = TRUE;
6679            }            }
6680          else firstchar = REQ_NONE;          else firstcharflags = REQ_NONE;
6681          zerofirstchar = REQ_NONE;          zerofirstcharflags = REQ_NONE;
6682          }          }
6683    
6684        /* If firstchar was previously set, convert the subpattern's firstchar        /* If firstchar was previously set, convert the subpattern's firstchar
6685        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
6686        existence beforehand. */        existence beforehand. */
6687    
6688        else if (subfirstchar >= 0 && subreqchar < 0)        else if (subfirstcharflags >= 0 && subreqcharflags < 0)
6689          subreqchar = subfirstchar | tempreqvary;          {
6690            subreqchar = subfirstchar;
6691            subreqcharflags = subfirstcharflags | tempreqvary;
6692            }
6693    
6694        /* If the subpattern set a required byte (or set a first byte that isn't        /* If the subpattern set a required byte (or set a first byte that isn't
6695        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6696    
6697        if (subreqchar >= 0) reqchar = subreqchar;        if (subreqcharflags >= 0)
6698            {
6699            reqchar = subreqchar;
6700            reqcharflags = subreqcharflags;
6701            }
6702        }        }
6703    
6704      /* 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 6709  for (;; ptr++)
6709      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
6710      firstchar, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6711    
6712      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;      else if (bravalue == OP_ASSERT && subreqcharflags >= 0)
6713          {
6714          reqchar = subreqchar;
6715          reqcharflags = subreqcharflags;
6716          }
6717      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6718    
6719    
# Line 6686  for (;; ptr++) Line 6729  for (;; ptr++)
6729      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6730      tempptr = ptr;      tempptr = ptr;
6731      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
   
6732      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6733    
6734      if (escape == 0)      if (escape == 0)                  /* The escape coded a single character */
6735        c = ec;        c = ec;
6736      else      else
6737        {        {
# Line 6706  for (;; ptr++) Line 6748  for (;; ptr++)
6748        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6749        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6750    
6751        if (firstchar == REQ_UNSET && escape > ESC_b && escape < ESC_Z)        if (firstcharflags == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6752          firstchar = REQ_NONE;          firstcharflags = REQ_NONE;
6753    
6754        /* 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. */
6755    
6756        zerofirstchar = firstchar;        zerofirstchar = firstchar;
6757          zerofirstcharflags = firstcharflags;
6758        zeroreqchar = reqchar;        zeroreqchar = reqchar;
6759          zeroreqcharflags = reqcharflags;
6760    
6761        /* \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'
6762        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 6785  for (;; ptr++)
6785          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)
6786            {            {
6787            BOOL is_a_number = TRUE;            BOOL is_a_number = TRUE;
6788            for (p = ptr + 1; *p != 0 && *p != terminator; p++)            for (p = ptr + 1; *p != CHAR_NULL && *p != (pcre_uchar)terminator; p++)
6789              {              {
6790              if (!MAX_255(*p)) { is_a_number = FALSE; break; }              if (!MAX_255(*p)) { is_a_number = FALSE; break; }
6791              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;
6792              if ((cd->ctypes[*p] & ctype_word) == 0) break;              if ((cd->ctypes[*p] & ctype_word) == 0) break;
6793              }              }
6794            if (*p != terminator)            if (*p != (pcre_uchar)terminator)
6795              {              {
6796              *errorcodeptr = ERR57;              *errorcodeptr = ERR57;
6797              break;              break;
# Line 6765  for (;; ptr++) Line 6809  for (;; ptr++)
6809    
6810          p = ptr + 2;          p = ptr + 2;
6811          while (IS_DIGIT(*p)) p++;          while (IS_DIGIT(*p)) p++;
6812          if (*p != terminator)          if (*p != (pcre_uchar)terminator)
6813            {            {
6814            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
6815            break;            break;
# Line 6802  for (;; ptr++) Line 6846  for (;; ptr++)
6846          recno = -escape;          recno = -escape;
6847    
6848          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6849          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6850          previous = code;          previous = code;
6851          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6852          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6829  for (;; ptr++) Line 6873  for (;; ptr++)
6873        else if (escape == ESC_P || escape == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6874          {          {
6875          BOOL negated;          BOOL negated;
6876          int pdata;          unsigned int ptype = 0, pdata = 0;
6877          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
6878          if (ptype < 0) goto FAILED;            goto FAILED;
6879          previous = code;          previous = code;
6880          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6881          *code++ = ptype;          *code++ = ptype;
# Line 6853  for (;; ptr++) Line 6897  for (;; ptr++)
6897        can obtain the OP value by negating the escape value in the default        can obtain the OP value by negating the escape value in the default
6898        situation when PCRE_UCP is not set. When it *is* set, we substitute        situation when PCRE_UCP is not set. When it *is* set, we substitute
6899        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6900        lookbehind. */        lookbehind, and \A also behaves as if it does. */
6901    
6902        else        else
6903          {          {
6904          if ((escape == ESC_b || escape == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&
6905                 cd->max_lookbehind == 0)
6906            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6907  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6908          if (escape >= ESC_DU && escape <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
# Line 6905  for (;; ptr++) Line 6950  for (;; ptr++)
6950      mclength = 1;      mclength = 1;
6951      mcbuffer[0] = c;      mcbuffer[0] = c;
6952    
6953  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32  #ifdef SUPPORT_UTF
6954      if (utf && HAS_EXTRALEN(c))      if (utf && HAS_EXTRALEN(c))
6955        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));
6956  #endif  #endif
# Line 6915  for (;; ptr++) Line 6960  for (;; ptr++)
6960    
6961      ONE_CHAR:      ONE_CHAR:
6962      previous = code;      previous = code;
6963    
6964      /* For caseless UTF-8 mode when UCP support is available, check whether      /* For caseless UTF-8 mode when UCP support is available, check whether
6965      this character has more than one other case. If so, generate a special      this character has more than one other case. If so, generate a special
6966      OP_PROP item instead of OP_CHARI. */      OP_PROP item instead of OP_CHARI. */
6967    
6968  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6969      if (utf && (options & PCRE_CASELESS) != 0)      if (utf && (options & PCRE_CASELESS) != 0)
6970        {        {
# Line 6929  for (;; ptr++) Line 6974  for (;; ptr++)
6974          *code++ = OP_PROP;          *code++ = OP_PROP;
6975          *code++ = PT_CLIST;          *code++ = PT_CLIST;
6976          *code++ = c;          *code++ = c;
6977          if (firstchar == REQ_UNSET) firstchar = zerofirstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;
6978          break;          break;
6979          }          }
6980        }        }
6981  #endif  #endif
6982    
6983      /* Caseful matches, or not one of the multicase characters. */      /* Caseful matches, or not one of the multicase characters. */
6984    
6985      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6986      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6987    
# Line 6950  for (;; ptr++) Line 6995  for (;; ptr++)
6995      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
6996      repeat. */      repeat. */
6997    
6998      if (firstchar == REQ_UNSET)      if (firstcharflags == REQ_UNSET)
6999        {        {
7000        zerofirstchar = REQ_NONE;        zerofirstcharflags = REQ_NONE;
7001        zeroreqchar = reqchar;        zeroreqchar = reqchar;
7002          zeroreqcharflags = reqcharflags;
7003    
7004        /* 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
7005        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
# Line 6961  for (;; ptr++) Line 7007  for (;; ptr++)
7007        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
7008          {          {
7009          firstchar = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
7010          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;          firstchar = mcbuffer[0];
7011            firstcharflags = req_caseopt;
7012    
7013            if (mclength != 1)
7014              {
7015              reqchar = code[-1];
7016              reqcharflags = cd->req_varyopt;
7017              }
7018          }          }
7019        else firstchar = reqchar = REQ_NONE;        else firstcharflags = reqcharflags = REQ_NONE;
7020        }        }
7021    
7022      /* 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 7025  for (;; ptr++)
7025      else      else
7026        {        {
7027        zerofirstchar = firstchar;        zerofirstchar = firstchar;
7028          zerofirstcharflags = firstcharflags;
7029        zeroreqchar = reqchar;        zeroreqchar = reqchar;
7030          zeroreqcharflags = reqcharflags;
7031        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
7032          reqchar = code[-1] | req_caseopt | cd->req_varyopt;          {
7033            reqchar = code[-1];
7034            reqcharflags = req_caseopt | cd->req_varyopt;
7035            }
7036        }        }
7037    
7038      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6993  return FALSE; Line 7051  return FALSE;
7051    
7052    
7053    
   
7054  /*************************************************  /*************************************************
7055  *     Compile sequence of alternatives           *  *     Compile sequence of alternatives           *
7056  *************************************************/  *************************************************/
# Line 7014  Arguments: Line 7071  Arguments:
7071    reset_bracount TRUE to reset the count for each branch    reset_bracount TRUE to reset the count for each branch
7072    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes      skip this many bytes at start (for brackets and OP_COND)
7073    cond_depth     depth of nesting for conditional subpatterns    cond_depth     depth of nesting for conditional subpatterns
7074    firstcharptr   place to put the first required character, or a negative number    firstcharptr    place to put the first required character
7075    reqcharptr     place to put the last required character, or a negative number    firstcharflagsptr place to put the first character flags, or a negative number
7076      reqcharptr     place to put the last required character
7077      reqcharflagsptr place to put the last required character flags, or a negative number
7078    bcptr          pointer to the chain of currently open branches    bcptr          pointer to the chain of currently open branches
7079    cd             points to the data block with tables pointers etc.    cd             points to the data block with tables pointers etc.
7080    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
# Line 7027  Returns:         TRUE on success Line 7086  Returns:         TRUE on success
7086  static BOOL  static BOOL
7087  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
7088    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
7089    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,    int cond_depth,
7090      pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
7091      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
7092    branch_chain *bcptr, compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
7093  {  {
7094  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
# Line 7037  pcre_uchar *start_bracket = code; Line 7098  pcre_uchar *start_bracket = code;
7098  pcre_uchar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
7099  open_capitem capitem;  open_capitem capitem;
7100  int capnumber = 0;  int capnumber = 0;
7101  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
7102  pcre_int32 branchfirstchar, branchreqchar;  pcre_int32 firstcharflags, reqcharflags;
7103    pcre_uint32 branchfirstchar, branchreqchar;
7104    pcre_int32 branchfirstcharflags, branchreqcharflags;
7105  int length;  int length;
7106  int orig_bracount;  unsigned int orig_bracount;
7107  int max_bracount;  unsigned int max_bracount;
7108  branch_chain bc;  branch_chain bc;
7109    
7110  bc.outer = bcptr;  bc.outer = bcptr;
7111  bc.current_branch = code;  bc.current_branch = code;
7112    
7113  firstchar = reqchar = REQ_UNSET;  firstchar = reqchar = 0;
7114    firstcharflags = reqcharflags = REQ_UNSET;
7115    
7116  /* 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
7117  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 7171  for (;;)
7171    into the length. */    into the length. */
7172    
7173    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
7174          &branchreqchar, &bc, cond_depth, cd,          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,
7175          (lengthptr == NULL)? NULL : &length))          cond_depth, cd, (lengthptr == NULL)? NULL : &length))
7176      {      {
7177      *ptrptr = ptr;      *ptrptr = ptr;
7178      return FALSE;      return FALSE;
# Line 7129  for (;;) Line 7193  for (;;)
7193      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
7194        {        {
7195        firstchar = branchfirstchar;        firstchar = branchfirstchar;
7196          firstcharflags = branchfirstcharflags;
7197        reqchar = branchreqchar;        reqchar = branchreqchar;
7198          reqcharflags = branchreqcharflags;
7199        }        }
7200    
7201      /* 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 7209  for (;;)
7209        we have to abandon the firstchar for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
7210        previously no reqchar, it takes on the value of the old firstchar. */        previously no reqchar, it takes on the value of the old firstchar. */
7211    
7212        if (firstchar >= 0 && firstchar != branchfirstchar)        if (firstcharflags >= 0 &&
7213              (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))
7214          {          {
7215          if (reqchar < 0) reqchar = firstchar;          if (reqcharflags < 0)
7216          firstchar = REQ_NONE;            {
7217              reqchar = firstchar;
7218              reqcharflags = firstcharflags;
7219              }
7220            firstcharflags = REQ_NONE;
7221          }          }
7222    
7223        /* 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
7224        branch becomes a reqchar if there isn't a branch reqchar. */        branch becomes a reqchar if there isn't a branch reqchar. */
7225    
7226        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)        if (firstcharflags < 0 && branchfirstcharflags >= 0 && branchreqcharflags < 0)
7227            branchreqchar = branchfirstchar;          {
7228            branchreqchar = branchfirstchar;
7229            branchreqcharflags = branchfirstcharflags;
7230            }
7231    
7232        /* Now ensure that the reqchars match */        /* Now ensure that the reqchars match */
7233    
7234        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))        if (((reqcharflags & ~REQ_VARY) != (branchreqcharflags & ~REQ_VARY)) ||
7235          reqchar = REQ_NONE;            reqchar != branchreqchar)
7236        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */          reqcharflags = REQ_NONE;
7237          else
7238            {
7239            reqchar = branchreqchar;
7240            reqcharflags |= branchreqcharflags; /* To "or" REQ_VARY */
7241            }
7242        }        }
7243    
7244      /* 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 7334  for (;;)
7334      *codeptr = code;      *codeptr = code;
7335      *ptrptr = ptr;      *ptrptr = ptr;
7336      *firstcharptr = firstchar;      *firstcharptr = firstchar;
7337        *firstcharflagsptr = firstcharflags;
7338      *reqcharptr = reqchar;      *reqcharptr = reqchar;
7339        *reqcharflagsptr = reqcharflags;
7340      if (lengthptr != NULL)      if (lengthptr != NULL)
7341        {        {
7342        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 7490  do { Line 7571  do {
7571       {       {
7572       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7573       }       }
7574    
7575     /* Atomic brackets */     /* Atomic brackets */
7576    
7577     else if (op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
# Line 7542  we return that char, otherwise -1. Line 7623  we return that char, otherwise -1.
7623    
7624  Arguments:  Arguments:
7625    code       points to start of expression (the bracket)    code       points to start of expression (the bracket)
7626      flags       points to the first char flags, or to REQ_NONE
7627    inassert   TRUE if in an assertion    inassert   TRUE if in an assertion
7628    
7629  Returns:     -1 or the fixed first char  Returns:     the fixed first char, or 0 with REQ_NONE in flags
7630  */  */
7631    
7632  static int  static pcre_uint32
7633  find_firstassertedchar(const pcre_uchar *code, BOOL inassert)  find_firstassertedchar(const pcre_uchar *code, pcre_int32 *flags,
7634      BOOL inassert)
7635  {  {
7636  register int c = -1;  register pcre_uint32 c = 0;
7637    int cflags = REQ_NONE;
7638    
7639    *flags = REQ_NONE;
7640  do {  do {
7641     int d;     pcre_uint32 d;
7642       int dflags;
7643     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||
7644               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;
7645     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,
7646       TRUE);       TRUE);
7647     register int op = *scode;     register pcre_uchar op = *scode;
7648    
7649     switch(op)     switch(op)
7650       {       {
7651       default:       default:
7652       return -1;       return 0;
7653    
7654       case OP_BRA:       case OP_BRA:
7655       case OP_BRAPOS:       case OP_BRAPOS:
# Line 7574  do { Line 7661  do {
7661       case OP_ONCE:       case OP_ONCE:
7662       case OP_ONCE_NC:       case OP_ONCE_NC:
7663       case OP_COND:       case OP_COND:
7664       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       d = find_firstassertedchar(scode, &dflags, op == OP_ASSERT);
7665         return -1;       if (dflags < 0)
7666       if (c < 0) c = d; else if (c != d) return -1;         return 0;
7667         if (cflags < 0) { c = d; cflags = dflags; } else if (c != d || cflags != dflags) return 0;
7668       break;       break;
7669    
7670       case OP_EXACT:       case OP_EXACT:
# Line 7587  do { Line 7675  do {
7675       case OP_PLUS:       case OP_PLUS:
7676       case OP_MINPLUS:       case OP_MINPLUS:
7677       case OP_POSPLUS:       case OP_POSPLUS:
7678       if (!inassert) return -1;       if (!inassert) return 0;
7679       if (c < 0) c = scode[1];       if (cflags < 0) { c = scode[1]; cflags = 0; }
7680         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7681       break;       break;
7682    
7683       case OP_EXACTI:       case OP_EXACTI:
# Line 7600  do { Line 7688  do {
7688       case OP_PLUSI:       case OP_PLUSI:
7689       case OP_MINPLUSI:       case OP_MINPLUSI:
7690       case OP_POSPLUSI:       case OP_POSPLUSI:
7691       if (!inassert) return -1;       if (!inassert) return 0;
7692       if (c < 0) c = scode[1] | REQ_CASELESS;       if (cflags < 0) { c = scode[1]; cflags = REQ_CASELESS; }
7693         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7694       break;       break;
7695       }       }
7696    
7697     code += GET(code, 1);     code += GET(code, 1);
7698     }     }
7699  while (*code == OP_ALT);  while (*code == OP_ALT);
7700    
7701    *flags = cflags;
7702  return c;  return c;
7703  }  }
7704    
# Line 7676  pcre32_compile2(PCRE_SPTR32 pattern, int Line 7766  pcre32_compile2(PCRE_SPTR32 pattern, int
7766  {  {
7767  REAL_PCRE *re;  REAL_PCRE *re;
7768  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7769  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
7770    pcre_int32 firstcharflags, reqcharflags;
7771  int newline;  int newline;
7772  int errorcode = 0;  int errorcode = 0;
7773  int skipatstart = 0;  int skipatstart = 0;
7774  BOOL utf;  BOOL utf;
7775    BOOL never_utf = FALSE;
7776  size_t size;  size_t size;
7777  pcre_uchar *code;  pcre_uchar *code;
7778  const pcre_uchar *codestart;  const pcre_uchar *codestart;
# Line 7739  if ((options & ~PUBLIC_COMPILE_OPTIONS) Line 7831  if ((options & ~PUBLIC_COMPILE_OPTIONS)
7831    errorcode = ERR17;    errorcode = ERR17;
7832    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
7833    }    }
7834    
7835    /* If PCRE_NEVER_UTF is set, remember it. As this option steals a bit that is
7836    also used for execution options, flatten it just in case. */
7837    
7838    if ((options & PCRE_NEVER_UTF) != 0)
7839      {
7840      never_utf = TRUE;
7841      options &= ~PCRE_NEVER_UTF;
7842      }
7843    
7844  /* Check for global one-time settings at the start of the pattern, and remember  /* Check for global one-time settings at the start of the pattern, and remember
7845  the offset for later. */  the offset for later. */
# Line 7749  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7850  while (ptr[skipatstart] == CHAR_LEFT_PAR
7850    int newnl = 0;    int newnl = 0;
7851    int newbsr = 0;    int newbsr = 0;
7852    
7853    /* For completeness and backward compatibility, (*UTFn) is supported in the
7854    relevant libraries, but (*UTF) is generic and always supported. Note that
7855    PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */
7856    
7857  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
7858    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
7859      { skipatstart += 7; options |= PCRE_UTF8; continue; }      { skipatstart += 7; options |= PCRE_UTF8; continue; }
7860  #endif  #endif
7861  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
7862    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF16_RIGHTPAR, 6) == 0)
7863      { skipatstart += 8; options |= PCRE_UTF16; continue; }      { skipatstart += 8; options |= PCRE_UTF16; continue; }
7864  #endif  #endif
7865  #ifdef COMPILE_PCRE32  #ifdef COMPILE_PCRE32
7866    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF32_RIGHTPAR, 6) == 0)
7867      { skipatstart += 8; options |= PCRE_UTF32; continue; }      { skipatstart += 8; options |= PCRE_UTF32; continue; }
7868  #endif  #endif
7869    
7870      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)
7871        { skipatstart += 6; options |= PCRE_UTF8; continue; }
7872    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)
7873      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7874    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 7788  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7896  while (ptr[skipatstart] == CHAR_LEFT_PAR
7896      options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr;      options = (options & ~(PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) | newbsr;
7897    else break;    else break;
7898    }    }
7899    
7900  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */
7901  utf = (options & PCRE_UTF8) != 0;  utf = (options & PCRE_UTF8) != 0;
7902    if (utf && never_utf)
7903      {
7904      errorcode = ERR78;
7905      goto PCRE_EARLY_ERROR_RETURN2;
7906      }
7907    
7908  /* Can't support UTF unless PCRE has been compiled to include the code. The  /* Can't support UTF unless PCRE has been compiled to include the code. The
7909  return of an error code from PRIV(valid_utf)() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
# Line 7926  ptr += skipatstart; Line 8039  ptr += skipatstart;
8039  code = cworkspace;  code = cworkspace;
8040  *code = OP_BRA;  *code = OP_BRA;
8041  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,
8042    FALSE, 0, 0, &firstchar, &reqchar, NULL, cd, &length);    FALSE, 0, 0, &firstchar, &firstcharflags, &reqchar, &reqcharflags, NULL,
8043      cd, &length);
8044  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
8045    
8046  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 8118  ptr = (const pcre_uchar *)pattern + skip
8118  code = (pcre_uchar *)codestart;  code = (pcre_uchar *)codestart;
8119  *code = OP_BRA;  *code = OP_BRA;
8120  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,
8121    &firstchar, &reqchar, NULL, cd, NULL);    &firstchar, &firstcharflags, &reqchar, &reqcharflags, NULL, cd, NULL);
8122  re->top_bracket = cd->bracount;  re->top_bracket = cd->bracount;
8123  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
8124  re->max_lookbehind = cd->max_lookbehind;  re->max_lookbehind = cd->max_lookbehind;
8125  re->flags = cd->external_flags | PCRE_MODE;  re->flags = cd->external_flags | PCRE_MODE;
8126    
8127  if (cd->had_accept) reqchar = REQ_NONE;   /* Must disable after (*ACCEPT) */  if (cd->had_accept)
8128      {
8129      reqchar = 0;              /* Must disable after (*ACCEPT) */
8130      reqcharflags = REQ_NONE;
8131      }
8132    
8133  /* 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. */
8134    
8135  if (errorcode == 0 && *ptr != 0) errorcode = ERR22;  if (errorcode == 0 && *ptr != CHAR_NULL) errorcode = ERR22;
8136    
8137  /* Fill in the terminating state and check for disastrous overflow, but  /* Fill in the terminating state and check for disastrous overflow, but
8138  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 8143  if debugging, leave the test till after
8143  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
8144  #endif  #endif
8145    
8146    #ifdef SUPPORT_VALGRIND
8147    /* If the estimated length exceeds the really used length, mark the extra
8148    allocated memory as unadressable, so that any out-of-bound reads can be
8149    detected. */
8150    VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
8151    #endif
8152    
8153  /* Fill in any forward references that are required. There may be repeated  /* Fill in any forward references that are required. There may be repeated
8154  references; optimize for them, as searching a large regex takes time. */  references; optimize for them, as searching a large regex takes time. */
8155    
# Line 8060  if (errorcode == 0 && re->top_backref > Line 8185  if (errorcode == 0 && re->top_backref >
8185    
8186  /* If there were any lookbehind assertions that contained OP_RECURSE  /* If there were any lookbehind assertions that contained OP_RECURSE
8187  (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,
8188  because they may contain forward references. Actual recursions can't be fixed  because they may contain forward references. Actual recursions cannot be fixed
8189  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
8190  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
8191  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 8256  if ((re->options & PCRE_ANCHORED) == 0)
8256    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;
8257    else    else
8258      {      {
8259      if (firstchar < 0)      if (firstcharflags < 0)
8260        firstchar = find_firstassertedchar(codestart, FALSE);        firstchar = find_firstassertedchar(codestart, &firstcharflags, FALSE);
8261      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */      if (firstcharflags >= 0)   /* Remove caseless flag for non-caseable chars */
8262        {        {
8263  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
8264        re->first_char = firstchar & 0xff;        re->first_char = firstchar & 0xff;
8265  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
8266        re->first_char = firstchar & 0xffff;        re->first_char = firstchar & 0xffff;
8267  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
8268        re->first_char = firstchar & ~REQ_MASK;        re->first_char = firstchar;
8269  #endif  #endif
8270        if ((firstchar & REQ_CASELESS) != 0)        if ((firstcharflags & REQ_CASELESS) != 0)
8271          {          {
8272  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
8273          /* 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 8299  if ((re->options & PCRE_ANCHORED) == 0)
8299  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
8300  bytes. */  bytes. */
8301    
8302  if (reqchar >= 0 &&  if (reqcharflags >= 0 &&
8303       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))       ((re->options & PCRE_ANCHORED) == 0 || (reqcharflags & REQ_VARY) != 0))
8304    {    {
8305  #if defined COMPILE_PCRE8  #if defined COMPILE_PCRE8
8306    re->req_char = reqchar & 0xff;    re->req_char = reqchar & 0xff;
8307  #elif defined COMPILE_PCRE16  #elif defined COMPILE_PCRE16
8308    re->req_char = reqchar & 0xffff;    re->req_char = reqchar & 0xffff;
8309  #elif defined COMPILE_PCRE32  #elif defined COMPILE_PCRE32
8310    re->req_char = reqchar & ~REQ_MASK;    re->req_char = reqchar;
8311  #endif  #endif
8312    if ((reqchar & REQ_CASELESS) != 0)    if ((reqcharflags & REQ_CASELESS) != 0)
8313      {      {
8314  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
8315      /* We ignore non-ASCII first chars in 8 bit mode. */      /* We ignore non-ASCII first chars in 8 bit mode. */

Legend:
Removed from v.1067  
changed lines
  Added in v.1309

  ViewVC Help
Powered by ViewVC 1.1.5