/[pcre]/code/branches/pcre16/pcre_compile.c
ViewVC logotype

Diff of /code/branches/pcre16/pcre_compile.c

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

revision 770 by zherczeg, Mon Nov 28 20:39:30 2011 UTC revision 795 by zherczeg, Sat Dec 10 02:20:06 2011 UTC
# Line 97  overrun before it actually does run off Line 97  overrun before it actually does run off
97    
98  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)
99    
100    /* Private flags added to firstchar and reqchar. */
101    
102    #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */
103    #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */
104    
105    /* Repeated character flags. */
106    
107    #define UTF_LENGTH     0x10000000l      /* The char contains its length. */
108    
109  /* Table for handling escaped characters in the range '0'-'z'. Positive returns  /* Table for handling escaped characters in the range '0'-'z'. Positive returns
110  are simple data values; negative values are for special things like \d and so  are simple data values; negative values are for special things like \d and so
# Line 466  static const char error_texts[] = Line 474  static const char error_texts[] =
474    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"
475    /* 70 */    /* 70 */
476    "internal error: unknown opcode in find_fixedlength()\0"    "internal error: unknown opcode in find_fixedlength()\0"
477      "Not allowed UTF-8 / UTF-16 code point (>= 0xd800 && <= 0xdfff)\0"
478    ;    ;
479    
480  /* 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 484  For convenience, we use the same bit def Line 493  For convenience, we use the same bit def
493    
494  Then we can use ctype_digit and ctype_xdigit in the code. */  Then we can use ctype_digit and ctype_xdigit in the code. */
495    
496    /* Using a simple comparison for decimal numbers rather than a memory read
497    is much faster, and the resulting code is simpler (the compiler turns it
498    into a subtraction and unsigned comparison). */
499    
500    #define IS_DIGIT(x) ((x) >= CHAR_0 && (x) <= CHAR_9)
501    
502  #ifndef EBCDIC  #ifndef EBCDIC
503    
504  /* This is the "normal" case, for ASCII systems, and EBCDIC systems running in  /* This is the "normal" case, for ASCII systems, and EBCDIC systems running in
505  UTF-8 mode. */  UTF-8 mode. */
506    
507  static const unsigned char digitab[] =  static const pcre_uint8 digitab[] =
508    {    {
509    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */
510    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15 */
# Line 528  static const unsigned char digitab[] = Line 543  static const unsigned char digitab[] =
543    
544  /* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */  /* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */
545    
546  static const unsigned char digitab[] =  static const pcre_uint8 digitab[] =
547    {    {
548    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7  0 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7  0 */
549    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15    */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15    */
# Line 563  static const unsigned char digitab[] = Line 578  static const unsigned char digitab[] =
578    0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, /*  0 - 7  F0 */    0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, /*  0 - 7  F0 */
579    0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00};/*  8 -255    */    0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00};/*  8 -255    */
580    
581  static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */  static const pcre_uint8 ebcdic_chartab[] = { /* chartable partial dup */
582    0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*   0-  7 */    0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*   0-  7 */
583    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */
584    0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*  16- 23 */    0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*  16- 23 */
# Line 651  Returns:    TRUE or FALSE Line 666  Returns:    TRUE or FALSE
666  static BOOL  static BOOL
667  is_counted_repeat(const pcre_uchar *p)  is_counted_repeat(const pcre_uchar *p)
668  {  {
669  if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  if (!IS_DIGIT(*p)) return FALSE;
670  while ((digitab[*p] & ctype_digit) != 0) p++;  p++;
671    while (IS_DIGIT(*p)) p++;
672  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
673    
674  if (*p++ != CHAR_COMMA) return FALSE;  if (*p++ != CHAR_COMMA) return FALSE;
675  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
676    
677  if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  if (!IS_DIGIT(*p)) return FALSE;
678  while ((digitab[*p] & ctype_digit) != 0) p++;  p++;
679    while (IS_DIGIT(*p)) p++;
680    
681  return (*p == CHAR_RIGHT_CURLY_BRACKET);  return (*p == CHAR_RIGHT_CURLY_BRACKET);
682  }  }
# Line 694  static int Line 711  static int
711  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,
712    int options, BOOL isclass)    int options, BOOL isclass)
713  {  {
714  BOOL utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
715    BOOL utf = (options & PCRE_UTF8) != 0;
716  const pcre_uchar *ptr = *ptrptr + 1;  const pcre_uchar *ptr = *ptrptr + 1;
717  int c, i;  pcre_int32 c;
718    int i;
719    
720  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
721  ptr--;                            /* Set pointer back to the last byte */  ptr--;                            /* Set pointer back to the last byte */
# Line 710  in a table. A non-zero result is somethi Line 729  in a table. A non-zero result is somethi
729  Otherwise further processing may be required. */  Otherwise further processing may be required. */
730    
731  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
732  else if (c < CHAR_0 || c > CHAR_z) {}                     /* Not alphanumeric */  /* Not alphanumeric */
733    else if (c < CHAR_0 || c > CHAR_z) {}
734  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0) c = i;
735    
736  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
737  else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) {}   /* Not alphanumeric */  /* Not alphanumeric */
738    else if (c < 'a' || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
739  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  c = i;
740  #endif  #endif
741    
# Line 740  else Line 761  else
761        {        {
762        /* In JavaScript, \u must be followed by four hexadecimal numbers.        /* In JavaScript, \u must be followed by four hexadecimal numbers.
763        Otherwise it is a lowercase u letter. */        Otherwise it is a lowercase u letter. */
764        if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0        if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
765             && (digitab[ptr[3]] & ctype_xdigit) != 0 && (digitab[ptr[4]] & ctype_xdigit) != 0)          && MAX_255(ptr[2]) && (digitab[ptr[2]] & ctype_xdigit) != 0
766            && MAX_255(ptr[3]) && (digitab[ptr[3]] & ctype_xdigit) != 0
767            && MAX_255(ptr[4]) && (digitab[ptr[4]] & ctype_xdigit) != 0)
768          {          {
769          c = 0;          c = 0;
770          for (i = 0; i < 4; ++i)          for (i = 0; i < 4; ++i)
# Line 797  else Line 820  else
820        {        {
821        const pcre_uchar *p;        const pcre_uchar *p;
822        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)
823          if (*p != CHAR_MINUS && (digitab[*p] & ctype_digit) == 0) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
824        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)
825          {          {
826          c = -ESC_k;          c = -ESC_k;
# Line 815  else Line 838  else
838        }        }
839      else negated = FALSE;      else negated = FALSE;
840    
841        /* The integer range is limited by the machine's int representation. */
842      c = 0;      c = 0;
843      while ((digitab[ptr[1]] & ctype_digit) != 0)      while (IS_DIGIT(ptr[1]))
844          {
845          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */
846            {
847            c = -1;
848            break;
849            }
850        c = c * 10 + *(++ptr) - CHAR_0;        c = c * 10 + *(++ptr) - CHAR_0;
851          }
852      if (c < 0)   /* Integer overflow */      if (((unsigned int)c) > INT_MAX) /* Integer overflow */
853        {        {
854          while (IS_DIGIT(ptr[1]))
855            ptr++;
856        *errorcodeptr = ERR61;        *errorcodeptr = ERR61;
857        break;        break;
858        }        }
# Line 868  else Line 900  else
900      if (!isclass)      if (!isclass)
901        {        {
902        oldptr = ptr;        oldptr = ptr;
903          /* The integer range is limited by the machine's int representation. */
904        c -= CHAR_0;        c -= CHAR_0;
905        while ((digitab[ptr[1]] & ctype_digit) != 0)        while (IS_DIGIT(ptr[1]))
906            {
907            if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */
908              {
909              c = -1;
910              break;
911              }
912          c = c * 10 + *(++ptr) - CHAR_0;          c = c * 10 + *(++ptr) - CHAR_0;
913        if (c < 0)    /* Integer overflow */          }
914          if (((unsigned int)c) > INT_MAX) /* Integer overflow */
915          {          {
916            while (IS_DIGIT(ptr[1]))
917              ptr++;
918          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
919          break;          break;
920          }          }
# Line 905  else Line 947  else
947      c -= CHAR_0;      c -= CHAR_0;
948      while(i++ < 2 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7)      while(i++ < 2 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7)
949          c = c * 8 + *(++ptr) - CHAR_0;          c = c * 8 + *(++ptr) - CHAR_0;
950      if (!utf8 && c > 255) *errorcodeptr = ERR51;      if (!utf && c > 0xff) *errorcodeptr = ERR51;
951      break;      break;
952    
953      /* \x is complicated. \x{ddd} is a character number which can be greater      /* \x is complicated. \x{ddd} is a character number which can be greater
954      than 0xff in utf8 mode, but only if the ddd are hex digits. If not, { is      than 0xff in utf or non-8bit mode, but only if the ddd are hex digits.
955      treated as a data character. */      If not, { is treated as a data character. */
956    
957      case CHAR_x:      case CHAR_x:
958      if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)      if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
959        {        {
960        /* In JavaScript, \x must be followed by two hexadecimal numbers.        /* In JavaScript, \x must be followed by two hexadecimal numbers.
961        Otherwise it is a lowercase x letter. */        Otherwise it is a lowercase x letter. */
962        if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0)        if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
963            && MAX_255(ptr[2]) && (digitab[ptr[2]] & ctype_xdigit) != 0)
964          {          {
965          c = 0;          c = 0;
966          for (i = 0; i < 2; ++i)          for (i = 0; i < 2; ++i)
# Line 938  else Line 981  else
981      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
982        {        {
983        const pcre_uchar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
       int count = 0;  
984    
985        c = 0;        c = 0;
986        while ((digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
987          {          {
988          register int cc = *pt++;          register int cc = *pt++;
989          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
         count++;  
990    
991  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
992          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
# Line 954  else Line 995  else
995          if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */          if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
996          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
997  #endif  #endif
998    
999    #ifdef COMPILE_PCRE8
1000            if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }
1001    #else
1002    #ifdef COMPILE_PCRE16
1003            if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }
1004    #endif
1005    #endif
1006            }
1007    
1008          if (c < 0)
1009            {
1010            while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1011            *errorcodeptr = ERR34;
1012          }          }
1013    
1014        if (*pt == CHAR_RIGHT_CURLY_BRACKET)        if (*pt == CHAR_RIGHT_CURLY_BRACKET)
1015          {          {
1016          if (c < 0 || count > (utf8? 8 : 2)) *errorcodeptr = ERR34;          if (utf && c >= 0xd800 && c <= 0xdfff) *errorcodeptr = ERR71;
1017          ptr = pt;          ptr = pt;
1018          break;          break;
1019          }          }
# Line 970  else Line 1025  else
1025      /* Read just a single-byte hex-defined char */      /* Read just a single-byte hex-defined char */
1026    
1027      c = 0;      c = 0;
1028      while (i++ < 2 && (digitab[ptr[1]] & ctype_xdigit) != 0)      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)
1029        {        {
1030        int cc;                                  /* Some compilers don't like */        int cc;                                  /* Some compilers don't like */
1031        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
# Line 1169  int max = -1; Line 1224  int max = -1;
1224  /* Read the minimum value and do a paranoid check: a negative value indicates  /* Read the minimum value and do a paranoid check: a negative value indicates
1225  an integer overflow. */  an integer overflow. */
1226    
1227  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - CHAR_0;  while (IS_DIGIT(*p)) min = min * 10 + *p++ - CHAR_0;
1228  if (min < 0 || min > 65535)  if (min < 0 || min > 65535)
1229    {    {
1230    *errorcodeptr = ERR5;    *errorcodeptr = ERR5;
# Line 1184  if (*p == CHAR_RIGHT_CURLY_BRACKET) max Line 1239  if (*p == CHAR_RIGHT_CURLY_BRACKET) max
1239    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)
1240      {      {
1241      max = 0;      max = 0;
1242      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - CHAR_0;      while(IS_DIGIT(*p)) max = max * 10 + *p++ - CHAR_0;
1243      if (max < 0 || max > 65535)      if (max < 0 || max > 65535)
1244        {        {
1245        *errorcodeptr = ERR5;        *errorcodeptr = ERR5;
# Line 1239  Arguments: Line 1294  Arguments:
1294    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1295    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1296    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1297    utf8         TRUE if we are in UTF-8 mode    utf          TRUE if we are in UTF-8 / UTF-16 mode
1298    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1299    
1300  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
# Line 1247  Returns:       the number of the named s Line 1302  Returns:       the number of the named s
1302    
1303  static int  static int
1304  find_parens_sub(pcre_uchar **ptrptr, compile_data *cd, const pcre_uchar *name, int lorn,  find_parens_sub(pcre_uchar **ptrptr, compile_data *cd, const pcre_uchar *name, int lorn,
1305    BOOL xmode, BOOL utf8, int *count)    BOOL xmode, BOOL utf, int *count)
1306  {  {
1307  pcre_uchar *ptr = *ptrptr;  pcre_uchar *ptr = *ptrptr;
1308  int start_count = *count;  int start_count = *count;
# Line 1415  for (; ptr < cd->end_pattern; ptr++) Line 1470  for (; ptr < cd->end_pattern; ptr++)
1470        {        {
1471        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1472        ptr++;        ptr++;
1473  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1474        if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;        if (utf) FORWARDCHAR(ptr);
1475  #endif  #endif
1476        }        }
1477      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
# Line 1427  for (; ptr < cd->end_pattern; ptr++) Line 1482  for (; ptr < cd->end_pattern; ptr++)
1482    
1483    if (*ptr == CHAR_LEFT_PARENTHESIS)    if (*ptr == CHAR_LEFT_PARENTHESIS)
1484      {      {
1485      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);
1486      if (rc > 0) return rc;      if (rc > 0) return rc;
1487      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
1488      }      }
# Line 1473  Arguments: Line 1528  Arguments:
1528    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1529    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1530    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1531    utf8         TRUE if we are in UTF-8 mode    utf          TRUE if we are in UTF-8 / UTF-16 mode
1532    
1533  Returns:       the number of the found subpattern, or -1 if not found  Returns:       the number of the found subpattern, or -1 if not found
1534  */  */
1535    
1536  static int  static int
1537  find_parens(compile_data *cd, const pcre_uchar *name, int lorn, BOOL xmode,  find_parens(compile_data *cd, const pcre_uchar *name, int lorn, BOOL xmode,
1538    BOOL utf8)    BOOL utf)
1539  {  {
1540  pcre_uchar *ptr = (pcre_uchar *)cd->start_pattern;  pcre_uchar *ptr = (pcre_uchar *)cd->start_pattern;
1541  int count = 0;  int count = 0;
# Line 1493  matching closing parens. That is why we Line 1548  matching closing parens. That is why we
1548    
1549  for (;;)  for (;;)
1550    {    {
1551    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);
1552    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == 0) break;
1553    }    }
1554    
# Line 1576  and doing the check at the end; a flag s Line 1631  and doing the check at the end; a flag s
1631    
1632  Arguments:  Arguments:
1633    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1634    utf8     TRUE in UTF-8 mode    utf      TRUE in UTF-8 / UTF-16 mode
1635    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1636    cd       the "compile data" structure    cd       the "compile data" structure
1637    
# Line 1588  Returns:   the fixed length, Line 1643  Returns:   the fixed length,
1643  */  */
1644    
1645  static int  static int
1646  find_fixedlength(pcre_uchar *code, BOOL utf8, BOOL atend, compile_data *cd)  find_fixedlength(pcre_uchar *code, BOOL utf, BOOL atend, compile_data *cd)
1647  {  {
1648  int length = -1;  int length = -1;
1649    
# Line 1615  for (;;) Line 1670  for (;;)
1670      case OP_ONCE:      case OP_ONCE:
1671      case OP_ONCE_NC:      case OP_ONCE_NC:
1672      case OP_COND:      case OP_COND:
1673      d = find_fixedlength(cc + ((op == OP_CBRA)? IMM2_SIZE : 0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? IMM2_SIZE : 0), utf, atend, cd);
1674      if (d < 0) return d;      if (d < 0) return d;
1675      branchlength += d;      branchlength += d;
1676      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 1649  for (;;) Line 1704  for (;;)
1704      cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */      cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
1705      do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */      do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */
1706      if (cc > cs && cc < ce) return -1;                    /* Recursion */      if (cc > cs && cc < ce) return -1;                    /* Recursion */
1707      d = find_fixedlength(cs + 2, utf8, atend, cd);      d = find_fixedlength(cs + 2, utf, atend, cd);
1708      if (d < 0) return d;      if (d < 0) return d;
1709      branchlength += d;      branchlength += d;
1710      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
# Line 1708  for (;;) Line 1763  for (;;)
1763      case OP_NOTI:      case OP_NOTI:
1764      branchlength++;      branchlength++;
1765      cc += 2;      cc += 2;
1766  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1767      if (utf8 && cc[-1] >= 0xc0) cc += PRIV(utf8_table4)[cc[-1] & 0x3f];      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1768  #endif  #endif
1769      break;      break;
1770    
# Line 1722  for (;;) Line 1777  for (;;)
1777      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1778      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1779      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1780  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1781      if (utf8 && cc[-1] >= 0xc0) cc += PRIV(utf8_table4)[cc[-1] & 0x3f];      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1782  #endif  #endif
1783      break;      break;
1784    
# Line 1903  length. Line 1958  length.
1958    
1959  Arguments:  Arguments:
1960    code        points to start of expression    code        points to start of expression
1961    utf8        TRUE in UTF-8 mode    utf         TRUE in UTF-8 / UTF-16 mode
1962    number      the required bracket number or negative to find a lookbehind    number      the required bracket number or negative to find a lookbehind
1963    
1964  Returns:      pointer to the opcode for the bracket, or NULL if not found  Returns:      pointer to the opcode for the bracket, or NULL if not found
1965  */  */
1966    
1967  const pcre_uchar *  const pcre_uchar *
1968  PRIV(find_bracket)(const pcre_uchar *code, BOOL utf8, int number)  PRIV(find_bracket)(const pcre_uchar *code, BOOL utf, int number)
1969  {  {
1970  for (;;)  for (;;)
1971    {    {
# Line 1990  for (;;) Line 2045  for (;;)
2045    a multi-byte character. The length in the table is a minimum, so we have to    a multi-byte character. The length in the table is a minimum, so we have to
2046    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
2047    
2048  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2049      if (utf8) switch(c)      if (utf) switch(c)
2050        {        {
2051        case OP_CHAR:        case OP_CHAR:
2052        case OP_CHARI:        case OP_CHARI:
# Line 2021  for (;;) Line 2076  for (;;)
2076        case OP_MINQUERYI:        case OP_MINQUERYI:
2077        case OP_POSQUERY:        case OP_POSQUERY:
2078        case OP_POSQUERYI:        case OP_POSQUERYI:
2079        if (code[-1] >= 0xc0) code += PRIV(utf8_table4)[code[-1] & 0x3f];        if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);
2080        break;        break;
2081        }        }
2082  #else  #else
2083      (void)(utf8);  /* Keep compiler happy by referencing function argument */      (void)(utf);  /* Keep compiler happy by referencing function argument */
2084  #endif  #endif
2085      }      }
2086    }    }
# Line 2042  instance of OP_RECURSE. Line 2097  instance of OP_RECURSE.
2097    
2098  Arguments:  Arguments:
2099    code        points to start of expression    code        points to start of expression
2100    utf8        TRUE in UTF-8 mode    utf         TRUE in UTF-8 / UTF-16 mode
2101    
2102  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found
2103  */  */
2104    
2105  static const pcre_uchar *  static const pcre_uchar *
2106  find_recurse(const pcre_uchar *code, BOOL utf8)  find_recurse(const pcre_uchar *code, BOOL utf)
2107  {  {
2108  for (;;)  for (;;)
2109    {    {
# Line 2110  for (;;) Line 2165  for (;;)
2165      by a multi-byte character. The length in the table is a minimum, so we have      by a multi-byte character. The length in the table is a minimum, so we have
2166      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
2167    
2168  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2169      if (utf8) switch(c)      if (utf) switch(c)
2170        {        {
2171        case OP_CHAR:        case OP_CHAR:
2172        case OP_CHARI:        case OP_CHARI:
# Line 2141  for (;;) Line 2196  for (;;)
2196        case OP_MINQUERYI:        case OP_MINQUERYI:
2197        case OP_POSQUERY:        case OP_POSQUERY:
2198        case OP_POSQUERYI:        case OP_POSQUERYI:
2199        if (code[-1] >= 0xc0) code += PRIV(utf8_table4)[code[-1] & 0x3f];        if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);
2200        break;        break;
2201        }        }
2202  #else  #else
2203      (void)(utf8);  /* Keep compiler happy by referencing function argument */      (void)(utf);  /* Keep compiler happy by referencing function argument */
2204  #endif  #endif
2205      }      }
2206    }    }
# Line 2168  bracket whose current branch will alread Line 2223  bracket whose current branch will alread
2223  Arguments:  Arguments:
2224    code        points to start of search    code        points to start of search
2225    endcode     points to where to stop    endcode     points to where to stop
2226    utf8        TRUE if in UTF8 mode    utf         TRUE if in UTF-8 / UTF-16 mode
2227    cd          contains pointers to tables etc.    cd          contains pointers to tables etc.
2228    
2229  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2176  Returns:      TRUE if what is matched co Line 2231  Returns:      TRUE if what is matched co
2231    
2232  static BOOL  static BOOL
2233  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2234    BOOL utf8, compile_data *cd)    BOOL utf, compile_data *cd)
2235  {  {
2236  register int c;  register int c;
2237  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
# Line 2224  for (code = first_significant_code(code Line 2279  for (code = first_significant_code(code
2279    
2280      do      do
2281        {        {
2282        if (could_be_empty_branch(scode, endcode, utf8, cd))        if (could_be_empty_branch(scode, endcode, utf, cd))
2283          {          {
2284          empty_branch = TRUE;          empty_branch = TRUE;
2285          break;          break;
# Line 2280  for (code = first_significant_code(code Line 2335  for (code = first_significant_code(code
2335        empty_branch = FALSE;        empty_branch = FALSE;
2336        do        do
2337          {          {
2338          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd))
2339            empty_branch = TRUE;            empty_branch = TRUE;
2340          code += GET(code, 1);          code += GET(code, 1);
2341          }          }
# Line 2302  for (code = first_significant_code(code Line 2357  for (code = first_significant_code(code
2357      actual length is stored in the compiled code, so we must update "code"      actual length is stored in the compiled code, so we must update "code"
2358      here. */      here. */
2359    
2360  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2361      case OP_XCLASS:      case OP_XCLASS:
2362      ccode = code += GET(code, 1);      ccode = code += GET(code, 1);
2363      goto CHECK_CLASS_REPEAT;      goto CHECK_CLASS_REPEAT;
# Line 2312  for (code = first_significant_code(code Line 2367  for (code = first_significant_code(code
2367      case OP_NCLASS:      case OP_NCLASS:
2368      ccode = code + PRIV(OP_lengths)[OP_CLASS];      ccode = code + PRIV(OP_lengths)[OP_CLASS];
2369    
2370  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2371      CHECK_CLASS_REPEAT:      CHECK_CLASS_REPEAT:
2372  #endif  #endif
2373    
# Line 2401  for (code = first_significant_code(code Line 2456  for (code = first_significant_code(code
2456      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,
2457      MINUPTO, and POSUPTO may be followed by a multibyte character */      MINUPTO, and POSUPTO may be followed by a multibyte character */
2458    
2459  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2460      case OP_STAR:      case OP_STAR:
2461      case OP_STARI:      case OP_STARI:
2462      case OP_MINSTAR:      case OP_MINSTAR:
# Line 2414  for (code = first_significant_code(code Line 2469  for (code = first_significant_code(code
2469      case OP_MINQUERYI:      case OP_MINQUERYI:
2470      case OP_POSQUERY:      case OP_POSQUERY:
2471      case OP_POSQUERYI:      case OP_POSQUERYI:
2472      if (utf8 && code[1] >= 0xc0) code += PRIV(utf8_table4)[code[1] & 0x3f];      if (utf && HAS_EXTRALEN(code[1])) code += GET_EXTRALEN(code[1]);
2473      break;      break;
2474    
2475      case OP_UPTO:      case OP_UPTO:
# Line 2423  for (code = first_significant_code(code Line 2478  for (code = first_significant_code(code
2478      case OP_MINUPTOI:      case OP_MINUPTOI:
2479      case OP_POSUPTO:      case OP_POSUPTO:
2480      case OP_POSUPTOI:      case OP_POSUPTOI:
2481      if (utf8 && code[1 + IMM2_SIZE] >= 0xc0) code += PRIV(utf8_table4)[code[1 + IMM2_SIZE] & 0x3f];      if (utf && HAS_EXTRALEN(code[1 + IMM2_SIZE])) code += GET_EXTRALEN(code[1 + IMM2_SIZE]);
2482      break;      break;
2483  #endif  #endif
2484    
# Line 2467  Arguments: Line 2522  Arguments:
2522    code        points to start of the recursion    code        points to start of the recursion
2523    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2524    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2525    utf8        TRUE if in UTF-8 mode    utf         TRUE if in UTF-8 / UTF-16 mode
2526    cd          pointers to tables etc    cd          pointers to tables etc
2527    
2528  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2475  Returns:      TRUE if what is matched co Line 2530  Returns:      TRUE if what is matched co
2530    
2531  static BOOL  static BOOL
2532  could_be_empty(const pcre_uchar *code, const pcre_uchar *endcode,  could_be_empty(const pcre_uchar *code, const pcre_uchar *endcode,
2533    branch_chain *bcptr, BOOL utf8, compile_data *cd)    branch_chain *bcptr, BOOL utf, compile_data *cd)
2534  {  {
2535  while (bcptr != NULL && bcptr->current_branch >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2536    {    {
2537    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf, cd))
2538      return FALSE;      return FALSE;
2539    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2540    }    }
# Line 2614  value in the reference (which is a group Line 2669  value in the reference (which is a group
2669  Arguments:  Arguments:
2670    group      points to the start of the group    group      points to the start of the group
2671    adjust     the amount by which the group is to be moved    adjust     the amount by which the group is to be moved
2672    utf8       TRUE in UTF-8 mode    utf        TRUE in UTF-8 / UTF-16 mode
2673    cd         contains pointers to tables etc.    cd         contains pointers to tables etc.
2674    save_hwm   the hwm forward reference pointer at the start of the group    save_hwm   the hwm forward reference pointer at the start of the group
2675    
# Line 2622  Returns:     nothing Line 2677  Returns:     nothing
2677  */  */
2678    
2679  static void  static void
2680  adjust_recurse(pcre_uchar *group, int adjust, BOOL utf8, compile_data *cd,  adjust_recurse(pcre_uchar *group, int adjust, BOOL utf, compile_data *cd,
2681    pcre_uchar *save_hwm)    pcre_uchar *save_hwm)
2682  {  {
2683  pcre_uchar *ptr = group;  pcre_uchar *ptr = group;
2684    
2685  while ((ptr = (pcre_uchar *)find_recurse(ptr, utf8)) != NULL)  while ((ptr = (pcre_uchar *)find_recurse(ptr, utf)) != NULL)
2686    {    {
2687    int offset;    int offset;
2688    pcre_uchar *hc;    pcre_uchar *hc;
# Line 2833  sense to automatically possessify the re Line 2888  sense to automatically possessify the re
2888    
2889  Arguments:  Arguments:
2890    previous      pointer to the repeated opcode    previous      pointer to the repeated opcode
2891    utf8          TRUE in UTF-8 mode    utf           TRUE in UTF-8 / UTF-16 mode
2892    ptr           next character in pattern    ptr           next character in pattern
2893    options       options bits    options       options bits
2894    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
# Line 2842  Returns:        TRUE if possessifying is Line 2897  Returns:        TRUE if possessifying is
2897  */  */
2898    
2899  static BOOL  static BOOL
2900  check_auto_possessive(const pcre_uchar *previous, BOOL utf8,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
2901    const pcre_uchar *ptr, int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
2902  {  {
2903  int c, next;  pcre_int32 c, next;
2904  int op_code = *previous++;  int op_code = *previous++;
2905    
2906  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
# Line 2862  if ((options & PCRE_EXTENDED) != 0) Line 2917  if ((options & PCRE_EXTENDED) != 0)
2917          {          {
2918          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2919          ptr++;          ptr++;
2920  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2921          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) FORWARDCHAR(ptr);
2922  #endif  #endif
2923          }          }
2924        }        }
# Line 2881  if (*ptr == CHAR_BACKSLASH) Line 2936  if (*ptr == CHAR_BACKSLASH)
2936    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
2937    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
2938    }    }
2939    else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
 else if ((cd->ctypes[*ptr] & ctype_meta) == 0)  
2940    {    {
2941  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2942    if (utf8) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
2943  #endif  #endif
2944    next = *ptr++;    next = *ptr++;
2945    }    }
   
2946  else return FALSE;  else return FALSE;
2947    
2948  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
# Line 2906  if ((options & PCRE_EXTENDED) != 0) Line 2959  if ((options & PCRE_EXTENDED) != 0)
2959          {          {
2960          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2961          ptr++;          ptr++;
2962  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2963          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) FORWARDCHAR(ptr);
2964  #endif  #endif
2965          }          }
2966        }        }
# Line 2927  the next item is a character. */ Line 2980  the next item is a character. */
2980  if (next >= 0) switch(op_code)  if (next >= 0) switch(op_code)
2981    {    {
2982    case OP_CHAR:    case OP_CHAR:
2983  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2984    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
2985  #else  #else
2986    c = *previous;    c = *previous;
# Line 2939  if (next >= 0) switch(op_code) Line 2992  if (next >= 0) switch(op_code)
2992    high-valued characters. */    high-valued characters. */
2993    
2994    case OP_CHARI:    case OP_CHARI:
2995  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2996    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
2997  #else  #else
2998    c = *previous;    c = *previous;
2999  #endif  #endif
3000    if (c == next) return FALSE;    if (c == next) return FALSE;
3001  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3002    if (utf8)    if (utf)
3003      {      {
3004      unsigned int othercase;      unsigned int othercase;
3005      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 2958  if (next >= 0) switch(op_code) Line 3011  if (next >= 0) switch(op_code)
3011      return (unsigned int)c != othercase;      return (unsigned int)c != othercase;
3012      }      }
3013    else    else
3014  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
3015    return (c != cd->fcc[next]);  /* Non-UTF-8 mode */    return (c != cd->fcc[next]);  /* Non-UTF-8 mode */
3016    
3017    /* For OP_NOT and OP_NOTI, the data is always a single-byte character. These    /* For OP_NOT and OP_NOTI, the data is always a single-byte character. These
# Line 2970  if (next >= 0) switch(op_code) Line 3023  if (next >= 0) switch(op_code)
3023    
3024    case OP_NOTI:    case OP_NOTI:
3025    if ((c = *previous) == next) return TRUE;    if ((c = *previous) == next) return TRUE;
3026  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3027    if (utf8)    if (utf)
3028      {      {
3029      unsigned int othercase;      unsigned int othercase;
3030      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 2983  if (next >= 0) switch(op_code) Line 3036  if (next >= 0) switch(op_code)
3036      return (unsigned int)c == othercase;      return (unsigned int)c == othercase;
3037      }      }
3038    else    else
3039  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
3040    return (c == cd->fcc[next]);  /* Non-UTF-8 mode */    return (c == cd->fcc[next]);  /* Non-UTF-8 mode */
3041    
3042    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.
# Line 3075  switch(op_code) Line 3128  switch(op_code)
3128    {    {
3129    case OP_CHAR:    case OP_CHAR:
3130    case OP_CHARI:    case OP_CHARI:
3131  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3132    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
3133  #else  #else
3134    c = *previous;    c = *previous;
# Line 3258  Arguments: Line 3311  Arguments:
3311    codeptr        points to the pointer to the current code point    codeptr        points to the pointer to the current code point
3312    ptrptr         points to the current pattern pointer    ptrptr         points to the current pattern pointer
3313    errorcodeptr   points to error code variable    errorcodeptr   points to error code variable
3314    firstbyteptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)
3315    reqbyteptr     set to the last literal character required, else < 0    reqcharptr     set to the last literal character required, else < 0
3316    bcptr          points to current branch chain    bcptr          points to current branch chain
3317    cond_depth     conditional nesting depth    cond_depth     conditional nesting depth
3318    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
# Line 3272  Returns:         TRUE on success Line 3325  Returns:         TRUE on success
3325    
3326  static BOOL  static BOOL
3327  compile_branch(int *optionsptr, pcre_uchar **codeptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3328    const pcre_uchar **ptrptr, int *errorcodeptr, int *firstbyteptr,    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,
3329    int *reqbyteptr, branch_chain *bcptr, int cond_depth, compile_data *cd,    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,
3330    int *lengthptr)    compile_data *cd, int *lengthptr)
3331  {  {
3332  int repeat_type, op_type;  int repeat_type, op_type;
3333  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3334  int bravalue = 0;  int bravalue = 0;
3335  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3336  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
3337  int zeroreqbyte, zerofirstbyte;  pcre_int32 zeroreqchar, zerofirstchar;
3338  int req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3339  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3340  int after_manual_callout = 0;  int after_manual_callout = 0;
3341  int length_prevgroup = 0;  int length_prevgroup = 0;
# Line 3292  pcre_uchar *last_code = code; Line 3345  pcre_uchar *last_code = code;
3345  pcre_uchar *orig_code = code;  pcre_uchar *orig_code = code;
3346  pcre_uchar *tempcode;  pcre_uchar *tempcode;
3347  BOOL inescq = FALSE;  BOOL inescq = FALSE;
3348  BOOL groupsetfirstbyte = FALSE;  BOOL groupsetfirstchar = FALSE;
3349  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
3350  const pcre_uchar *tempptr;  const pcre_uchar *tempptr;
3351  const pcre_uchar *nestptr = NULL;  const pcre_uchar *nestptr = NULL;
# Line 3305  pcre_uint8 classbits[32]; Line 3358  pcre_uint8 classbits[32];
3358  must not do this for other options (e.g. PCRE_EXTENDED) because they may change  must not do this for other options (e.g. PCRE_EXTENDED) because they may change
3359  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3360    
3361  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3362  BOOL utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
3363  pcre_uint8 utf8_char[6];  BOOL utf = (options & PCRE_UTF8) != 0;
3364    pcre_uchar utf_chars[6];
3365  #else  #else
3366  BOOL utf8 = FALSE;  BOOL utf = FALSE;
3367  #endif  #endif
3368    
3369  /* Helper variables for OP_XCLASS opcode (for characters > 255). */  /* Helper variables for OP_XCLASS opcode (for characters > 255). */
# Line 3331  greedy_non_default = greedy_default ^ 1; Line 3385  greedy_non_default = greedy_default ^ 1;
3385    
3386  /* Initialize no first byte, no required byte. REQ_UNSET means "no char  /* Initialize no first byte, no required byte. REQ_UNSET means "no char
3387  matching encountered yet". It gets changed to REQ_NONE if we hit something that  matching encountered yet". It gets changed to REQ_NONE if we hit something that
3388  matches a non-fixed char first char; reqbyte just remains unset if we never  matches a non-fixed char first char; reqchar just remains unset if we never
3389  find one.  find one.
3390    
3391  When we hit a repeat whose minimum is zero, we may have to adjust these values  When we hit a repeat whose minimum is zero, we may have to adjust these values
3392  to take the zero repeat into account. This is implemented by setting them to  to take the zero repeat into account. This is implemented by setting them to
3393  zerofirstbyte and zeroreqbyte when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3394  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3395    
3396  firstbyte = reqbyte = zerofirstbyte = zeroreqbyte = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;
3397    
3398  /* The variable req_caseopt contains either the REQ_CASELESS value or zero,  /* The variable req_caseopt contains either the REQ_CASELESS value
3399  according to the current setting of the caseless flag. REQ_CASELESS is a bit  or zero, according to the current setting of the caseless flag. The
3400  value > 255. It is added into the firstbyte or reqbyte variables to record the  REQ_CASELESS leaves the lower 28 bit empty. It is added into the
3401  case status of the value. This is used only for ASCII characters. */  firstchar or reqchar variables to record the case status of the
3402    value. This is used only for ASCII characters. */
3403    
3404  req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;  req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS:0;
3405    
3406  /* Switch on next character until the end of the branch */  /* Switch on next character until the end of the branch */
3407    
# Line 3364  for (;; ptr++) Line 3419  for (;; ptr++)
3419    int recno;    int recno;
3420    int refsign;    int refsign;
3421    int skipbytes;    int skipbytes;
3422    int subreqbyte;    int subreqchar;
3423    int subfirstbyte;    int subfirstchar;
3424    int terminator;    int terminator;
3425    int mclength;    int mclength;
3426    int tempbracount;    int tempbracount;
3427    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3428    
3429    /* Get next byte in the pattern */    /* Get next character in the pattern */
3430    
3431    c = *ptr;    c = *ptr;
3432    
# Line 3416  for (;; ptr++) Line 3471  for (;; ptr++)
3471        }        }
3472    
3473      *lengthptr += (int)(code - last_code);      *lengthptr += (int)(code - last_code);
3474      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, (int)(code - last_code),      DPRINTF(("length=%d added %d c=%c (0x%x)\n", *lengthptr,
3475        c));        (int)(code - last_code), c, c));
3476    
3477      /* If "previous" is set and it is not at the start of the work space, move      /* If "previous" is set and it is not at the start of the work space, move
3478      it back to there, in order to avoid filling up the work space. Otherwise,      it back to there, in order to avoid filling up the work space. Otherwise,
# Line 3503  for (;; ptr++) Line 3558  for (;; ptr++)
3558          {          {
3559          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3560          ptr++;          ptr++;
3561  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3562          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) FORWARDCHAR(ptr);
3563  #endif  #endif
3564          }          }
3565        if (*ptr != 0) continue;        if (*ptr != 0) continue;
# Line 3528  for (;; ptr++) Line 3583  for (;; ptr++)
3583      case 0:                        /* The branch terminates at string end */      case 0:                        /* The branch terminates at string end */
3584      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3585      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3586      *firstbyteptr = firstbyte;      *firstcharptr = firstchar;
3587      *reqbyteptr = reqbyte;      *reqcharptr = reqchar;
3588      *codeptr = code;      *codeptr = code;
3589      *ptrptr = ptr;      *ptrptr = ptr;
3590      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3553  for (;; ptr++) Line 3608  for (;; ptr++)
3608      previous = NULL;      previous = NULL;
3609      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3610        {        {
3611        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3612        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3613        }        }
3614      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3565  for (;; ptr++) Line 3620  for (;; ptr++)
3620      break;      break;
3621    
3622      /* There can never be a first char if '.' is first, whatever happens about      /* There can never be a first char if '.' is first, whatever happens about
3623      repeats. The value of reqbyte doesn't change either. */      repeats. The value of reqchar doesn't change either. */
3624    
3625      case CHAR_DOT:      case CHAR_DOT:
3626      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3627      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
3628      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
3629      previous = code;      previous = code;
3630      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
3631      break;      break;
# Line 3644  for (;; ptr++) Line 3699  for (;; ptr++)
3699          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
3700        {        {
3701        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
3702        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3703        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
3704        break;        break;
3705        }        }
3706    
# Line 3683  for (;; ptr++) Line 3738  for (;; ptr++)
3738        {        {
3739        const pcre_uchar *oldptr;        const pcre_uchar *oldptr;
3740    
3741  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3742        if (utf8 && c > 127)        if (utf && HAS_EXTRALEN(c))
3743          {                           /* Braces are required because the */          {                           /* Braces are required because the */
3744          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
3745          }          }
# Line 3902  for (;; ptr++) Line 3957  for (;; ptr++)
3957              SETBIT(classbits, 0x20); /* SPACE */              SETBIT(classbits, 0x20); /* SPACE */
3958              SETBIT(classbits, 0xa0); /* NSBP */              SETBIT(classbits, 0xa0); /* NSBP */
3959  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3960              if (utf8)              if (utf)
3961                {                {
3962                xclass = TRUE;                xclass = TRUE;
3963                *class_uchardata++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3964                class_uchardata += PRIV(ord2utf8)(0x1680, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x1680, class_uchardata);
3965                *class_uchardata++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3966                class_uchardata += PRIV(ord2utf8)(0x180e, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x180e, class_uchardata);
3967                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
3968                class_uchardata += PRIV(ord2utf8)(0x2000, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2000, class_uchardata);
3969                class_uchardata += PRIV(ord2utf8)(0x200A, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x200A, class_uchardata);
3970                *class_uchardata++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3971                class_uchardata += PRIV(ord2utf8)(0x202f, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x202f, class_uchardata);
3972                *class_uchardata++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3973                class_uchardata += PRIV(ord2utf8)(0x205f, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x205f, class_uchardata);
3974                *class_uchardata++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3975                class_uchardata += PRIV(ord2utf8)(0x3000, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);
3976                }                }
3977  #endif  #endif
3978              continue;              continue;
# Line 3937  for (;; ptr++) Line 3992  for (;; ptr++)
3992                }                }
3993    
3994  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3995              if (utf8)              if (utf)
3996                {                {
3997                xclass = TRUE;                xclass = TRUE;
3998                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
3999                class_uchardata += PRIV(ord2utf8)(0x0100, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);
4000                class_uchardata += PRIV(ord2utf8)(0x167f, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x167f, class_uchardata);
4001                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4002                class_uchardata += PRIV(ord2utf8)(0x1681, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x1681, class_uchardata);
4003                class_uchardata += PRIV(ord2utf8)(0x180d, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x180d, class_uchardata);
4004                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4005                class_uchardata += PRIV(ord2utf8)(0x180f, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x180f, class_uchardata);
4006                class_uchardata += PRIV(ord2utf8)(0x1fff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x1fff, class_uchardata);
4007                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4008                class_uchardata += PRIV(ord2utf8)(0x200B, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x200B, class_uchardata);
4009                class_uchardata += PRIV(ord2utf8)(0x202e, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x202e, class_uchardata);
4010                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4011                class_uchardata += PRIV(ord2utf8)(0x2030, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2030, class_uchardata);
4012                class_uchardata += PRIV(ord2utf8)(0x205e, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x205e, class_uchardata);
4013                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4014                class_uchardata += PRIV(ord2utf8)(0x2060, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2060, class_uchardata);
4015                class_uchardata += PRIV(ord2utf8)(0x2fff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2fff, class_uchardata);
4016                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4017                class_uchardata += PRIV(ord2utf8)(0x3001, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x3001, class_uchardata);
4018                class_uchardata += PRIV(ord2utf8)(0x7fffffff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4019                }                }
4020  #endif  #endif
4021              continue;              continue;
# Line 3972  for (;; ptr++) Line 4027  for (;; ptr++)
4027              SETBIT(classbits, 0x0d); /* CR */              SETBIT(classbits, 0x0d); /* CR */
4028              SETBIT(classbits, 0x85); /* NEL */              SETBIT(classbits, 0x85); /* NEL */
4029  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4030              if (utf8)              if (utf)
4031                {                {
4032                xclass = TRUE;                xclass = TRUE;
4033                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4034                class_uchardata += PRIV(ord2utf8)(0x2028, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2028, class_uchardata);
4035                class_uchardata += PRIV(ord2utf8)(0x2029, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4036                }                }
4037  #endif  #endif
4038              continue;              continue;
# Line 4000  for (;; ptr++) Line 4055  for (;; ptr++)
4055                }                }
4056    
4057  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4058              if (utf8)              if (utf)
4059                {                {
4060                xclass = TRUE;                xclass = TRUE;
4061                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4062                class_uchardata += PRIV(ord2utf8)(0x0100, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);
4063                class_uchardata += PRIV(ord2utf8)(0x2027, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2027, class_uchardata);
4064                *class_uchardata++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4065                class_uchardata += PRIV(ord2utf8)(0x2029, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4066                class_uchardata += PRIV(ord2utf8)(0x7fffffff, class_uchardata);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4067                }                }
4068  #endif  #endif
4069              continue;              continue;
# Line 4095  for (;; ptr++) Line 4150  for (;; ptr++)
4150            goto LONE_SINGLE_CHARACTER;            goto LONE_SINGLE_CHARACTER;
4151            }            }
4152    
4153  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4154          if (utf8)          if (utf)
4155            {                           /* Braces are required because the */            {                           /* Braces are required because the */
4156            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */
4157            }            }
# Line 4145  for (;; ptr++) Line 4200  for (;; ptr++)
4200          matching for characters > 127 is available only if UCP support is          matching for characters > 127 is available only if UCP support is
4201          available. */          available. */
4202    
4203  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)
4204          if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))          if ((d > 255) || (utf && ((options & PCRE_CASELESS) != 0 && d > 127)))
4205  #endif  #elif defined  SUPPORT_UTF
4206  #ifndef COMPILE_PCRE8          if (utf && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))
4207    #elif !(defined COMPILE_PCRE8)
4208          if (d > 255)          if (d > 255)
4209  #endif  #endif
4210  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
4211            {            {
4212            xclass = TRUE;            xclass = TRUE;
4213    
# Line 4160  for (;; ptr++) Line 4216  for (;; ptr++)
4216            they fit with the basic range. */            they fit with the basic range. */
4217    
4218  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4219    #ifndef COMPILE_PCRE8
4220              if (utf && (options & PCRE_CASELESS) != 0)
4221    #else
4222            if ((options & PCRE_CASELESS) != 0)            if ((options & PCRE_CASELESS) != 0)
4223    #endif
4224              {              {
4225              unsigned int occ, ocd;              unsigned int occ, ocd;
4226              unsigned int cc = c;              unsigned int cc = c;
# Line 4191  for (;; ptr++) Line 4251  for (;; ptr++)
4251                else                else
4252                  {                  {
4253                  *class_uchardata++ = XCL_RANGE;                  *class_uchardata++ = XCL_RANGE;
4254                  class_uchardata += PRIV(ord2utf8)(occ, class_uchardata);                  class_uchardata += PRIV(ord2utf)(occ, class_uchardata);
4255                  }                  }
4256                class_uchardata += PRIV(ord2utf8)(ocd, class_uchardata);                class_uchardata += PRIV(ord2utf)(ocd, class_uchardata);
4257                }                }
4258              }              }
4259  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 4203  for (;; ptr++) Line 4263  for (;; ptr++)
4263    
4264            *class_uchardata++ = XCL_RANGE;            *class_uchardata++ = XCL_RANGE;
4265  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4266            class_uchardata += PRIV(ord2utf8)(c, class_uchardata);  #ifndef COMPILE_PCRE8
4267            class_uchardata += PRIV(ord2utf8)(d, class_uchardata);            if (utf)
4268                {
4269                class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4270                class_uchardata += PRIV(ord2utf)(d, class_uchardata);
4271                }
4272              else
4273                {
4274                *class_uchardata++ = c;
4275                *class_uchardata++ = d;
4276                }
4277  #else  #else
4278              class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4279              class_uchardata += PRIV(ord2utf)(d, class_uchardata);
4280    #endif
4281    #else /* SUPPORT_UTF */
4282            *class_uchardata++ = c;            *class_uchardata++ = c;
4283            *class_uchardata++ = d;            *class_uchardata++ = d;
4284  #endif  #endif /* SUPPORT_UTF */
4285    
4286            /* With UCP support, we are done. Without UCP support, there is no            /* With UCP support, we are done. Without UCP support, there is no
4287            caseless matching for UTF characters > 127; we can use the bit map            caseless matching for UTF characters > 127; we can use the bit map
# Line 4216  for (;; ptr++) Line 4289  for (;; ptr++)
4289            can still use  */            can still use  */
4290    
4291  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4292            continue;    /* With next character in the class */  #ifndef COMPILE_PCRE8
4293  #else            if (utf)
4294  #ifdef SUPPORT_UTF  #endif
4295                continue;    /* With next character in the class */
4296    #endif  /* SUPPORT_UCP */
4297    
4298    #if defined SUPPORT_UTF && !defined(SUPPORT_UCP) && !(defined COMPILE_PCRE8)
4299              if (utf)
4300                {
4301                if ((options & PCRE_CASELESS) == 0 || c > 127) continue;
4302                /* Adjust upper limit and fall through to set up the map */
4303                d = 127;
4304                }
4305              else
4306                {
4307                if (c > 255) continue;
4308                /* Adjust upper limit and fall through to set up the map */
4309                d = 255;
4310                }
4311    #elif defined SUPPORT_UTF && !defined(SUPPORT_UCP)
4312            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;
4313            /* Adjust upper limit and fall through to set up the map */            /* Adjust upper limit and fall through to set up the map */
4314            d = 127;            d = 127;
# Line 4226  for (;; ptr++) Line 4316  for (;; ptr++)
4316            if (c > 255) continue;            if (c > 255) continue;
4317            /* Adjust upper limit and fall through to set up the map */            /* Adjust upper limit and fall through to set up the map */
4318            d = 255;            d = 255;
4319  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF && !SUPPORT_UCP && !COMPILE_PCRE8 */
 #endif  /* SUPPORT_UCP */  
4320            }            }
4321  #endif  /* SUPPORT_UTF8 || COMPILE_PCRE16 */  #endif  /* SUPPORT_UTF || !COMPILE_PCRE8 */
4322    
4323          /* We use the bit map for 8 bit mode, or when the characters fall          /* We use the bit map for 8 bit mode, or when the characters fall
4324          partially or entirely to [0-255] ([0-127] for UCP) ranges. */          partially or entirely to [0-255] ([0-127] for UCP) ranges. */
# Line 4260  for (;; ptr++) Line 4349  for (;; ptr++)
4349    
4350        /* Handle a character that cannot go in the bit map */        /* Handle a character that cannot go in the bit map */
4351    
4352  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)
4353        if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))        if ((c > 255) || (utf && ((options & PCRE_CASELESS) != 0 && c > 127)))
4354  #endif  #elif defined SUPPORT_UTF
4355  #ifndef COMPILE_PCRE8        if (utf && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))
4356    #elif !(defined COMPILE_PCRE8)
4357        if (c > 255)        if (c > 255)
4358  #endif  #endif
4359  #if defined SUPPORT_UTF || defined COMPILE_PCRE16  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
4360          {          {
4361          xclass = TRUE;          xclass = TRUE;
4362          *class_uchardata++ = XCL_SINGLE;          *class_uchardata++ = XCL_SINGLE;
4363  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4364          class_uchardata += PRIV(ord2utf8)(c, class_uchardata);  #ifndef COMPILE_PCRE8
4365  #else          /* In non 8 bit mode, we can get here even
4366          *class_uchardata++ = c;          if we are not in UTF mode. */
4367            if (!utf)
4368              *class_uchardata++ = c;
4369            else
4370  #endif  #endif
4371              class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4372    #else /* SUPPORT_UTF */
4373            *class_uchardata++ = c;
4374    #endif /* SUPPORT_UTF */
4375    
4376  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4377    #ifdef COMPILE_PCRE8
4378          if ((options & PCRE_CASELESS) != 0)          if ((options & PCRE_CASELESS) != 0)
4379    #else
4380            /* In non 8 bit mode, we can get here even
4381            if we are not in UTF mode. */
4382            if (utf && (options & PCRE_CASELESS) != 0)
4383    #endif
4384            {            {
4385            unsigned int othercase;            unsigned int othercase;
4386            if ((othercase = UCD_OTHERCASE(c)) != c)            if ((othercase = UCD_OTHERCASE(c)) != c)
4387              {              {
4388              *class_uchardata++ = XCL_SINGLE;              *class_uchardata++ = XCL_SINGLE;
4389              class_uchardata += PRIV(ord2utf8)(othercase, class_uchardata);              class_uchardata += PRIV(ord2utf)(othercase, class_uchardata);
4390              }              }
4391            }            }
4392  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
4393    
4394          }          }
4395        else        else
4396  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF || COMPILE_PCRE16 */
   
4397        /* Handle a single-byte character */        /* Handle a single-byte character */
4398          {          {
4399          classbits[c/8] |= (1 << (c&7));          classbits[c/8] |= (1 << (c&7));
# Line 4303  for (;; ptr++) Line 4405  for (;; ptr++)
4405          class_charcount++;          class_charcount++;
4406          class_lastchar = c;          class_lastchar = c;
4407          }          }
4408    
4409        }        }
4410    
4411      /* Loop until ']' reached. This "while" is the end of the "do" far above.      /* Loop until ']' reached. This "while" is the end of the "do" far above.
# Line 4335  for (;; ptr++) Line 4438  for (;; ptr++)
4438      The optimization throws away the bit map. We turn the item into a      The optimization throws away the bit map. We turn the item into a
4439      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.
4440      Note that OP_NOT[I] does not support multibyte characters. In the positive      Note that OP_NOT[I] does not support multibyte characters. In the positive
4441      case, it can cause firstbyte to be set. Otherwise, there can be no first      case, it can cause firstchar to be set. Otherwise, there can be no first
4442      char if this item is first, whatever repeat count may follow. In the case      char if this item is first, whatever repeat count may follow. In the case
4443      of reqbyte, save the previous value for reinstating. */      of reqchar, save the previous value for reinstating. */
4444    
4445  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4446      if (class_charcount == 1 && !xclass &&      if (class_charcount == 1 && !xclass &&
4447        (!utf8 || !negate_class || class_lastchar < 128))        (!utf || !negate_class || class_lastchar < 128))
 #elif defined COMPILE_PCRE8  
     if (class_charcount == 1)  
4448  #else  #else
4449      if (class_charcount == 1 && !xclass)      if (class_charcount == 1)
4450  #endif  #endif
4451        {        {
4452        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
4453    
4454        /* The OP_NOT[I] opcodes work on one-byte characters only. */        /* The OP_NOT[I] opcodes work on one-byte characters only. */
4455    
4456        if (negate_class)        if (negate_class)
4457          {          {
4458          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4459          zerofirstbyte = firstbyte;          zerofirstchar = firstchar;
4460          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4461          *code++ = class_lastchar;          *code++ = class_lastchar;
4462          break;          break;
# Line 4364  for (;; ptr++) Line 4465  for (;; ptr++)
4465        /* For a single, positive character, get the value into mcbuffer, and        /* For a single, positive character, get the value into mcbuffer, and
4466        then we can handle this with the normal one-character code. */        then we can handle this with the normal one-character code. */
4467    
4468  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4469        if (utf8 && class_lastchar > 127)        if (utf && class_lastchar > 127)
4470          mclength = PRIV(ord2utf8)(class_lastchar, mcbuffer);          mclength = PRIV(ord2utf)(class_lastchar, mcbuffer);
4471        else        else
4472  #endif  #endif
4473          {          {
# Line 4378  for (;; ptr++) Line 4479  for (;; ptr++)
4479    
4480      /* The general case - not the one-char optimization. If this is the first      /* The general case - not the one-char optimization. If this is the first
4481      thing in the branch, there can be no first char setting, whatever the      thing in the branch, there can be no first char setting, whatever the
4482      repeat count. Any reqbyte setting must remain unchanged after any kind of      repeat count. Any reqchar setting must remain unchanged after any kind of
4483      repeat. */      repeat. */
4484    
4485      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4486      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
4487      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
4488    
4489      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4490      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 4476  for (;; ptr++) Line 4577  for (;; ptr++)
4577    
4578      if (repeat_min == 0)      if (repeat_min == 0)
4579        {        {
4580        firstbyte = zerofirstbyte;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4581        reqbyte = zeroreqbyte;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4582        }        }
4583    
4584      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4542  for (;; ptr++) Line 4643  for (;; ptr++)
4643    
4644      /* If previous was a character match, abolish the item and generate a      /* If previous was a character match, abolish the item and generate a
4645      repeat item instead. If a char item has a minumum of more than one, ensure      repeat item instead. If a char item has a minumum of more than one, ensure
4646      that it is set in reqbyte - it might not be if a sequence such as x{3} is      that it is set in reqchar - it might not be if a sequence such as x{3} is
4647      the first thing in a branch because the x will have gone into firstbyte      the first thing in a branch because the x will have gone into firstchar
4648      instead.  */      instead.  */
4649    
4650      if (*previous == OP_CHAR || *previous == OP_CHARI)      if (*previous == OP_CHAR || *previous == OP_CHARI)
4651        {        {
4652        op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR;        op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR;
4653    
4654        /* Deal with UTF-8 characters that take up more than one byte. It's        /* Deal with UTF characters that take up more than one character. It's
4655        easier to write this out separately than try to macrify it. Use c to        easier to write this out separately than try to macrify it. Use c to
4656        hold the length of the character in bytes, plus 0x80 to flag that it's a        hold the length of the character in bytes, plus UTF_LENGTH to flag that
4657        length rather than a small character. */        it's a length rather than a small character. */
4658    
4659  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4660        if (utf8 && (code[-1] & 0x80) != 0)        if (utf && NOT_FIRSTCHAR(code[-1]))
4661          {          {
4662          pcre_uchar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
4663          while((*lastchar & 0xc0) == 0x80) lastchar--;          BACKCHAR(lastchar);
4664          c = code - lastchar;            /* Length of UTF-8 character */          c = code - lastchar;            /* Length of UTF-8 character */
4665          memcpy(utf8_char, lastchar, c); /* Save the char */          memcpy(utf_chars, lastchar, IN_UCHARS(c)); /* Save the char */
4666          c |= 0x80;                      /* Flag c as a length */          c |= UTF_LENGTH;                /* Flag c as a length */
4667          }          }
4668        else        else
4669  #endif  #endif /* SUPPORT_UTF */
   
       /* Handle the case of a single byte - either with no UTF8 support, or  
       with UTF-8 disabled, or for a UTF-8 character < 128. */  
4670    
4671          /* Handle the case of a single charater - either with no UTF support, or
4672          with UTF disabled, or for a single character UTF character. */
4673          {          {
4674          c = code[-1];          c = code[-1];
4675          if (repeat_min > 1) reqbyte = c | req_caseopt | cd->req_varyopt;          if (repeat_min > 1) reqchar = c | req_caseopt | cd->req_varyopt;
4676          }          }
4677    
4678        /* 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 4582  for (;; ptr++) Line 4682  for (;; ptr++)
4682    
4683        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4684            repeat_max < 0 &&            repeat_max < 0 &&
4685            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4686          {          {
4687          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4688          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4603  for (;; ptr++) Line 4703  for (;; ptr++)
4703        c = previous[1];        c = previous[1];
4704        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4705            repeat_max < 0 &&            repeat_max < 0 &&
4706            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4707          {          {
4708          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4709          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4627  for (;; ptr++) Line 4727  for (;; ptr++)
4727    
4728        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4729            repeat_max < 0 &&            repeat_max < 0 &&
4730            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4731          {          {
4732          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4733          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4707  for (;; ptr++) Line 4807  for (;; ptr++)
4807          we have to insert the character for the previous code. For a repeated          we have to insert the character for the previous code. For a repeated
4808          Unicode property match, there are two extra bytes that define the          Unicode property match, there are two extra bytes that define the
4809          required property. In UTF-8 mode, long characters have their length in          required property. In UTF-8 mode, long characters have their length in
4810          c, with the 0x80 bit as a flag. */          c, with the UTF_LENGTH bit as a flag. */
4811    
4812          if (repeat_max < 0)          if (repeat_max < 0)
4813            {            {
4814  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4815            if (utf8 && c >= 128)            if (utf && (c & UTF_LENGTH) != 0)
4816              {              {
4817              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, IN_UCHARS(c & 7));
4818              code += c & 7;              code += c & 7;
4819              }              }
4820            else            else
# Line 4736  for (;; ptr++) Line 4836  for (;; ptr++)
4836    
4837          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4838            {            {
4839  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4840            if (utf8 && c >= 128)            if (utf && (c & UTF_LENGTH) != 0)
4841              {              {
4842              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, IN_UCHARS(c & 7));
4843              code += c & 7;              code += c & 7;
4844              }              }
4845            else            else
# Line 4766  for (;; ptr++) Line 4866  for (;; ptr++)
4866    
4867        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
4868    
4869  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4870        if (utf8 && c >= 128)        if (utf && (c & UTF_LENGTH) != 0)
4871          {          {
4872          memcpy(code, utf8_char, c & 7);          memcpy(code, utf_chars, IN_UCHARS(c & 7));
4873          code += c & 7;          code += c & 7;
4874          }          }
4875        else        else
# Line 4793  for (;; ptr++) Line 4893  for (;; ptr++)
4893    
4894      else if (*previous == OP_CLASS ||      else if (*previous == OP_CLASS ||
4895               *previous == OP_NCLASS ||               *previous == OP_NCLASS ||
4896  #if defined SUPPORT_UTF8 || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4897               *previous == OP_XCLASS ||               *previous == OP_XCLASS ||
4898  #endif  #endif
4899               *previous == OP_REF ||               *previous == OP_REF ||
# Line 4896  for (;; ptr++) Line 4996  for (;; ptr++)
4996          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */
4997            {            {
4998            *code = OP_END;            *code = OP_END;
4999            adjust_recurse(previous, 1, utf8, cd, save_hwm);            adjust_recurse(previous, 1, utf, cd, save_hwm);
5000            memmove(previous + 1, previous, IN_UCHARS(len));            memmove(previous + 1, previous, IN_UCHARS(len));
5001            code++;            code++;
5002            if (repeat_max == 0)            if (repeat_max == 0)
# Line 4920  for (;; ptr++) Line 5020  for (;; ptr++)
5020            {            {
5021            int offset;            int offset;
5022            *code = OP_END;            *code = OP_END;
5023            adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd, save_hwm);            adjust_recurse(previous, 2 + LINK_SIZE, utf, cd, save_hwm);
5024            memmove(previous + 2 + LINK_SIZE, previous, IN_UCHARS(len));            memmove(previous + 2 + LINK_SIZE, previous, IN_UCHARS(len));
5025            code += 2 + LINK_SIZE;            code += 2 + LINK_SIZE;
5026            *previous++ = OP_BRAZERO + repeat_type;            *previous++ = OP_BRAZERO + repeat_type;
# Line 4971  for (;; ptr++) Line 5071  for (;; ptr++)
5071    
5072            else            else
5073              {              {
5074              if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte;              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;
5075              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5076                {                {
5077                pcre_uchar *hc;                pcre_uchar *hc;
# Line 5122  for (;; ptr++) Line 5222  for (;; ptr++)
5222              pcre_uchar *scode = bracode;              pcre_uchar *scode = bracode;
5223              do              do
5224                {                {
5225                if (could_be_empty_branch(scode, ketcode, utf8, cd))                if (could_be_empty_branch(scode, ketcode, utf, cd))
5226                  {                  {
5227                  *bracode += OP_SBRA - OP_BRA;                  *bracode += OP_SBRA - OP_BRA;
5228                  break;                  break;
# Line 5145  for (;; ptr++) Line 5245  for (;; ptr++)
5245                {                {
5246                int nlen = (int)(code - bracode);                int nlen = (int)(code - bracode);
5247                *code = OP_END;                *code = OP_END;
5248                adjust_recurse(bracode, 1 + LINK_SIZE, utf8, cd, save_hwm);                adjust_recurse(bracode, 1 + LINK_SIZE, utf, cd, save_hwm);
5249                memmove(bracode + 1 + LINK_SIZE, bracode, IN_UCHARS(nlen));                memmove(bracode + 1 + LINK_SIZE, bracode, IN_UCHARS(nlen));
5250                code += 1 + LINK_SIZE;                code += 1 + LINK_SIZE;
5251                nlen += 1 + LINK_SIZE;                nlen += 1 + LINK_SIZE;
# Line 5222  for (;; ptr++) Line 5322  for (;; ptr++)
5322        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5323          {          {
5324          tempcode += PRIV(OP_lengths)[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5325  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
5326          if (utf8 && tempcode[-1] >= 0xc0)          if (utf && HAS_EXTRALEN(tempcode[-1]))
5327            tempcode += PRIV(utf8_table4)[tempcode[-1] & 0x3f];            tempcode += GET_EXTRALEN(tempcode[-1]);
5328  #endif  #endif
5329          }          }
5330    
# Line 5261  for (;; ptr++) Line 5361  for (;; ptr++)
5361    
5362          default:          default:
5363          *code = OP_END;          *code = OP_END;
5364          adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);          adjust_recurse(tempcode, 1 + LINK_SIZE, utf, cd, save_hwm);
5365          memmove(tempcode + 1 + LINK_SIZE, tempcode, IN_UCHARS(len));          memmove(tempcode + 1 + LINK_SIZE, tempcode, IN_UCHARS(len));
5366          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
5367          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
# Line 5274  for (;; ptr++) Line 5374  for (;; ptr++)
5374        }        }
5375    
5376      /* In all case we no longer have a previous item. We also set the      /* In all case we no longer have a previous item. We also set the
5377      "follows varying string" flag for subsequently encountered reqbytes if      "follows varying string" flag for subsequently encountered reqchars if
5378      it isn't already set and we have just passed a varying length item. */      it isn't already set and we have just passed a varying length item. */
5379    
5380      END_REPEAT:      END_REPEAT:
# Line 5352  for (;; ptr++) Line 5452  for (;; ptr++)
5452                }                }
5453              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5454    
5455              /* Do not set firstbyte after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5456              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
5457              }              }
5458    
5459            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5506  for (;; ptr++) Line 5606  for (;; ptr++)
5606          while ((cd->ctypes[*ptr] & ctype_word) != 0)          while ((cd->ctypes[*ptr] & ctype_word) != 0)
5607            {            {
5608            if (recno >= 0)            if (recno >= 0)
5609              recno = ((digitab[*ptr] & ctype_digit) != 0)?              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;
               recno * 10 + *ptr - CHAR_0 : -1;  
5610            ptr++;            ptr++;
5611            }            }
5612          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
# Line 5571  for (;; ptr++) Line 5670  for (;; ptr++)
5670          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
5671    
5672          else if ((i = find_parens(cd, name, namelen,          else if ((i = find_parens(cd, name, namelen,
5673                          (options & PCRE_EXTENDED) != 0, utf8)) > 0)                          (options & PCRE_EXTENDED) != 0, utf)) > 0)
5674            {            {
5675            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
5676            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
# Line 5597  for (;; ptr++) Line 5696  for (;; ptr++)
5696            recno = 0;            recno = 0;
5697            for (i = 1; i < namelen; i++)            for (i = 1; i < namelen; i++)
5698              {              {
5699              if ((digitab[name[i]] & ctype_digit) == 0)              if (!IS_DIGIT(name[i]))
5700                {                {
5701                *errorcodeptr = ERR15;                *errorcodeptr = ERR15;
5702                goto FAILED;                goto FAILED;
# Line 5697  for (;; ptr++) Line 5796  for (;; ptr++)
5796          *code++ = OP_CALLOUT;          *code++ = OP_CALLOUT;
5797            {            {
5798            int n = 0;            int n = 0;
5799            while ((digitab[*(++ptr)] & ctype_digit) != 0)            ptr++;
5800              n = n * 10 + *ptr - CHAR_0;            while(IS_DIGIT(*ptr))
5801                n = n * 10 + *ptr++ - CHAR_0;
5802            if (*ptr != CHAR_RIGHT_PARENTHESIS)            if (*ptr != CHAR_RIGHT_PARENTHESIS)
5803              {              {
5804              *errorcodeptr = ERR39;              *errorcodeptr = ERR39;
# Line 5760  for (;; ptr++) Line 5860  for (;; ptr++)
5860                *errorcodeptr = ERR49;                *errorcodeptr = ERR49;
5861                goto FAILED;                goto FAILED;
5862                }                }
5863              if (namelen + 3 > cd->name_entry_size)              if (namelen + IMM2_SIZE + 1 > cd->name_entry_size)
5864                {                {
5865                cd->name_entry_size = namelen + 3;                cd->name_entry_size = namelen + IMM2_SIZE + 1;
5866                if (namelen > MAX_NAME_SIZE)                if (namelen > MAX_NAME_SIZE)
5867                  {                  {
5868                  *errorcodeptr = ERR48;                  *errorcodeptr = ERR48;
# Line 5791  for (;; ptr++) Line 5891  for (;; ptr++)
5891    
5892              for (i = 0; i < cd->names_found; i++)              for (i = 0; i < cd->names_found; i++)
5893                {                {
5894                int crc = memcmp(name, slot+2, namelen);                int crc = memcmp(name, slot+IMM2_SIZE, IN_UCHARS(namelen));
5895                if (crc == 0)                if (crc == 0)
5896                  {                  {
5897                  if (slot[2+namelen] == 0)                  if (slot[IMM2_SIZE+namelen] == 0)
5898                    {                    {
5899                    if (GET2(slot, 0) != cd->bracount + 1 &&                    if (GET2(slot, 0) != cd->bracount + 1 &&
5900                        (options & PCRE_DUPNAMES) == 0)                        (options & PCRE_DUPNAMES) == 0)
# Line 5846  for (;; ptr++) Line 5946  for (;; ptr++)
5946                }                }
5947    
5948              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
5949              memcpy(slot + 2, name, IN_UCHARS(namelen));              memcpy(slot + IMM2_SIZE, name, IN_UCHARS(namelen));
5950              slot[2 + namelen] = 0;              slot[IMM2_SIZE + namelen] = 0;
5951              }              }
5952            }            }
5953    
# Line 5915  for (;; ptr++) Line 6015  for (;; ptr++)
6015            temp = cd->end_pattern;            temp = cd->end_pattern;
6016            cd->end_pattern = ptr;            cd->end_pattern = ptr;
6017            recno = find_parens(cd, name, namelen,            recno = find_parens(cd, name, namelen,
6018              (options & PCRE_EXTENDED) != 0, utf8);              (options & PCRE_EXTENDED) != 0, utf);
6019            cd->end_pattern = temp;            cd->end_pattern = temp;
6020            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */
6021            }            }
# Line 5931  for (;; ptr++) Line 6031  for (;; ptr++)
6031            for (i = 0; i < cd->names_found; i++)            for (i = 0; i < cd->names_found; i++)
6032              {              {
6033              if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0 &&              if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0 &&
6034                  slot[2+namelen] == 0)                  slot[IMM2_SIZE+namelen] == 0)
6035                break;                break;
6036              slot += cd->name_entry_size;              slot += cd->name_entry_size;
6037              }              }
# Line 5942  for (;; ptr++) Line 6042  for (;; ptr++)
6042              }              }
6043            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
6044                      find_parens(cd, name, namelen,                      find_parens(cd, name, namelen,
6045                        (options & PCRE_EXTENDED) != 0, utf8)) <= 0)                        (options & PCRE_EXTENDED) != 0, utf)) <= 0)
6046              {              {
6047              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
6048              goto FAILED;              goto FAILED;
# Line 5981  for (;; ptr++) Line 6081  for (;; ptr++)
6081            if ((refsign = *ptr) == CHAR_PLUS)            if ((refsign = *ptr) == CHAR_PLUS)
6082              {              {
6083              ptr++;              ptr++;
6084              if ((digitab[*ptr] & ctype_digit) == 0)              if (!IS_DIGIT(*ptr))
6085                {                {
6086                *errorcodeptr = ERR63;                *errorcodeptr = ERR63;
6087                goto FAILED;                goto FAILED;
# Line 5989  for (;; ptr++) Line 6089  for (;; ptr++)
6089              }              }
6090            else if (refsign == CHAR_MINUS)            else if (refsign == CHAR_MINUS)
6091              {              {
6092              if ((digitab[ptr[1]] & ctype_digit) == 0)              if (!IS_DIGIT(ptr[1]))
6093                goto OTHER_CHAR_AFTER_QUERY;                goto OTHER_CHAR_AFTER_QUERY;
6094              ptr++;              ptr++;
6095              }              }
6096    
6097            recno = 0;            recno = 0;
6098            while((digitab[*ptr] & ctype_digit) != 0)            while(IS_DIGIT(*ptr))
6099              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6100    
6101            if (*ptr != terminator)            if (*ptr != terminator)
# Line 6046  for (;; ptr++) Line 6146  for (;; ptr++)
6146              {              {
6147              *code = OP_END;              *code = OP_END;
6148              if (recno != 0)              if (recno != 0)
6149                called = PRIV(find_bracket)(cd->start_code, utf8, recno);                called = PRIV(find_bracket)(cd->start_code, utf, recno);
6150    
6151              /* Forward reference */              /* Forward reference */
6152    
6153              if (called == NULL)              if (called == NULL)
6154                {                {
6155                if (find_parens(cd, NULL, recno,                if (find_parens(cd, NULL, recno,
6156                      (options & PCRE_EXTENDED) != 0, utf8) < 0)                      (options & PCRE_EXTENDED) != 0, utf) < 0)
6157                  {                  {
6158                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
6159                  goto FAILED;                  goto FAILED;
# Line 6077  for (;; ptr++) Line 6177  for (;; ptr++)
6177              conditional subpatterns will be picked up then. */              conditional subpatterns will be picked up then. */
6178    
6179              else if (GET(called, 1) == 0 && cond_depth <= 0 &&              else if (GET(called, 1) == 0 && cond_depth <= 0 &&
6180                       could_be_empty(called, code, bcptr, utf8, cd))                       could_be_empty(called, code, bcptr, utf, cd))
6181                {                {
6182                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
6183                goto FAILED;                goto FAILED;
# Line 6093  for (;; ptr++) Line 6193  for (;; ptr++)
6193    
6194          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6195    
6196          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
6197          continue;          continue;
6198    
6199    
# Line 6150  for (;; ptr++) Line 6250  for (;; ptr++)
6250          both phases.          both phases.
6251    
6252          If we are not at the pattern start, reset the greedy defaults and the          If we are not at the pattern start, reset the greedy defaults and the
6253          case value for firstbyte and reqbyte. */          case value for firstchar and reqchar. */
6254    
6255          if (*ptr == CHAR_RIGHT_PARENTHESIS)          if (*ptr == CHAR_RIGHT_PARENTHESIS)
6256            {            {
# Line 6163  for (;; ptr++) Line 6263  for (;; ptr++)
6263              {              {
6264              greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);              greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);
6265              greedy_non_default = greedy_default ^ 1;              greedy_non_default = greedy_default ^ 1;
6266              req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;              req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS:0;
6267              }              }
6268    
6269            /* Change options at this level, and pass them back for use            /* Change options at this level, and pass them back for use
# Line 6226  for (;; ptr++) Line 6326  for (;; ptr++)
6326           skipbytes,                       /* Skip over bracket number */           skipbytes,                       /* Skip over bracket number */
6327           cond_depth +           cond_depth +
6328             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6329           &subfirstbyte,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6330           &subreqbyte,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6331           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6332           cd,                              /* Tables block */           cd,                              /* Tables block */
6333           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 6278  for (;; ptr++) Line 6378  for (;; ptr++)
6378          }          }
6379    
6380        /* A "normal" conditional group. If there is just one branch, we must not        /* A "normal" conditional group. If there is just one branch, we must not
6381        make use of its firstbyte or reqbyte, because this is equivalent to an        make use of its firstchar or reqchar, because this is equivalent to an
6382        empty second branch. */        empty second branch. */
6383    
6384        else        else
# Line 6288  for (;; ptr++) Line 6388  for (;; ptr++)
6388            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6389            goto FAILED;            goto FAILED;
6390            }            }
6391          if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE;          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;
6392          }          }
6393        }        }
6394    
# Line 6332  for (;; ptr++) Line 6432  for (;; ptr++)
6432      /* Handle updating of the required and first characters for other types of      /* Handle updating of the required and first characters for other types of
6433      group. Update for normal brackets of all kinds, and conditions with two      group. Update for normal brackets of all kinds, and conditions with two
6434      branches (see code above). If the bracket is followed by a quantifier with      branches (see code above). If the bracket is followed by a quantifier with
6435      zero repeat, we have to back off. Hence the definition of zeroreqbyte and      zero repeat, we have to back off. Hence the definition of zeroreqchar and
6436      zerofirstbyte outside the main loop so that they can be accessed for the      zerofirstchar outside the main loop so that they can be accessed for the
6437      back off. */      back off. */
6438    
6439      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
6440      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
6441      groupsetfirstbyte = FALSE;      groupsetfirstchar = FALSE;
6442    
6443      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
6444        {        {
6445        /* If we have not yet set a firstbyte in this branch, take it from the        /* If we have not yet set a firstchar in this branch, take it from the
6446        subpattern, remembering that it was set here so that a repeat of more        subpattern, remembering that it was set here so that a repeat of more
6447        than one can replicate it as reqbyte if necessary. If the subpattern has        than one can replicate it as reqchar if necessary. If the subpattern has
6448        no firstbyte, set "none" for the whole branch. In both cases, a zero        no firstchar, set "none" for the whole branch. In both cases, a zero
6449        repeat forces firstbyte to "none". */        repeat forces firstchar to "none". */
6450    
6451        if (firstbyte == REQ_UNSET)        if (firstchar == REQ_UNSET)
6452          {          {
6453          if (subfirstbyte >= 0)          if (subfirstchar >= 0)
6454            {            {
6455            firstbyte = subfirstbyte;            firstchar = subfirstchar;
6456            groupsetfirstbyte = TRUE;            groupsetfirstchar = TRUE;
6457            }            }
6458          else firstbyte = REQ_NONE;          else firstchar = REQ_NONE;
6459          zerofirstbyte = REQ_NONE;          zerofirstchar = REQ_NONE;
6460          }          }
6461    
6462        /* If firstbyte was previously set, convert the subpattern's firstbyte        /* If firstchar was previously set, convert the subpattern's firstchar
6463        into reqbyte 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
6464        existence beforehand. */        existence beforehand. */
6465    
6466        else if (subfirstbyte >= 0 && subreqbyte < 0)        else if (subfirstchar >= 0 && subreqchar < 0)
6467          subreqbyte = subfirstbyte | tempreqvary;          subreqchar = subfirstchar | tempreqvary;
6468    
6469        /* 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
6470        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6471    
6472        if (subreqbyte >= 0) reqbyte = subreqbyte;        if (subreqchar >= 0) reqchar = subreqchar;
6473        }        }
6474    
6475      /* For a forward assertion, we take the reqbyte, if set. This can be      /* For a forward assertion, we take the reqchar, if set. This can be
6476      helpful if the pattern that follows the assertion doesn't set a different      helpful if the pattern that follows the assertion doesn't set a different
6477      char. For example, it's useful for /(?=abcde).+/. We can't set firstbyte      char. For example, it's useful for /(?=abcde).+/. We can't set firstchar
6478      for an assertion, however because it leads to incorrect effect for patterns      for an assertion, however because it leads to incorrect effect for patterns
6479      such as /(?=a)a.+/ when the "real" "a" would then become a reqbyte instead      such as /(?=a)a.+/ when the "real" "a" would then become a reqchar instead
6480      of a firstbyte. 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
6481      firstbyte, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6482    
6483      else if (bravalue == OP_ASSERT && subreqbyte >= 0) reqbyte = subreqbyte;      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;
6484      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6485    
6486    
# Line 6413  for (;; ptr++) Line 6513  for (;; ptr++)
6513        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6514        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6515    
6516        if (firstbyte == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)
6517          firstbyte = REQ_NONE;          firstchar = REQ_NONE;
6518    
6519        /* 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. */
6520    
6521        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
6522        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6523    
6524        /* \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'
6525        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 6470  for (;; ptr++) Line 6570  for (;; ptr++)
6570          /* Test a signed number in angle brackets or quotes. */          /* Test a signed number in angle brackets or quotes. */
6571    
6572          p = ptr + 2;          p = ptr + 2;
6573          while ((digitab[*p] & ctype_digit) != 0) p++;          while (IS_DIGIT(*p)) p++;
6574          if (*p != terminator)          if (*p != terminator)
6575            {            {
6576            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
# Line 6498  for (;; ptr++) Line 6598  for (;; ptr++)
6598          goto NAMED_REF_OR_RECURSE;          goto NAMED_REF_OR_RECURSE;
6599          }          }
6600    
6601        /* Back references are handled specially; must disable firstbyte if        /* Back references are handled specially; must disable firstchar if
6602        not set to cope with cases like (?=(\w+))\1: which would otherwise set        not set to cope with cases like (?=(\w+))\1: which would otherwise set
6603        ':' later. */        ':' later. */
6604    
# Line 6508  for (;; ptr++) Line 6608  for (;; ptr++)
6608          recno = -c - ESC_REF;          recno = -c - ESC_REF;
6609    
6610          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6611          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
6612          previous = code;          previous = code;
6613          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6614          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6575  for (;; ptr++) Line 6675  for (;; ptr++)
6675    
6676            {            {
6677            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
6678            *code++ = (!utf8 && c == -ESC_C)? OP_ALLANY : -c;            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;
6679            }            }
6680          }          }
6681        continue;        continue;
# Line 6585  for (;; ptr++) Line 6685  for (;; ptr++)
6685      a value > 127. We set its representation in the length/buffer, and then      a value > 127. We set its representation in the length/buffer, and then
6686      handle it as a data character. */      handle it as a data character. */
6687    
6688  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6689      if (utf8 && c > 127)      if (utf && c > 127)
6690        mclength = PRIV(ord2utf8)(c, mcbuffer);        mclength = PRIV(ord2utf)(c, mcbuffer);
6691      else      else
6692  #endif  #endif
6693    
# Line 6608  for (;; ptr++) Line 6708  for (;; ptr++)
6708      mclength = 1;      mclength = 1;
6709      mcbuffer[0] = c;      mcbuffer[0] = c;
6710    
6711  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6712      if (utf8 && c >= 0xc0)      if (utf && HAS_EXTRALEN(c))
6713        {        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));
       while ((ptr[1] & 0xc0) == 0x80)  
         mcbuffer[mclength++] = *(++ptr);  
       }  
6714  #endif  #endif
6715    
6716      /* At this point we have the character's bytes in mcbuffer, and the length      /* At this point we have the character's bytes in mcbuffer, and the length
# Line 6631  for (;; ptr++) Line 6728  for (;; ptr++)
6728    
6729      /* Set the first and required bytes appropriately. If no previous first      /* Set the first and required bytes appropriately. If no previous first
6730      byte, set it from this character, but revert to none on a zero repeat.      byte, set it from this character, but revert to none on a zero repeat.
6731      Otherwise, leave the firstbyte value alone, and don't change it on a zero      Otherwise, leave the firstchar value alone, and don't change it on a zero
6732      repeat. */      repeat. */
6733    
6734      if (firstbyte == REQ_UNSET)      if (firstchar == REQ_UNSET)
6735        {        {
6736        zerofirstbyte = REQ_NONE;        zerofirstchar = REQ_NONE;
6737        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6738    
6739        /* If the character is more than one byte long, we can set firstbyte        /* If the character is more than one byte long, we can set firstchar
6740        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
6741    
6742        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6743          {          {
6744          firstbyte = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
6745          if (mclength != 1) reqbyte = code[-1] | cd->req_varyopt;          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;
6746          }          }
6747        else firstbyte = reqbyte = REQ_NONE;        else firstchar = reqchar = REQ_NONE;
6748        }        }
6749    
6750      /* firstbyte was previously set; we can set reqbyte only if the length is      /* firstchar was previously set; we can set reqchar only if the length is
6751      1 or the matching is caseful. */      1 or the matching is caseful. */
6752    
6753      else      else
6754        {        {
6755        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
6756        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6757        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6758          reqbyte = code[-1] | req_caseopt | cd->req_varyopt;          reqchar = code[-1] | req_caseopt | cd->req_varyopt;
6759        }        }
6760    
6761      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6698  Arguments: Line 6795  Arguments:
6795    reset_bracount TRUE to reset the count for each branch    reset_bracount TRUE to reset the count for each branch
6796    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes      skip this many bytes at start (for brackets and OP_COND)
6797    cond_depth     depth of nesting for conditional subpatterns    cond_depth     depth of nesting for conditional subpatterns
6798    firstbyteptr   place to put the first required character, or a negative number    firstcharptr   place to put the first required character, or a negative number
6799    reqbyteptr     place to put the last required character, or a negative number    reqcharptr     place to put the last required character, or a negative number
6800    bcptr          pointer to the chain of currently open branches    bcptr          pointer to the chain of currently open branches
6801    cd             points to the data block with tables pointers etc.    cd             points to the data block with tables pointers etc.
6802    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
# Line 6711  Returns:         TRUE on success Line 6808  Returns:         TRUE on success
6808  static BOOL  static BOOL
6809  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
6810    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
6811    int cond_depth, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr,    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,
6812    compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
6813  {  {
6814  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
6815  pcre_uchar *code = *codeptr;  pcre_uchar *code = *codeptr;
# Line 6721  pcre_uchar *start_bracket = code; Line 6818  pcre_uchar *start_bracket = code;
6818  pcre_uchar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
6819  open_capitem capitem;  open_capitem capitem;
6820  int capnumber = 0;  int capnumber = 0;
6821  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
6822  int branchfirstbyte, branchreqbyte;  pcre_int32 branchfirstchar, branchreqchar;
6823  int length;  int length;
6824  int orig_bracount;  int orig_bracount;
6825  int max_bracount;  int max_bracount;
# Line 6731  branch_chain bc; Line 6828  branch_chain bc;
6828  bc.outer = bcptr;  bc.outer = bcptr;
6829  bc.current_branch = code;  bc.current_branch = code;
6830    
6831  firstbyte = reqbyte = REQ_UNSET;  firstchar = reqchar = REQ_UNSET;
6832    
6833  /* 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
6834  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 6790  for (;;) Line 6887  for (;;)
6887    /* Now compile the branch; in the pre-compile phase its length gets added    /* Now compile the branch; in the pre-compile phase its length gets added
6888    into the length. */    into the length. */
6889    
6890    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstbyte,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
6891          &branchreqbyte, &bc, cond_depth, cd,          &branchreqchar, &bc, cond_depth, cd,
6892          (lengthptr == NULL)? NULL : &length))          (lengthptr == NULL)? NULL : &length))
6893      {      {
6894      *ptrptr = ptr;      *ptrptr = ptr;
# Line 6807  for (;;) Line 6904  for (;;)
6904    
6905    if (lengthptr == NULL)    if (lengthptr == NULL)
6906      {      {
6907      /* If this is the first branch, the firstbyte and reqbyte values for the      /* If this is the first branch, the firstchar and reqchar values for the
6908      branch become the values for the regex. */      branch become the values for the regex. */
6909    
6910      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
6911        {        {
6912        firstbyte = branchfirstbyte;        firstchar = branchfirstchar;
6913        reqbyte = branchreqbyte;        reqchar = branchreqchar;
6914        }        }
6915    
6916      /* If this is not the first branch, the first char and reqbyte have to      /* If this is not the first branch, the first char and reqchar have to
6917      match the values from all the previous branches, except that if the      match the values from all the previous branches, except that if the
6918      previous value for reqbyte didn't have REQ_VARY set, it can still match,      previous value for reqchar didn't have REQ_VARY set, it can still match,
6919      and we set REQ_VARY for the regex. */      and we set REQ_VARY for the regex. */
6920    
6921      else      else
6922        {        {
6923        /* If we previously had a firstbyte, but it doesn't match the new branch,        /* If we previously had a firstchar, but it doesn't match the new branch,
6924        we have to abandon the firstbyte for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
6925        previously no reqbyte, it takes on the value of the old firstbyte. */        previously no reqchar, it takes on the value of the old firstchar. */
6926    
6927        if (firstbyte >= 0 && firstbyte != branchfirstbyte)        if (firstchar >= 0 && firstchar != branchfirstchar)
6928          {          {
6929          if (reqbyte < 0) reqbyte = firstbyte;          if (reqchar < 0) reqchar = firstchar;
6930          firstbyte = REQ_NONE;          firstchar = REQ_NONE;
6931          }          }
6932    
6933        /* If we (now or from before) have no firstbyte, a firstbyte from the        /* If we (now or from before) have no firstchar, a firstchar from the
6934        branch becomes a reqbyte if there isn't a branch reqbyte. */        branch becomes a reqchar if there isn't a branch reqchar. */
6935    
6936        if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0)        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)
6937            branchreqbyte = branchfirstbyte;            branchreqchar = branchfirstchar;
6938    
6939        /* Now ensure that the reqbytes match */        /* Now ensure that the reqchars match */
6940    
6941        if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY))        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))
6942          reqbyte = REQ_NONE;          reqchar = REQ_NONE;
6943        else reqbyte |= branchreqbyte;   /* To "or" REQ_VARY */        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */
6944        }        }
6945    
6946      /* 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 6933  for (;;) Line 7030  for (;;)
7030    
7031      *codeptr = code;      *codeptr = code;
7032      *ptrptr = ptr;      *ptrptr = ptr;
7033      *firstbyteptr = firstbyte;      *firstcharptr = firstchar;
7034      *reqbyteptr = reqbyte;      *reqcharptr = reqchar;
7035      if (lengthptr != NULL)      if (lengthptr != NULL)
7036        {        {
7037        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 7313  pcre16_compile2(PCRE_SPTR16 pattern, int Line 7410  pcre16_compile2(PCRE_SPTR16 pattern, int
7410  {  {
7411  real_pcre *re;  real_pcre *re;
7412  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7413  int firstbyte, reqbyte, newline;  pcre_int32 firstchar, reqchar;
7414    int newline;
7415  int errorcode = 0;  int errorcode = 0;
7416  int skipatstart = 0;  int skipatstart = 0;
7417  BOOL utf8;  BOOL utf;
7418  size_t size;  size_t size;
7419  pcre_uchar *code;  pcre_uchar *code;
7420  const pcre_uchar *codestart;  const pcre_uchar *codestart;
# Line 7384  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7482  while (ptr[skipatstart] == CHAR_LEFT_PAR
7482    int newnl = 0;    int newnl = 0;
7483    int newbsr = 0;    int newbsr = 0;
7484    
7485    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)  #ifdef COMPILE_PCRE8
7486      if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 5) == 0)
7487      { skipatstart += 7; options |= PCRE_UTF8; continue; }      { skipatstart += 7; options |= PCRE_UTF8; continue; }
7488    #endif
7489    #ifdef COMPILE_PCRE16
7490      if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)
7491        { skipatstart += 8; options |= PCRE_UTF16; continue; }
7492    #endif
7493    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)
7494      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7495    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 7414  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7518  while (ptr[skipatstart] == CHAR_LEFT_PAR
7518    else break;    else break;
7519    }    }
7520    
7521  utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
7522    utf = (options & PCRE_UTF8) != 0;
7523    
7524  /* Can't support UTF8 unless PCRE has been compiled to include the code. The  /* Can't support UTF unless PCRE has been compiled to include the code. The
7525  return of an error code from PRIV(valid_utf8)() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
7526  release 8.13. It is passed back from pcre_[dfa_]exec(), but at the moment is  release 8.13. It is passed back from pcre_[dfa_]exec(), but at the moment is
7527  not used here. */  not used here. */
7528    
7529  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
7530  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&
7531       (errorcode = PRIV(valid_utf8)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)
7532    {    {
7533    errorcode = ERR44;    errorcode = ERR44;
7534    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
7535    }    }
7536  #else  #else
7537  if (utf8)  if (utf)
7538    {    {
7539    errorcode = ERR32;    errorcode = ERR32;
7540    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
# Line 7541  ptr += skipatstart; Line 7646  ptr += skipatstart;
7646  code = cworkspace;  code = cworkspace;
7647  *code = OP_BRA;  *code = OP_BRA;
7648  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,
7649    FALSE, 0, 0, &firstbyte, &reqbyte, NULL, cd, &length);    FALSE, 0, 0, &firstchar, &reqchar, NULL, cd, &length);
7650  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
7651    
7652  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,
# Line 7558  externally provided function. Integer ov Line 7663  externally provided function. Integer ov
7663  because nowadays we limit the maximum value of cd->names_found and  because nowadays we limit the maximum value of cd->names_found and
7664  cd->name_entry_size. */  cd->name_entry_size. */
7665    
7666  size = sizeof(real_pcre) + (length + cd->names_found * (cd->name_entry_size + 3)) * sizeof(pcre_uchar);  size = sizeof(real_pcre) + (length + cd->names_found * cd->name_entry_size) * sizeof(pcre_uchar);
7667  re = (real_pcre *)(pcre_malloc)(size);  re = (real_pcre *)(pcre_malloc)(size);
7668    
7669  if (re == NULL)  if (re == NULL)
# Line 7578  re->size = (int)size; Line 7683  re->size = (int)size;
7683  re->options = cd->external_options;  re->options = cd->external_options;
7684  re->flags = cd->external_flags;  re->flags = cd->external_flags;
7685  re->dummy1 = 0;  re->dummy1 = 0;
7686  re->first_byte = 0;  re->first_char = 0;
7687  re->req_byte = 0;  re->req_char = 0;
7688  re->name_table_offset = sizeof(real_pcre) / sizeof(pcre_uchar);  re->name_table_offset = sizeof(real_pcre) / sizeof(pcre_uchar);
7689  re->name_entry_size = cd->name_entry_size;  re->name_entry_size = cd->name_entry_size;
7690  re->name_count = cd->names_found;  re->name_count = cd->names_found;
# Line 7615  ptr = (const pcre_uchar *)pattern + skip Line 7720  ptr = (const pcre_uchar *)pattern + skip
7720  code = (pcre_uchar *)codestart;  code = (pcre_uchar *)codestart;
7721  *code = OP_BRA;  *code = OP_BRA;
7722  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,
7723    &firstbyte, &reqbyte, NULL, cd, NULL);    &firstchar, &reqchar, NULL, cd, NULL);
7724  re->top_bracket = cd->bracount;  re->top_bracket = cd->bracount;
7725  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
7726  re->flags = cd->external_flags;  re->flags = cd->external_flags | PCRE_MODE;
7727    
7728  if (cd->had_accept) reqbyte = REQ_NONE;   /* Must disable after (*ACCEPT) */  if (cd->had_accept) reqchar = REQ_NONE;   /* Must disable after (*ACCEPT) */
7729    
7730  /* 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. */
7731    
# Line 7644  while (errorcode == 0 && cd->hwm > cwork Line 7749  while (errorcode == 0 && cd->hwm > cwork
7749    cd->hwm -= LINK_SIZE;    cd->hwm -= LINK_SIZE;
7750    offset = GET(cd->hwm, 0);    offset = GET(cd->hwm, 0);
7751    recno = GET(codestart, offset);    recno = GET(codestart, offset);
7752    groupptr = PRIV(find_bracket)(codestart, utf8, recno);    groupptr = PRIV(find_bracket)(codestart, utf, recno);
7753    if (groupptr == NULL) errorcode = ERR53;    if (groupptr == NULL) errorcode = ERR53;
7754      else PUT(((pcre_uchar *)codestart), offset, (int)(groupptr - codestart));      else PUT(((pcre_uchar *)codestart), offset, (int)(groupptr - codestart));
7755    }    }
# Line 7671  if (cd->check_lookbehind) Line 7776  if (cd->check_lookbehind)
7776    of zero, but that is a pathological case, and it does no harm.) When we find    of zero, but that is a pathological case, and it does no harm.) When we find
7777    one, we temporarily terminate the branch it is in while we scan it. */    one, we temporarily terminate the branch it is in while we scan it. */
7778    
7779    for (cc = (pcre_uchar *)PRIV(find_bracket)(codestart, utf8, -1);    for (cc = (pcre_uchar *)PRIV(find_bracket)(codestart, utf, -1);
7780         cc != NULL;         cc != NULL;
7781         cc = (pcre_uchar *)PRIV(find_bracket)(cc, utf8, -1))         cc = (pcre_uchar *)PRIV(find_bracket)(cc, utf, -1))
7782      {      {
7783      if (GET(cc, 1) == 0)      if (GET(cc, 1) == 0)
7784        {        {
# Line 7726  if ((re->options & PCRE_ANCHORED) == 0) Line 7831  if ((re->options & PCRE_ANCHORED) == 0)
7831      re->options |= PCRE_ANCHORED;      re->options |= PCRE_ANCHORED;
7832    else    else
7833      {      {
7834      if (firstbyte < 0)      if (firstchar < 0)
7835        firstbyte = find_firstassertedchar(codestart, FALSE);        firstchar = find_firstassertedchar(codestart, FALSE);
7836      if (firstbyte >= 0)   /* Remove caseless flag for non-caseable chars */      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */
7837        {        {
7838        int ch = firstbyte & 255;  #ifdef COMPILE_PCRE8
7839        re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&        re->first_char = firstchar & 0xff;
7840           cd->fcc[ch] == ch)? ch : firstbyte;  #else
7841    #ifdef COMPILE_PCRE16
7842          re->first_char = firstchar & 0xffff;
7843    #endif
7844    #endif
7845          if ((firstchar & REQ_CASELESS) != 0)
7846            {
7847    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
7848            /* We ignore non-ASCII first chars in 8 bit mode. */
7849            if (utf)
7850              {
7851              if (re->first_char < 128)
7852                {
7853                if (cd->fcc[re->first_char] != re->first_char)
7854                  re->flags |= PCRE_FCH_CASELESS;
7855                }
7856              else if (UCD_OTHERCASE(re->first_char) != re->first_char)
7857                re->flags |= PCRE_FCH_CASELESS;
7858              }
7859            else
7860    #endif
7861            if (MAX_255(re->first_char)
7862                && cd->fcc[re->first_char] != re->first_char)
7863              re->flags |= PCRE_FCH_CASELESS;
7864            }
7865    
7866        re->flags |= PCRE_FIRSTSET;        re->flags |= PCRE_FIRSTSET;
7867        }        }
7868      else if (is_startline(codestart, 0, cd->backref_map))      else if (is_startline(codestart, 0, cd->backref_map))
# Line 7744  if ((re->options & PCRE_ANCHORED) == 0) Line 7874  if ((re->options & PCRE_ANCHORED) == 0)
7874  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
7875  bytes. */  bytes. */
7876    
7877  if (reqbyte >= 0 &&  if (reqchar >= 0 &&
7878       ((re->options & PCRE_ANCHORED) == 0 || (reqbyte & REQ_VARY) != 0))       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))
7879    {    {
7880    int ch = reqbyte & 255;  #ifdef COMPILE_PCRE8
7881    re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&    re->req_char = reqchar & 0xff;
7882      cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;  #else
7883    #ifdef COMPILE_PCRE16
7884      re->req_char = reqchar & 0xffff;
7885    #endif
7886    #endif
7887      if ((reqchar & REQ_CASELESS) != 0)
7888        {
7889    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
7890        /* We ignore non-ASCII first chars in 8 bit mode. */
7891        if (utf)
7892          {
7893          if (re->req_char < 128)
7894            {
7895            if (cd->fcc[re->req_char] != re->req_char)
7896              re->flags |= PCRE_RCH_CASELESS;
7897            }
7898          else if (UCD_OTHERCASE(re->req_char) != re->req_char)
7899            re->flags |= PCRE_RCH_CASELESS;
7900          }
7901        else
7902    #endif
7903        if (MAX_255(re->req_char) && cd->fcc[re->req_char] != re->req_char)
7904          re->flags |= PCRE_RCH_CASELESS;
7905        }
7906    
7907    re->flags |= PCRE_REQCHSET;    re->flags |= PCRE_REQCHSET;
7908    }    }
7909    
# Line 7764  printf("Options=%08x\n", re->options); Line 7918  printf("Options=%08x\n", re->options);
7918    
7919  if ((re->flags & PCRE_FIRSTSET) != 0)  if ((re->flags & PCRE_FIRSTSET) != 0)
7920    {    {
7921    int ch = re->first_byte & 255;    pcre_uchar ch = re->first_char;
7922    const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)?    const char *caseless =
7923      "" : " (caseless)";      ((re->flags & PCRE_FCH_CASELESS) == 0)? "" : " (caseless)";
7924    if (isprint(ch)) printf("First char = %c%s\n", ch, caseless);    if (PRINTABLE(ch)) printf("First char = %c%s\n", ch, caseless);
7925      else printf("First char = \\x%02x%s\n", ch, caseless);      else printf("First char = \\x%02x%s\n", ch, caseless);
7926    }    }
7927    
7928  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
7929    {    {
7930    int ch = re->req_byte & 255;    pcre_uchar ch = re->req_char;
7931    const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)?    const char *caseless =
7932      "" : " (caseless)";      ((re->flags & PCRE_RCH_CASELESS) == 0)? "" : " (caseless)";
7933    if (isprint(ch)) printf("Req char = %c%s\n", ch, caseless);    if (PRINTABLE(ch)) printf("Req char = %c%s\n", ch, caseless);
7934      else printf("Req char = \\x%02x%s\n", ch, caseless);      else printf("Req char = \\x%02x%s\n", ch, caseless);
7935    }    }
7936    

Legend:
Removed from v.770  
changed lines
  Added in v.795

  ViewVC Help
Powered by ViewVC 1.1.5