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

Diff of /code/trunk/pcre_compile.c

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

revision 1045 by ph10, Sun Sep 23 16:50:00 2012 UTC revision 1325 by ph10, Fri May 10 14:03:18 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 53  supporting internal functions that are n Line 53  supporting internal functions that are n
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    
56  /* When PCRE_DEBUG is defined, we need the pcre(16)_printint() function, which  /* When PCRE_DEBUG is defined, we need the pcre(16|32)_printint() function, which
57  is also used by pcretest. PCRE_DEBUG is not defined when building a production  is also used by pcretest. PCRE_DEBUG is not defined when building a production
58  library. We do not need to select pcre16_printint.c specially, because the  library. We do not need to select pcre16_printint.c specially, because the
59  COMPILE_PCREx macro will already be appropriately set. */  COMPILE_PCREx macro will already be appropriately set. */
# Line 80  to check them every time. */ Line 80  to check them every time. */
80  /* Definitions to allow mutual recursion */  /* Definitions to allow mutual recursion */
81    
82  static int  static int
83    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84      const pcre_uint32 *, unsigned int);      const pcre_uint32 *, unsigned int);
85    
86  static BOOL  static BOOL
87    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
88      int, int, int *, int *, branch_chain *, compile_data *, int *);      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,
89        compile_data *, int *);
90    
91    
92    
# Line 121  overrun before it actually does run off Line 122  overrun before it actually does run off
122    
123  /* Private flags added to firstchar and reqchar. */  /* Private flags added to firstchar and reqchar. */
124    
125  #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */  #define REQ_CASELESS    (1 << 0)        /* Indicates caselessness */
126  #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */  #define REQ_VARY        (1 << 1)        /* Reqchar followed non-literal item */
127    /* Negative values for the firstchar and reqchar flags */
128    #define REQ_UNSET       (-2)
129    #define REQ_NONE        (-1)
130    
131  /* Repeated character flags. */  /* Repeated character flags. */
132    
# Line 483  static const char error_texts[] = Line 487  static const char error_texts[] =
487    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
488    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
489    /* 60 */    /* 60 */
490    "(*VERB) not recognized\0"    "(*VERB) not recognized or malformed\0"
491    "number is too big\0"    "number is too big\0"
492    "subpattern name expected\0"    "subpattern name expected\0"
493    "digit expected after (?+\0"    "digit expected after (?+\0"
# Line 503  static const char error_texts[] = Line 507  static const char error_texts[] =
507    /* 75 */    /* 75 */
508    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
509    "character value in \\u.... sequence is too large\0"    "character value in \\u.... sequence is too large\0"
510      "invalid UTF-32 string\0"
511      "setting UTF is disabled by the application\0"
512    ;    ;
513    
514  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 643  static const pcre_uint8 ebcdic_chartab[] Line 649  static const pcre_uint8 ebcdic_chartab[]
649    
650    
651    
   
652  /*************************************************  /*************************************************
653  *            Find an error text                  *  *            Find an error text                  *
654  *************************************************/  *************************************************/
# Line 663  find_error_text(int n) Line 668  find_error_text(int n)
668  const char *s = error_texts;  const char *s = error_texts;
669  for (; n > 0; n--)  for (; n > 0; n--)
670    {    {
671    while (*s++ != 0) {};    while (*s++ != CHAR_NULL) {};
672    if (*s == 0) return "Error text not found (please report)";    if (*s == CHAR_NULL) return "Error text not found (please report)";
673    }    }
674  return s;  return s;
675  }  }
# Line 747  return (*p == CHAR_RIGHT_CURLY_BRACKET); Line 752  return (*p == CHAR_RIGHT_CURLY_BRACKET);
752  *************************************************/  *************************************************/
753    
754  /* This function is called when a \ has been encountered. It either returns a  /* This function is called when a \ has been encountered. It either returns a
755  positive value for a simple escape such as \n, or a negative value which  positive value for a simple escape such as \n, or 0 for a data character
756  encodes one of the more complicated things such as \d. A backreference to group  which will be placed in chptr. A backreference to group n is returned as
757  n is returned as -(ESC_REF + n); ESC_REF is the highest ESC_xxx macro. When  negative n. When UTF-8 is enabled, a positive value greater than 255 may
758  UTF-8 is enabled, a positive value greater than 255 may be returned. On entry,  be returned in chptr.
759  ptr is pointing at the \. On exit, it is on the final character of the escape  On entry,ptr is pointing at the \. On exit, it is on the final character of the
760  sequence.  escape sequence.
761    
762  Arguments:  Arguments:
763    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
764      chptr          points to the data character
765    errorcodeptr   points to the errorcode variable    errorcodeptr   points to the errorcode variable
766    bracount       number of previous extracting brackets    bracount       number of previous extracting brackets
767    options        the options bits    options        the options bits
768    isclass        TRUE if inside a character class    isclass        TRUE if inside a character class
769    
770  Returns:         zero or positive => a data character  Returns:         zero => a data character
771                   negative => a special escape sequence                   positive => a special escape sequence
772                     negative => a back reference
773                   on error, errorcodeptr is set                   on error, errorcodeptr is set
774  */  */
775    
776  static int  static int
777  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
778    int options, BOOL isclass)    int bracount, int options, BOOL isclass)
779  {  {
780  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
781  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
782  const pcre_uchar *ptr = *ptrptr + 1;  const pcre_uchar *ptr = *ptrptr + 1;
783  pcre_int32 c;  pcre_uint32 c;
784    int escape = 0;
785  int i;  int i;
786    
787  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
# Line 781  ptr--;                            /* Set Line 789  ptr--;                            /* Set
789    
790  /* If backslash is at the end of the pattern, it's an error. */  /* If backslash is at the end of the pattern, it's an error. */
791    
792  if (c == 0) *errorcodeptr = ERR1;  if (c == CHAR_NULL) *errorcodeptr = ERR1;
793    
794  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup
795  in a table. A non-zero result is something that can be returned immediately.  in a table. A non-zero result is something that can be returned immediately.
# Line 790  Otherwise further processing may be requ Line 798  Otherwise further processing may be requ
798  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
799  /* Not alphanumeric */  /* Not alphanumeric */
800  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
801  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0)
802      { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
803    
804  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
805  /* Not alphanumeric */  /* Not alphanumeric */
806  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
807  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
808  #endif  #endif
809    
810  /* Escapes that need further processing, or are illegal. */  /* Escapes that need further processing, or are illegal. */
# Line 803  else if ((i = escapes[c - 0x48]) != 0) Line 812  else if ((i = escapes[c - 0x48]) != 0)
812  else  else
813    {    {
814    const pcre_uchar *oldptr;    const pcre_uchar *oldptr;
815    BOOL braced, negated;    BOOL braced, negated, overflow;
816      int s;
817    
818    switch (c)    switch (c)
819      {      {
# Line 828  else Line 838  else
838          c = 0;          c = 0;
839          for (i = 0; i < 4; ++i)          for (i = 0; i < 4; ++i)
840            {            {
841            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
842  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
843            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
844            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 838  else Line 848  else
848  #endif  #endif
849            }            }
850    
851  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
852          if (c > (utf ? 0x10ffff : 0xff))          if (c > (utf ? 0x10ffffU : 0xffU))
853  #else  #elif defined COMPILE_PCRE16
854  #ifdef COMPILE_PCRE16          if (c > (utf ? 0x10ffffU : 0xffffU))
855          if (c > (utf ? 0x10ffff : 0xffff))  #elif defined COMPILE_PCRE32
856  #endif          if (utf && c > 0x10ffffU)
857  #endif  #endif
858            {            {
859            *errorcodeptr = ERR76;            *errorcodeptr = ERR76;
# Line 875  else Line 885  else
885      (3) For Oniguruma compatibility we also support \g followed by a name or a      (3) For Oniguruma compatibility we also support \g followed by a name or a
886      number either in angle brackets or in single quotes. However, these are      number either in angle brackets or in single quotes. However, these are
887      (possibly recursive) subroutine calls, _not_ backreferences. Just return      (possibly recursive) subroutine calls, _not_ backreferences. Just return
888      the -ESC_g code (cf \k). */      the ESC_g code (cf \k). */
889    
890      case CHAR_g:      case CHAR_g:
891      if (isclass) break;      if (isclass) break;
892      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)
893        {        {
894        c = -ESC_g;        escape = ESC_g;
895        break;        break;
896        }        }
897    
# Line 890  else Line 900  else
900      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
901        {        {
902        const pcre_uchar *p;        const pcre_uchar *p;
903        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)        for (p = ptr+2; *p != CHAR_NULL && *p != CHAR_RIGHT_CURLY_BRACKET; p++)
904          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
905        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != CHAR_NULL && *p != CHAR_RIGHT_CURLY_BRACKET)
906          {          {
907          c = -ESC_k;          escape = ESC_k;
908          break;          break;
909          }          }
910        braced = TRUE;        braced = TRUE;
# Line 910  else Line 920  else
920      else negated = FALSE;      else negated = FALSE;
921    
922      /* The integer range is limited by the machine's int representation. */      /* The integer range is limited by the machine's int representation. */
923      c = 0;      s = 0;
924        overflow = FALSE;
925      while (IS_DIGIT(ptr[1]))      while (IS_DIGIT(ptr[1]))
926        {        {
927        if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */        if (s > INT_MAX / 10 - 1) /* Integer overflow */
928          {          {
929          c = -1;          overflow = TRUE;
930          break;          break;
931          }          }
932        c = c * 10 + *(++ptr) - CHAR_0;        s = s * 10 + (int)(*(++ptr) - CHAR_0);
933        }        }
934      if (((unsigned int)c) > INT_MAX) /* Integer overflow */      if (overflow) /* Integer overflow */
935        {        {
936        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
937          ptr++;          ptr++;
# Line 934  else Line 945  else
945        break;        break;
946        }        }
947    
948      if (c == 0)      if (s == 0)
949        {        {
950        *errorcodeptr = ERR58;        *errorcodeptr = ERR58;
951        break;        break;
# Line 942  else Line 953  else
953    
954      if (negated)      if (negated)
955        {        {
956        if (c > bracount)        if (s > bracount)
957          {          {
958          *errorcodeptr = ERR15;          *errorcodeptr = ERR15;
959          break;          break;
960          }          }
961        c = bracount - (c - 1);        s = bracount - (s - 1);
962        }        }
963    
964      c = -(ESC_REF + c);      escape = -s;
965      break;      break;
966    
967      /* The handling of escape sequences consisting of a string of digits      /* The handling of escape sequences consisting of a string of digits
# Line 972  else Line 983  else
983        {        {
984        oldptr = ptr;        oldptr = ptr;
985        /* The integer range is limited by the machine's int representation. */        /* The integer range is limited by the machine's int representation. */
986        c -= CHAR_0;        s = (int)(c -CHAR_0);
987          overflow = FALSE;
988        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
989          {          {
990          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */          if (s > INT_MAX / 10 - 1) /* Integer overflow */
991            {            {
992            c = -1;            overflow = TRUE;
993            break;            break;
994            }            }
995          c = c * 10 + *(++ptr) - CHAR_0;          s = s * 10 + (int)(*(++ptr) - CHAR_0);
996          }          }
997        if (((unsigned int)c) > INT_MAX) /* Integer overflow */        if (overflow) /* Integer overflow */
998          {          {
999          while (IS_DIGIT(ptr[1]))          while (IS_DIGIT(ptr[1]))
1000            ptr++;            ptr++;
1001          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
1002          break;          break;
1003          }          }
1004        if (c < 10 || c <= bracount)        if (s < 10 || s <= bracount)
1005          {          {
1006          c = -(ESC_REF + c);          escape = -s;
1007          break;          break;
1008          }          }
1009        ptr = oldptr;      /* Put the pointer back and fall through */        ptr = oldptr;      /* Put the pointer back and fall through */
# Line 1038  else Line 1050  else
1050          c = 0;          c = 0;
1051          for (i = 0; i < 2; ++i)          for (i = 0; i < 2; ++i)
1052            {            {
1053            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
1054  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1055            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1056            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1056  else Line 1068  else
1068        const pcre_uchar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
1069    
1070        c = 0;        c = 0;
1071          overflow = FALSE;
1072        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
1073          {          {
1074          register int cc = *pt++;          register pcre_uint32 cc = *pt++;
1075          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
1076    
1077    #ifdef COMPILE_PCRE32
1078            if (c >= 0x10000000l) { overflow = TRUE; break; }
1079    #endif
1080    
1081  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1082          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1083          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1069  else Line 1086  else
1086          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
1087  #endif  #endif
1088    
1089  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
1090          if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }          if (c > (utf ? 0x10ffffU : 0xffU)) { overflow = TRUE; break; }
1091  #else  #elif defined COMPILE_PCRE16
1092  #ifdef COMPILE_PCRE16          if (c > (utf ? 0x10ffffU : 0xffffU)) { overflow = TRUE; break; }
1093          if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }  #elif defined COMPILE_PCRE32
1094  #endif          if (utf && c > 0x10ffffU) { overflow = TRUE; break; }
1095  #endif  #endif
1096          }          }
1097    
1098        if (c < 0)        if (overflow)
1099          {          {
1100          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1101          *errorcodeptr = ERR34;          *errorcodeptr = ERR34;
# Line 1100  else Line 1117  else
1117      c = 0;      c = 0;
1118      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)
1119        {        {
1120        int cc;                                  /* Some compilers don't like */        pcre_uint32 cc;                          /* Some compilers don't like */
1121        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
1122  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1123        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */
# Line 1119  else Line 1136  else
1136    
1137      case CHAR_c:      case CHAR_c:
1138      c = *(++ptr);      c = *(++ptr);
1139      if (c == 0)      if (c == CHAR_NULL)
1140        {        {
1141        *errorcodeptr = ERR2;        *errorcodeptr = ERR2;
1142        break;        break;
# Line 1159  else Line 1176  else
1176  newline". PCRE does not support \N{name}. However, it does support  newline". PCRE does not support \N{name}. However, it does support
1177  quantification such as \N{2,3}. */  quantification such as \N{2,3}. */
1178    
1179  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&  if (escape == ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&
1180       !is_counted_repeat(ptr+2))       !is_counted_repeat(ptr+2))
1181    *errorcodeptr = ERR37;    *errorcodeptr = ERR37;
1182    
1183  /* If PCRE_UCP is set, we change the values for \d etc. */  /* If PCRE_UCP is set, we change the values for \d etc. */
1184    
1185  if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w)  if ((options & PCRE_UCP) != 0 && escape >= ESC_D && escape <= ESC_w)
1186    c -= (ESC_DU - ESC_D);    escape += (ESC_DU - ESC_D);
1187    
1188  /* Set the pointer to the final character before returning. */  /* Set the pointer to the final character before returning. */
1189    
1190  *ptrptr = ptr;  *ptrptr = ptr;
1191  return c;  *chptr = c;
1192    return escape;
1193  }  }
1194    
   
   
1195  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1196  /*************************************************  /*************************************************
1197  *               Handle \P and \p                 *  *               Handle \P and \p                 *
# Line 1189  escape sequence. Line 1205  escape sequence.
1205  Argument:  Argument:
1206    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
1207    negptr         points to a boolean that is set TRUE for negation else FALSE    negptr         points to a boolean that is set TRUE for negation else FALSE
1208    dptr           points to an int that is set to the detailed property value    ptypeptr       points to an unsigned int that is set to the type value
1209      pdataptr       points to an unsigned int that is set to the detailed property value
1210    errorcodeptr   points to the error code variable    errorcodeptr   points to the error code variable
1211    
1212  Returns:         type value from ucp_type_table, or -1 for an invalid type  Returns:         TRUE if the type value was found, or FALSE for an invalid type
1213  */  */
1214    
1215  static int  static BOOL
1216  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1217      unsigned int *pdataptr, int *errorcodeptr)
1218  {  {
1219  int c, i, bot, top;  pcre_uchar c;
1220    int i, bot, top;
1221  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
1222  pcre_uchar name[32];  pcre_uchar name[32];
1223    
1224  c = *(++ptr);  c = *(++ptr);
1225  if (c == 0) goto ERROR_RETURN;  if (c == CHAR_NULL) goto ERROR_RETURN;
1226    
1227  *negptr = FALSE;  *negptr = FALSE;
1228    
# Line 1220  if (c == CHAR_LEFT_CURLY_BRACKET) Line 1239  if (c == CHAR_LEFT_CURLY_BRACKET)
1239    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)
1240      {      {
1241      c = *(++ptr);      c = *(++ptr);
1242      if (c == 0) goto ERROR_RETURN;      if (c == CHAR_NULL) goto ERROR_RETURN;
1243      if (c == CHAR_RIGHT_CURLY_BRACKET) break;      if (c == CHAR_RIGHT_CURLY_BRACKET) break;
1244      name[i] = c;      name[i] = c;
1245      }      }
# Line 1245  top = PRIV(utt_size); Line 1264  top = PRIV(utt_size);
1264    
1265  while (bot < top)  while (bot < top)
1266    {    {
1267      int r;
1268    i = (bot + top) >> 1;    i = (bot + top) >> 1;
1269    c = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);    r = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);
1270    if (c == 0)    if (r == 0)
1271      {      {
1272      *dptr = PRIV(utt)[i].value;      *ptypeptr = PRIV(utt)[i].type;
1273      return PRIV(utt)[i].type;      *pdataptr = PRIV(utt)[i].value;
1274        return TRUE;
1275      }      }
1276    if (c > 0) bot = i + 1; else top = i;    if (r > 0) bot = i + 1; else top = i;
1277    }    }
1278    
1279  *errorcodeptr = ERR47;  *errorcodeptr = ERR47;
1280  *ptrptr = ptr;  *ptrptr = ptr;
1281  return -1;  return FALSE;
1282    
1283  ERROR_RETURN:  ERROR_RETURN:
1284  *errorcodeptr = ERR46;  *errorcodeptr = ERR46;
1285  *ptrptr = ptr;  *ptrptr = ptr;
1286  return -1;  return FALSE;
1287  }  }
1288  #endif  #endif
1289    
# Line 1297  int max = -1; Line 1318  int max = -1;
1318  /* 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
1319  an integer overflow. */  an integer overflow. */
1320    
1321  while (IS_DIGIT(*p)) min = min * 10 + *p++ - CHAR_0;  while (IS_DIGIT(*p)) min = min * 10 + (int)(*p++ - CHAR_0);
1322  if (min < 0 || min > 65535)  if (min < 0 || min > 65535)
1323    {    {
1324    *errorcodeptr = ERR5;    *errorcodeptr = ERR5;
# Line 1312  if (*p == CHAR_RIGHT_CURLY_BRACKET) max Line 1333  if (*p == CHAR_RIGHT_CURLY_BRACKET) max
1333    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)
1334      {      {
1335      max = 0;      max = 0;
1336      while(IS_DIGIT(*p)) max = max * 10 + *p++ - CHAR_0;      while(IS_DIGIT(*p)) max = max * 10 + (int)(*p++ - CHAR_0);
1337      if (max < 0 || max > 65535)      if (max < 0 || max > 65535)
1338        {        {
1339        *errorcodeptr = ERR5;        *errorcodeptr = ERR5;
# Line 1367  Arguments: Line 1388  Arguments:
1388    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1389    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1390    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1391    utf          TRUE if we are in UTF-8 / UTF-16 mode    utf          TRUE if we are in UTF-8 / UTF-16 / UTF-32 mode
1392    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1393    
1394  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 1389  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1410  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1410    {    {
1411    /* Handle specials such as (*SKIP) or (*UTF8) etc. */    /* Handle specials such as (*SKIP) or (*UTF8) etc. */
1412    
1413    if (ptr[1] == CHAR_ASTERISK) ptr += 2;    if (ptr[1] == CHAR_ASTERISK)
1414        {
1415        ptr += 2;
1416        while (ptr < cd->end_pattern && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1417        }
1418    
1419    /* Handle a normal, unnamed capturing parenthesis. */    /* Handle a normal, unnamed capturing parenthesis. */
1420    
# Line 1413  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1438  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1438    
1439    else if (ptr[2] == CHAR_NUMBER_SIGN)    else if (ptr[2] == CHAR_NUMBER_SIGN)
1440      {      {
1441      for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break;      for (ptr += 3; *ptr != CHAR_NULL; ptr++)
1442          if (*ptr == CHAR_RIGHT_PARENTHESIS) break;
1443      goto FAIL_EXIT;      goto FAIL_EXIT;
1444      }      }
1445    
# Line 1426  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1452  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1452      ptr += 2;      ptr += 2;
1453      if (ptr[1] != CHAR_QUESTION_MARK)      if (ptr[1] != CHAR_QUESTION_MARK)
1454        {        {
1455        while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;        while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1456        if (*ptr != 0) ptr++;        if (*ptr != CHAR_NULL) ptr++;
1457        }        }
1458      }      }
1459    
# Line 1443  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1469  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1469      if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&      if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&
1470          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)
1471        {        {
1472        int term;        pcre_uchar term;
1473        const pcre_uchar *thisname;        const pcre_uchar *thisname;
1474        *count += 1;        *count += 1;
1475        if (name == NULL && *count == lorn) return *count;        if (name == NULL && *count == lorn) return *count;
# Line 1451  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1477  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1477        if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;        if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;
1478        thisname = ptr;        thisname = ptr;
1479        while (*ptr != term) ptr++;        while (*ptr != term) ptr++;
1480        if (name != NULL && lorn == ptr - thisname &&        if (name != NULL && lorn == (int)(ptr - thisname) &&
1481            STRNCMP_UC_UC(name, thisname, lorn) == 0)            STRNCMP_UC_UC(name, thisname, (unsigned int)lorn) == 0)
1482          return *count;          return *count;
1483        term++;        term++;
1484        }        }
# Line 1470  for (; ptr < cd->end_pattern; ptr++) Line 1496  for (; ptr < cd->end_pattern; ptr++)
1496    
1497    if (*ptr == CHAR_BACKSLASH)    if (*ptr == CHAR_BACKSLASH)
1498      {      {
1499      if (*(++ptr) == 0) goto FAIL_EXIT;      if (*(++ptr) == CHAR_NULL) goto FAIL_EXIT;
1500      if (*ptr == CHAR_Q) for (;;)      if (*ptr == CHAR_Q) for (;;)
1501        {        {
1502        while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};        while (*(++ptr) != CHAR_NULL && *ptr != CHAR_BACKSLASH) {};
1503        if (*ptr == 0) goto FAIL_EXIT;        if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1504        if (*(++ptr) == CHAR_E) break;        if (*(++ptr) == CHAR_E) break;
1505        }        }
1506      continue;      continue;
# Line 1518  for (; ptr < cd->end_pattern; ptr++) Line 1544  for (; ptr < cd->end_pattern; ptr++)
1544    
1545      while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)      while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)
1546        {        {
1547        if (*ptr == 0) return -1;        if (*ptr == CHAR_NULL) return -1;
1548        if (*ptr == CHAR_BACKSLASH)        if (*ptr == CHAR_BACKSLASH)
1549          {          {
1550          if (*(++ptr) == 0) goto FAIL_EXIT;          if (*(++ptr) == CHAR_NULL) goto FAIL_EXIT;
1551          if (*ptr == CHAR_Q) for (;;)          if (*ptr == CHAR_Q) for (;;)
1552            {            {
1553            while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};            while (*(++ptr) != CHAR_NULL && *ptr != CHAR_BACKSLASH) {};
1554            if (*ptr == 0) goto FAIL_EXIT;            if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1555            if (*(++ptr) == CHAR_E) break;            if (*(++ptr) == CHAR_E) break;
1556            }            }
1557          continue;          continue;
# Line 1539  for (; ptr < cd->end_pattern; ptr++) Line 1565  for (; ptr < cd->end_pattern; ptr++)
1565    if (xmode && *ptr == CHAR_NUMBER_SIGN)    if (xmode && *ptr == CHAR_NUMBER_SIGN)
1566      {      {
1567      ptr++;      ptr++;
1568      while (*ptr != 0)      while (*ptr != CHAR_NULL)
1569        {        {
1570        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1571        ptr++;        ptr++;
# Line 1547  for (; ptr < cd->end_pattern; ptr++) Line 1573  for (; ptr < cd->end_pattern; ptr++)
1573        if (utf) FORWARDCHAR(ptr);        if (utf) FORWARDCHAR(ptr);
1574  #endif  #endif
1575        }        }
1576      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1577      continue;      continue;
1578      }      }
1579    
# Line 1557  for (; ptr < cd->end_pattern; ptr++) Line 1583  for (; ptr < cd->end_pattern; ptr++)
1583      {      {
1584      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);
1585      if (rc > 0) return rc;      if (rc > 0) return rc;
1586      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == CHAR_NULL) goto FAIL_EXIT;
1587      }      }
1588    
1589    else if (*ptr == CHAR_RIGHT_PARENTHESIS)    else if (*ptr == CHAR_RIGHT_PARENTHESIS)
# Line 1601  Arguments: Line 1627  Arguments:
1627    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1628    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1629    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1630    utf          TRUE if we are in UTF-8 / UTF-16 mode    utf          TRUE if we are in UTF-8 / UTF-16 / UTF-32 mode
1631    
1632  Returns:       the number of the found subpattern, or -1 if not found  Returns:       the number of the found subpattern, or -1 if not found
1633  */  */
# Line 1622  matching closing parens. That is why we Line 1648  matching closing parens. That is why we
1648  for (;;)  for (;;)
1649    {    {
1650    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);
1651    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == CHAR_NULL) break;
1652    }    }
1653    
1654  return rc;  return rc;
# Line 1704  and doing the check at the end; a flag s Line 1730  and doing the check at the end; a flag s
1730    
1731  Arguments:  Arguments:
1732    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1733    utf      TRUE in UTF-8 / UTF-16 mode    utf      TRUE in UTF-8 / UTF-16 / UTF-32 mode
1734    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1735    cd       the "compile data" structure    cd       the "compile data" structure
1736    
# Line 1730  for (;;) Line 1756  for (;;)
1756    {    {
1757    int d;    int d;
1758    pcre_uchar *ce, *cs;    pcre_uchar *ce, *cs;
1759    register int op = *cc;    register pcre_uchar op = *cc;
1760    
1761    switch (op)    switch (op)
1762      {      {
# Line 1850  for (;;) Line 1876  for (;;)
1876      case OP_EXACTI:      case OP_EXACTI:
1877      case OP_NOTEXACT:      case OP_NOTEXACT:
1878      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1879      branchlength += GET2(cc,1);      branchlength += (int)GET2(cc,1);
1880      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1881  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1882      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
# Line 1859  for (;;) Line 1885  for (;;)
1885    
1886      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1887      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1888      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP) cc += 2;      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP)
1889          cc += 2;
1890      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1891      break;      break;
1892    
# Line 1894  for (;;) Line 1921  for (;;)
1921    
1922      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1923    
 #if defined SUPPORT_UTF || defined COMPILE_PCRE16  
     case OP_XCLASS:  
     cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];  
     /* Fall through */  
 #endif  
   
1924      case OP_CLASS:      case OP_CLASS:
1925      case OP_NCLASS:      case OP_NCLASS:
1926    #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1927        case OP_XCLASS:
1928        /* The original code caused an unsigned overflow in 64 bit systems,
1929        so now we use a conditional statement. */
1930        if (op == OP_XCLASS)
1931          cc += GET(cc, 1);
1932        else
1933          cc += PRIV(OP_lengths)[OP_CLASS];
1934    #else
1935      cc += PRIV(OP_lengths)[OP_CLASS];      cc += PRIV(OP_lengths)[OP_CLASS];
1936    #endif
1937    
1938      switch (*cc)      switch (*cc)
1939        {        {
# Line 1917  for (;;) Line 1948  for (;;)
1948        case OP_CRRANGE:        case OP_CRRANGE:
1949        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1950        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1951        branchlength += GET2(cc,1);        branchlength += (int)GET2(cc,1);
1952        cc += 1 + 2 * IMM2_SIZE;        cc += 1 + 2 * IMM2_SIZE;
1953        break;        break;
1954    
# Line 2033  length. Line 2064  length.
2064    
2065  Arguments:  Arguments:
2066    code        points to start of expression    code        points to start of expression
2067    utf         TRUE in UTF-8 / UTF-16 mode    utf         TRUE in UTF-8 / UTF-16 / UTF-32 mode
2068    number      the required bracket number or negative to find a lookbehind    number      the required bracket number or negative to find a lookbehind
2069    
2070  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
# Line 2044  PRIV(find_bracket)(const pcre_uchar *cod Line 2075  PRIV(find_bracket)(const pcre_uchar *cod
2075  {  {
2076  for (;;)  for (;;)
2077    {    {
2078    register int c = *code;    register pcre_uchar c = *code;
2079    
2080    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
2081    
# Line 2067  for (;;) Line 2098  for (;;)
2098    else if (c == OP_CBRA || c == OP_SCBRA ||    else if (c == OP_CBRA || c == OP_SCBRA ||
2099             c == OP_CBRAPOS || c == OP_SCBRAPOS)             c == OP_CBRAPOS || c == OP_SCBRAPOS)
2100      {      {
2101      int n = GET2(code, 1+LINK_SIZE);      int n = (int)GET2(code, 1+LINK_SIZE);
2102      if (n == number) return (pcre_uchar *)code;      if (n == number) return (pcre_uchar *)code;
2103      code += PRIV(OP_lengths)[c];      code += PRIV(OP_lengths)[c];
2104      }      }
# Line 2097  for (;;) Line 2128  for (;;)
2128        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2129        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2130        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2131        if (code[1 + IMM2_SIZE] == OP_PROP        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2132          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;          code += 2;
2133        break;        break;
2134    
2135        case OP_MARK:        case OP_MARK:
2136        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2137        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2138        case OP_THEN_ARG:        case OP_THEN_ARG:
2139        code += code[1];        code += code[1];
2140        break;        break;
# Line 2120  for (;;) Line 2148  for (;;)
2148    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
2149    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
2150    
2151  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2152      if (utf) switch(c)      if (utf) switch(c)
2153        {        {
2154        case OP_CHAR:        case OP_CHAR:
# Line 2172  instance of OP_RECURSE. Line 2200  instance of OP_RECURSE.
2200    
2201  Arguments:  Arguments:
2202    code        points to start of expression    code        points to start of expression
2203    utf         TRUE in UTF-8 / UTF-16 mode    utf         TRUE in UTF-8 / UTF-16 / UTF-32 mode
2204    
2205  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
2206  */  */
# Line 2182  find_recurse(const pcre_uchar *code, BOO Line 2210  find_recurse(const pcre_uchar *code, BOO
2210  {  {
2211  for (;;)  for (;;)
2212    {    {
2213    register int c = *code;    register pcre_uchar c = *code;
2214    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
2215    if (c == OP_RECURSE) return code;    if (c == OP_RECURSE) return code;
2216    
# Line 2217  for (;;) Line 2245  for (;;)
2245        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2246        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2247        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2248        if (code[1 + IMM2_SIZE] == OP_PROP        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2249          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;          code += 2;
2250        break;        break;
2251    
2252        case OP_MARK:        case OP_MARK:
2253        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
2254        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
2255        case OP_THEN_ARG:        case OP_THEN_ARG:
2256        code += code[1];        code += code[1];
2257        break;        break;
# Line 2240  for (;;) Line 2265  for (;;)
2265      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
2266      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
2267    
2268  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2269      if (utf) switch(c)      if (utf) switch(c)
2270        {        {
2271        case OP_CHAR:        case OP_CHAR:
# Line 2326  bracket whose current branch will alread Line 2351  bracket whose current branch will alread
2351  Arguments:  Arguments:
2352    code        points to start of search    code        points to start of search
2353    endcode     points to where to stop    endcode     points to where to stop
2354    utf         TRUE if in UTF-8 / UTF-16 mode    utf         TRUE if in UTF-8 / UTF-16 / UTF-32 mode
2355    cd          contains pointers to tables etc.    cd          contains pointers to tables etc.
2356    
2357  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2336  static BOOL Line 2361  static BOOL
2361  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2362    BOOL utf, compile_data *cd)    BOOL utf, compile_data *cd)
2363  {  {
2364  register int c;  register pcre_uchar c;
2365  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
2366       code < endcode;       code < endcode;
2367       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))
# Line 2370  for (code = first_significant_code(code Line 2395  for (code = first_significant_code(code
2395      /* Test for forward reference */      /* Test for forward reference */
2396    
2397      for (scode = cd->start_workspace; scode < cd->hwm; scode += LINK_SIZE)      for (scode = cd->start_workspace; scode < cd->hwm; scode += LINK_SIZE)
2398        if (GET(scode, 0) == code + 1 - cd->start_code) return TRUE;        if ((int)GET(scode, 0) == (int)(code + 1 - cd->start_code)) return TRUE;
2399    
2400      /* Not a forward reference, test for completed backward reference */      /* Not a forward reference, test for completed backward reference */
2401    
# Line 2543  for (code = first_significant_code(code Line 2568  for (code = first_significant_code(code
2568      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2569      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2570      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2571      if (code[1 + IMM2_SIZE] == OP_PROP      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2572        || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;        code += 2;
2573      break;      break;
2574    
2575      /* End of branch */      /* End of branch */
# Line 2559  for (code = first_significant_code(code Line 2584  for (code = first_significant_code(code
2584      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,
2585      MINUPTO, and POSUPTO may be followed by a multibyte character */      MINUPTO, and POSUPTO may be followed by a multibyte character */
2586    
2587  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2588      case OP_STAR:      case OP_STAR:
2589      case OP_STARI:      case OP_STARI:
2590      case OP_MINSTAR:      case OP_MINSTAR:
# Line 2591  for (code = first_significant_code(code Line 2616  for (code = first_significant_code(code
2616      case OP_MARK:      case OP_MARK:
2617      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
2618      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     code += code[1];  
     break;  
   
2619      case OP_THEN_ARG:      case OP_THEN_ARG:
2620      code += code[1];      code += code[1];
2621      break;      break;
# Line 2625  Arguments: Line 2647  Arguments:
2647    code        points to start of the recursion    code        points to start of the recursion
2648    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2649    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2650    utf         TRUE if in UTF-8 / UTF-16 mode    utf         TRUE if in UTF-8 / UTF-16 / UTF-32 mode
2651    cd          pointers to tables etc    cd          pointers to tables etc
2652    
2653  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2691  Returns:   TRUE or FALSE Line 2713  Returns:   TRUE or FALSE
2713  static BOOL  static BOOL
2714  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)
2715  {  {
2716  int terminator;          /* Don't combine these lines; the Solaris cc */  pcre_uchar terminator;          /* Don't combine these lines; the Solaris cc */
2717  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */
2718  for (++ptr; *ptr != 0; ptr++)  for (++ptr; *ptr != CHAR_NULL; ptr++)
2719    {    {
2720    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2721      ptr++;      ptr++;
# Line 2740  register int yield = 0; Line 2762  register int yield = 0;
2762  while (posix_name_lengths[yield] != 0)  while (posix_name_lengths[yield] != 0)
2763    {    {
2764    if (len == posix_name_lengths[yield] &&    if (len == posix_name_lengths[yield] &&
2765      STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;      STRNCMP_UC_C8(ptr, pn, (unsigned int)len) == 0) return yield;
2766    pn += posix_name_lengths[yield] + 1;    pn += posix_name_lengths[yield] + 1;
2767    yield++;    yield++;
2768    }    }
# Line 2772  value in the reference (which is a group Line 2794  value in the reference (which is a group
2794  Arguments:  Arguments:
2795    group      points to the start of the group    group      points to the start of the group
2796    adjust     the amount by which the group is to be moved    adjust     the amount by which the group is to be moved
2797    utf        TRUE in UTF-8 / UTF-16 mode    utf        TRUE in UTF-8 / UTF-16 / UTF-32 mode
2798    cd         contains pointers to tables etc.    cd         contains pointers to tables etc.
2799    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
2800    
# Line 2795  while ((ptr = (pcre_uchar *)find_recurse Line 2817  while ((ptr = (pcre_uchar *)find_recurse
2817    
2818    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)
2819      {      {
2820      offset = GET(hc, 0);      offset = (int)GET(hc, 0);
2821      if (cd->start_code + offset == ptr + 1)      if (cd->start_code + offset == ptr + 1)
2822        {        {
2823        PUT(hc, 0, offset + adjust);        PUT(hc, 0, offset + adjust);
# Line 2808  while ((ptr = (pcre_uchar *)find_recurse Line 2830  while ((ptr = (pcre_uchar *)find_recurse
2830    
2831    if (hc >= cd->hwm)    if (hc >= cd->hwm)
2832      {      {
2833      offset = GET(ptr, 1);      offset = (int)GET(ptr, 1);
2834      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);
2835      }      }
2836    
# Line 2878  PUT(previous_callout, 2 + LINK_SIZE, len Line 2900  PUT(previous_callout, 2 + LINK_SIZE, len
2900  /* This function is passed the start and end of a class range, in UTF-8 mode  /* This function is passed the start and end of a class range, in UTF-8 mode
2901  with UCP support. It searches up the characters, looking for ranges of  with UCP support. It searches up the characters, looking for ranges of
2902  characters in the "other" case. Each call returns the next one, updating the  characters in the "other" case. Each call returns the next one, updating the
2903  start address. A character with multiple other cases is returned on its own  start address. A character with multiple other cases is returned on its own
2904  with a special return value.  with a special return value.
2905    
2906  Arguments:  Arguments:
# Line 2890  Arguments: Line 2912  Arguments:
2912  Yield:        -1 when no more  Yield:        -1 when no more
2913                 0 when a range is returned                 0 when a range is returned
2914                >0 the CASESET offset for char with multiple other cases                >0 the CASESET offset for char with multiple other cases
2915                  in this case, ocptr contains the original                  in this case, ocptr contains the original
2916  */  */
2917    
2918  static int  static int
2919  get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr,  get_othercase_range(pcre_uint32 *cptr, pcre_uint32 d, pcre_uint32 *ocptr,
2920    unsigned int *odptr)    pcre_uint32 *odptr)
2921  {  {
2922  unsigned int c, othercase, next;  pcre_uint32 c, othercase, next;
2923  int co;  unsigned int co;
2924    
2925  /* Find the first character that has an other case. If it has multiple other  /* Find the first character that has an other case. If it has multiple other
2926  cases, return its case offset value. */  cases, return its case offset value. */
2927    
2928  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2929    {    {
2930    if ((co = UCD_CASESET(c)) != 0)    if ((co = UCD_CASESET(c)) != 0)
2931      {      {
2932      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2933      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2934      return co;      return (int)co;
2935      }      }
2936    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2937    }    }
2938    
2939  if (c > d) return -1;  /* Reached end of range */  if (c > d) return -1;  /* Reached end of range */
# Line 2949  Returns:       TRUE if auto-possessifyin Line 2971  Returns:       TRUE if auto-possessifyin
2971  */  */
2972    
2973  static BOOL  static BOOL
2974  check_char_prop(int c, int ptype, int pdata, BOOL negated)  check_char_prop(pcre_uint32 c, unsigned int ptype, unsigned int pdata, BOOL negated)
2975  {  {
2976    #ifdef SUPPORT_UCP
2977    const pcre_uint32 *p;
2978    #endif
2979    
2980  const ucd_record *prop = GET_UCD(c);  const ucd_record *prop = GET_UCD(c);
2981    
2982  switch(ptype)  switch(ptype)
2983    {    {
2984    case PT_LAMP:    case PT_LAMP:
# Line 2989  switch(ptype) Line 3016  switch(ptype)
3016    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
3017            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
3018            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
3019    
3020    #ifdef SUPPORT_UCP
3021      case PT_CLIST:
3022      p = PRIV(ucd_caseless_sets) + prop->caseset;
3023      for (;;)
3024        {
3025        if (c < *p) return !negated;
3026        if (c == *p++) return negated;
3027        }
3028      break;  /* Control never reaches here */
3029    #endif
3030    }    }
3031    
3032  return FALSE;  return FALSE;
3033  }  }
3034  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 3006  sense to automatically possessify the re Line 3045  sense to automatically possessify the re
3045    
3046  Arguments:  Arguments:
3047    previous      pointer to the repeated opcode    previous      pointer to the repeated opcode
3048    utf           TRUE in UTF-8 / UTF-16 mode    utf           TRUE in UTF-8 / UTF-16 / UTF-32 mode
3049    ptr           next character in pattern    ptr           next character in pattern
3050    options       options bits    options       options bits
3051    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
# Line 3018  static BOOL Line 3057  static BOOL
3057  check_auto_possessive(const pcre_uchar *previous, BOOL utf,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
3058    const pcre_uchar *ptr, int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
3059  {  {
3060  pcre_int32 c, next;  pcre_uint32 c = NOTACHAR;
3061  int op_code = *previous++;  pcre_uint32 next;
3062    int escape;
3063    pcre_uchar op_code = *previous++;
3064    
3065  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
3066    
# Line 3031  if ((options & PCRE_EXTENDED) != 0) Line 3072  if ((options & PCRE_EXTENDED) != 0)
3072      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
3073        {        {
3074        ptr++;        ptr++;
3075        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3076          {          {
3077          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
3078          ptr++;          ptr++;
# Line 3050  value is a character, a negative value i Line 3091  value is a character, a negative value i
3091  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
3092    {    {
3093    int temperrorcode = 0;    int temperrorcode = 0;
3094    next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,
3095        FALSE);
3096    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
3097    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
3098    }    }
3099  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
3100    {    {
3101      escape = 0;
3102  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3103    if (utf) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
3104  #endif  #endif
# Line 3073  if ((options & PCRE_EXTENDED) != 0) Line 3116  if ((options & PCRE_EXTENDED) != 0)
3116      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
3117        {        {
3118        ptr++;        ptr++;
3119        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3120          {          {
3121          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
3122          ptr++;          ptr++;
# Line 3092  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 3135  if (*ptr == CHAR_ASTERISK || *ptr == CHA
3135    STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)    STRNCMP_UC_C8(ptr, STR_LEFT_CURLY_BRACKET STR_0 STR_COMMA, 3) == 0)
3136      return FALSE;      return FALSE;
3137    
3138  /* Now compare the next item with the previous opcode. First, handle cases when  /* If the previous item is a character, get its value. */
 the next item is a character. */  
3139    
3140  if (next >= 0) switch(op_code)  if (op_code == OP_CHAR || op_code == OP_CHARI ||
3141        op_code == OP_NOT || op_code == OP_NOTI)
3142    {    {
   case OP_CHAR:  
3143  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3144    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
3145  #else  #else
3146    c = *previous;    c = *previous;
3147  #endif  #endif
3148    return c != next;    }
3149    
3150    /* For CHARI (caseless character) we must check the other case. If we have  /* Now compare the next item with the previous opcode. First, handle cases when
3151    Unicode property support, we can use it to test the other case of  the next item is a character. */
   high-valued characters. */  
3152    
3153    case OP_CHARI:  if (escape == 0)
3154  #ifdef SUPPORT_UTF    {
3155    GETCHARTEST(c, previous);    /* For a caseless UTF match, the next character may have more than one other
3156  #else    case, which maps to the special PT_CLIST property. Check this first. */
3157    c = *previous;  
3158    #ifdef SUPPORT_UCP
3159      if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
3160        {
3161        unsigned int ocs = UCD_CASESET(next);
3162        if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);
3163        }
3164  #endif  #endif
3165    if (c == next) return FALSE;  
3166  #ifdef SUPPORT_UTF    switch(op_code)
   if (utf)  
3167      {      {
3168      unsigned int othercase;      case OP_CHAR:
3169      if (next < 128) othercase = cd->fcc[next]; else      return c != next;
3170    
3171        /* For CHARI (caseless character) we must check the other case. If we have
3172        Unicode property support, we can use it to test the other case of
3173        high-valued characters. We know that next can have only one other case,
3174        because multi-other-case characters are dealt with above. */
3175    
3176        case OP_CHARI:
3177        if (c == next) return FALSE;
3178    #ifdef SUPPORT_UTF
3179        if (utf)
3180          {
3181          pcre_uint32 othercase;
3182          if (next < 128) othercase = cd->fcc[next]; else
3183  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3184      othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
3185  #else  #else
3186      othercase = NOTACHAR;        othercase = NOTACHAR;
3187  #endif  #endif
3188      return (unsigned int)c != othercase;        return c != othercase;
3189      }        }
3190    else      else
3191  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3192    return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3193    
3194    case OP_NOT:      case OP_NOT:
3195  #ifdef SUPPORT_UTF      return c == next;
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   return c == next;  
3196    
3197    case OP_NOTI:      case OP_NOTI:
3198  #ifdef SUPPORT_UTF      if (c == next) return TRUE;
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   if (c == next) return TRUE;  
3199  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3200    if (utf)      if (utf)
3201      {        {
3202      unsigned int othercase;        pcre_uint32 othercase;
3203      if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
3204  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3205      othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
3206  #else  #else
3207      othercase = NOTACHAR;        othercase = NOTACHAR;
3208  #endif  #endif
3209      return (unsigned int)c == othercase;        return c == othercase;
3210      }        }
3211    else      else
3212  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3213    return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */      return (c == TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3214    
3215    /* 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.
3216    When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */      When it is set, \d etc. are converted into OP_(NOT_)PROP codes. */
3217    
3218    case OP_DIGIT:      case OP_DIGIT:
3219    return next > 255 || (cd->ctypes[next] & ctype_digit) == 0;      return next > 255 || (cd->ctypes[next] & ctype_digit) == 0;
3220    
3221    case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
3222    return next <= 255 && (cd->ctypes[next] & ctype_digit) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_digit) != 0;
3223    
3224    case OP_WHITESPACE:      case OP_WHITESPACE:
3225    return next > 255 || (cd->ctypes[next] & ctype_space) == 0;      return next > 255 || (cd->ctypes[next] & ctype_space) == 0;
3226    
3227    case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
3228    return next <= 255 && (cd->ctypes[next] & ctype_space) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_space) != 0;
3229    
3230    case OP_WORDCHAR:      case OP_WORDCHAR:
3231    return next > 255 || (cd->ctypes[next] & ctype_word) == 0;      return next > 255 || (cd->ctypes[next] & ctype_word) == 0;
3232    
3233    case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
3234    return next <= 255 && (cd->ctypes[next] & ctype_word) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_word) != 0;
3235    
3236    case OP_HSPACE:      case OP_HSPACE:
3237    case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3238    switch(next)      switch(next)
3239      {        {
3240      HSPACE_CASES:        HSPACE_CASES:
3241      return op_code == OP_NOT_HSPACE;        return op_code == OP_NOT_HSPACE;
   
     default:  
     return op_code != OP_NOT_HSPACE;  
     }  
3242    
3243    case OP_ANYNL:        default:
3244    case OP_VSPACE:        return op_code != OP_NOT_HSPACE;
3245    case OP_NOT_VSPACE:        }
3246    switch(next)  
3247      {      case OP_ANYNL:
3248      VSPACE_CASES:      case OP_VSPACE:
3249      return op_code == OP_NOT_VSPACE;      case OP_NOT_VSPACE:
3250        switch(next)
3251      default:        {
3252      return op_code != OP_NOT_VSPACE;        VSPACE_CASES:
3253      }        return op_code == OP_NOT_VSPACE;
3254    
3255          default:
3256          return op_code != OP_NOT_VSPACE;
3257          }
3258    
3259  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3260    case OP_PROP:      case OP_PROP:
3261    return check_char_prop(next, previous[0], previous[1], FALSE);      return check_char_prop(next, previous[0], previous[1], FALSE);
3262    
3263    case OP_NOTPROP:      case OP_NOTPROP:
3264    return check_char_prop(next, previous[0], previous[1], TRUE);      return check_char_prop(next, previous[0], previous[1], TRUE);
3265  #endif  #endif
3266    
3267    default:      default:
3268    return FALSE;      return FALSE;
3269        }
3270    }    }
3271    
   
3272  /* Handle the case when the next item is \d, \s, etc. Note that when PCRE_UCP  /* Handle the case when the next item is \d, \s, etc. Note that when PCRE_UCP
3273  is set, \d turns into ESC_du rather than ESC_d, etc., so ESC_d etc. are  is set, \d turns into ESC_du rather than ESC_d, etc., so ESC_d etc. are
3274  generated only when PCRE_UCP is *not* set, that is, when only ASCII  generated only when PCRE_UCP is *not* set, that is, when only ASCII
# Line 3230  switch(op_code) Line 3279  switch(op_code)
3279    {    {
3280    case OP_CHAR:    case OP_CHAR:
3281    case OP_CHARI:    case OP_CHARI:
3282  #ifdef SUPPORT_UTF    switch(escape)
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   switch(-next)  
3283      {      {
3284      case ESC_d:      case ESC_d:
3285      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;
# Line 3259  switch(op_code) Line 3303  switch(op_code)
3303      case ESC_H:      case ESC_H:
3304      switch(c)      switch(c)
3305        {        {
3306        HSPACE_CASES:        HSPACE_CASES:
3307        return -next != ESC_h;        return escape != ESC_h;
3308    
3309        default:        default:
3310        return -next == ESC_h;        return escape == ESC_h;
3311        }        }
3312    
3313      case ESC_v:      case ESC_v:
3314      case ESC_V:      case ESC_V:
3315      switch(c)      switch(c)
3316        {        {
3317        VSPACE_CASES:        VSPACE_CASES:
3318        return -next != ESC_v;        return escape != ESC_v;
3319    
3320        default:        default:
3321        return -next == ESC_v;        return escape == ESC_v;
3322        }        }
3323    
3324      /* When PCRE_UCP is set, these values get generated for \d etc. Find      /* When PCRE_UCP is set, these values get generated for \d etc. Find
3325      their substitutions and process them. The result will always be either      their substitutions and process them. The result will always be either
3326      -ESC_p or -ESC_P. Then fall through to process those values. */      ESC_p or ESC_P. Then fall through to process those values. */
3327    
3328  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3329      case ESC_du:      case ESC_du:
# Line 3290  switch(op_code) Line 3334  switch(op_code)
3334      case ESC_SU:      case ESC_SU:
3335        {        {
3336        int temperrorcode = 0;        int temperrorcode = 0;
3337        ptr = substitutes[-next - ESC_DU];        ptr = substitutes[escape - ESC_DU];
3338        next = check_escape(&ptr, &temperrorcode, 0, options, FALSE);        escape = check_escape(&ptr, &next, &temperrorcode, 0, options, FALSE);
3339        if (temperrorcode != 0) return FALSE;        if (temperrorcode != 0) return FALSE;
3340        ptr++;    /* For compatibility */        ptr++;    /* For compatibility */
3341        }        }
# Line 3300  switch(op_code) Line 3344  switch(op_code)
3344      case ESC_p:      case ESC_p:
3345      case ESC_P:      case ESC_P:
3346        {        {
3347        int ptype, pdata, errorcodeptr;        unsigned int ptype = 0, pdata = 0;
3348          int errorcodeptr;
3349        BOOL negated;        BOOL negated;
3350    
3351        ptr--;      /* Make ptr point at the p or P */        ptr--;      /* Make ptr point at the p or P */
3352        ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr);        if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcodeptr))
3353        if (ptype < 0) return FALSE;          return FALSE;
3354        ptr++;      /* Point past the final curly ket */        ptr++;      /* Point past the final curly ket */
3355    
3356        /* If the property item is optional, we have to give up. (When generated        /* If the property item is optional, we have to give up. (When generated
# Line 3318  switch(op_code) Line 3363  switch(op_code)
3363    
3364        /* Do the property check. */        /* Do the property check. */
3365    
3366        return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated);        return check_char_prop(c, ptype, pdata, (escape == ESC_P) != negated);
3367        }        }
3368  #endif  #endif
3369    
# Line 3333  switch(op_code) Line 3378  switch(op_code)
3378    these op-codes are never generated.) */    these op-codes are never generated.) */
3379    
3380    case OP_DIGIT:    case OP_DIGIT:
3381    return next == -ESC_D || next == -ESC_s || next == -ESC_W ||    return escape == ESC_D || escape == ESC_s || escape == ESC_W ||
3382           next == -ESC_h || next == -ESC_v || next == -ESC_R;           escape == ESC_h || escape == ESC_v || escape == ESC_R;
3383    
3384    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
3385    return next == -ESC_d;    return escape == ESC_d;
3386    
3387    case OP_WHITESPACE:    case OP_WHITESPACE:
3388    return next == -ESC_S || next == -ESC_d || next == -ESC_w;    return escape == ESC_S || escape == ESC_d || escape == ESC_w;
3389    
3390    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
3391    return next == -ESC_s || next == -ESC_h || next == -ESC_v || next == -ESC_R;    return escape == ESC_s || escape == ESC_h || escape == ESC_v || escape == ESC_R;
3392    
3393    case OP_HSPACE:    case OP_HSPACE:
3394    return next == -ESC_S || next == -ESC_H || next == -ESC_d ||    return escape == ESC_S || escape == ESC_H || escape == ESC_d ||
3395           next == -ESC_w || next == -ESC_v || next == -ESC_R;           escape == ESC_w || escape == ESC_v || escape == ESC_R;
3396    
3397    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3398    return next == -ESC_h;    return escape == ESC_h;
3399    
3400    /* Can't have \S in here because VT matches \S (Perl anomaly) */    /* Can't have \S in here because VT matches \S (Perl anomaly) */
3401    case OP_ANYNL:    case OP_ANYNL:
3402    case OP_VSPACE:    case OP_VSPACE:
3403    return next == -ESC_V || next == -ESC_d || next == -ESC_w;    return escape == ESC_V || escape == ESC_d || escape == ESC_w;
3404    
3405    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3406    return next == -ESC_v || next == -ESC_R;    return escape == ESC_v || escape == ESC_R;
3407    
3408    case OP_WORDCHAR:    case OP_WORDCHAR:
3409    return next == -ESC_W || next == -ESC_s || next == -ESC_h ||    return escape == ESC_W || escape == ESC_s || escape == ESC_h ||
3410           next == -ESC_v || next == -ESC_R;           escape == ESC_v || escape == ESC_R;
3411    
3412    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
3413    return next == -ESC_w || next == -ESC_d;    return escape == ESC_w || escape == ESC_d;
3414    
3415    default:    default:
3416    return FALSE;    return FALSE;
# Line 3381  switch(op_code) Line 3426  switch(op_code)
3426  *************************************************/  *************************************************/
3427    
3428  /* This function packages up the logic of adding a character or range of  /* This function packages up the logic of adding a character or range of
3429  characters to a class. The character values in the arguments will be within the  characters to a class. The character values in the arguments will be within the
3430  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3431  mutually recursive with the function immediately below.  mutually recursive with the function immediately below.
3432    
3433  Arguments:  Arguments:
3434    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3435    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3436    options       the options word    options       the options word
3437    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3438    start         start of range character    start         start of range character
3439    end           end of range character    end           end of range character
3440    
3441  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3442                  the pointer to extra data is updated                  the pointer to extra data is updated
3443  */  */
3444    
3445  static int  static int
3446  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3447    compile_data *cd, unsigned int start, unsigned int end)    compile_data *cd, pcre_uint32 start, pcre_uint32 end)
3448  {  {
3449  unsigned int c;  pcre_uint32 c;
3450  int n8 = 0;  int n8 = 0;
3451    
3452  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
3453  cases. In Unicode, there are 8-bit characters that have alternate cases that  cases. In Unicode, there are 8-bit characters that have alternate cases that
3454  are greater than 255 and vice-versa. Sometimes we can just extend the original  are greater than 255 and vice-versa. Sometimes we can just extend the original
3455  range. */  range. */
3456    
3457  if ((options & PCRE_CASELESS) != 0)  if ((options & PCRE_CASELESS) != 0)
3458    {    {
3459  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3460    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3461      {      {
3462      int rc;      int rc;
3463      unsigned int oc, od;      pcre_uint32 oc, od;
3464    
3465      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3466      c = start;      c = start;
3467    
3468      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3469        {        {
3470        /* Handle a single character that has more than one other case. */        /* Handle a single character that has more than one other case. */
3471    
3472        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3473          PRIV(ucd_caseless_sets) + rc, oc);          PRIV(ucd_caseless_sets) + rc, oc);
3474    
3475        /* Do nothing if the other case range is within the original range. */        /* Do nothing if the other case range is within the original range. */
3476    
3477        else if (oc >= start && od <= end) continue;        else if (oc >= start && od <= end) continue;
3478    
3479        /* Extend the original range if there is overlap, noting that if oc < c, we        /* Extend the original range if there is overlap, noting that if oc < c, we
3480        can't have od > end because a subrange is always shorter than the basic        can't have od > end because a subrange is always shorter than the basic
3481        range. Otherwise, use a recursive call to add the additional range. */        range. Otherwise, use a recursive call to add the additional range. */
3482    
3483        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3484        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3485        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
# Line 3444  if ((options & PCRE_CASELESS) != 0) Line 3489  if ((options & PCRE_CASELESS) != 0)
3489  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3490    
3491    /* Not UTF-mode, or no UCP */    /* Not UTF-mode, or no UCP */
3492    
3493    for (c = start; c <= end && c < 256; c++)    for (c = start; c <= end && c < 256; c++)
3494      {      {
3495      SETBIT(classbits, cd->fcc[c]);      SETBIT(classbits, cd->fcc[c]);
3496      n8++;      n8++;
3497      }      }
3498    }    }
3499    
3500  /* Now handle the original range. Adjust the final value according to the bit  /* Now handle the original range. Adjust the final value according to the bit
3501  length - this means that the same lists of (e.g.) horizontal spaces can be used  length - this means that the same lists of (e.g.) horizontal spaces can be used
3502  in all cases. */  in all cases. */
3503    
3504  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3505  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3506    if ((options & PCRE_UTF8) == 0)    if ((options & PCRE_UTF8) == 0)
3507  #endif  #endif
3508    if (end > 0xff) end = 0xff;    if (end > 0xff) end = 0xff;
 #endif  
3509    
3510  #ifdef COMPILE_PCRE16  #elif defined COMPILE_PCRE16
3511  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3512    if ((options & PCRE_UTF16) == 0)    if ((options & PCRE_UTF16) == 0)
3513  #endif  #endif
3514    if (end > 0xffff) end = 0xffff;    if (end > 0xffff) end = 0xffff;
3515  #endif  
3516    #endif /* COMPILE_PCRE[8|16] */
3517    
3518  /* If all characters are less than 256, use the bit map. Otherwise use extra  /* If all characters are less than 256, use the bit map. Otherwise use extra
3519  data. */  data. */
# Line 3477  if (end < 0x100) Line 3522  if (end < 0x100)
3522    {    {
3523    for (c = start; c <= end; c++)    for (c = start; c <= end; c++)
3524      {      {
3525      n8++;      n8++;
3526      SETBIT(classbits, c);      SETBIT(classbits, c);
3527      }      }
3528    }    }
3529    
3530  else  else
3531    {    {
3532    pcre_uchar *uchardata = *uchardptr;    pcre_uchar *uchardata = *uchardptr;
3533    
3534  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3535    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3536      {      {
3537      if (start < end)      if (start < end)
3538        {        {
3539        *uchardata++ = XCL_RANGE;        *uchardata++ = XCL_RANGE;
3540        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3541        uchardata += PRIV(ord2utf)(end, uchardata);        uchardata += PRIV(ord2utf)(end, uchardata);
3542        }        }
3543      else if (start == end)      else if (start == end)
3544        {        {
3545        *uchardata++ = XCL_SINGLE;        *uchardata++ = XCL_SINGLE;
3546        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3547        }        }
3548      }      }
3549    else    else
3550  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3551    
3552    /* Without UTF support, character values are constrained by the bit length,    /* Without UTF support, character values are constrained by the bit length,
3553    and can only be > 256 for 16-bit and 32-bit libraries. */    and can only be > 256 for 16-bit and 32-bit libraries. */
3554    
3555  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3556      {}      {}
3557  #else  #else
3558    if (start < end)    if (start < end)
3559      {      {
3560      *uchardata++ = XCL_RANGE;      *uchardata++ = XCL_RANGE;
# Line 3520  else Line 3565  else
3565      {      {
3566      *uchardata++ = XCL_SINGLE;      *uchardata++ = XCL_SINGLE;
3567      *uchardata++ = start;      *uchardata++ = start;
3568      }      }
3569  #endif  #endif
3570    
3571    *uchardptr = uchardata;   /* Updata extra data pointer */    *uchardptr = uchardata;   /* Updata extra data pointer */
3572    }    }
3573    
3574  return n8;    /* Number of 8-bit characters */  return n8;    /* Number of 8-bit characters */
3575  }  }
3576    
3577    
3578    
3579    
3580  /*************************************************  /*************************************************
3581  *        Add a list of characters to a class     *  *        Add a list of characters to a class     *
3582  *************************************************/  *************************************************/
3583    
3584  /* This function is used for adding a list of case-equivalent characters to a  /* This function is used for adding a list of case-equivalent characters to a
3585  class, and also for adding a list of horizontal or vertical whitespace. If the  class, and also for adding a list of horizontal or vertical whitespace. If the
3586  list is in order (which it should be), ranges of characters are detected and  list is in order (which it should be), ranges of characters are detected and
3587  handled appropriately. This function is mutually recursive with the function  handled appropriately. This function is mutually recursive with the function
# Line 3546  Arguments: Line 3591  Arguments:
3591    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3592    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3593    options       the options word    options       the options word
3594    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3595    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3596    except        character to omit; this is used when adding lists of    except        character to omit; this is used when adding lists of
3597                    case-equivalent characters to avoid including the one we                    case-equivalent characters to avoid including the one we
3598                    already know about                    already know about
3599    
3600  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3601                  the pointer to extra data is updated                  the pointer to extra data is updated
3602  */  */
# Line 3565  while (p[0] < NOTACHAR) Line 3610  while (p[0] < NOTACHAR)
3610    {    {
3611    int n = 0;    int n = 0;
3612    if (p[0] != except)    if (p[0] != except)
3613      {      {
3614      while(p[n+1] == p[0] + n + 1) n++;      while(p[n+1] == p[0] + n + 1) n++;
3615      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3616      }      }
3617    p += n + 1;    p += n + 1;
3618    }    }
3619  return n8;  return n8;
3620  }  }
3621    
3622    
3623    
# Line 3587  Arguments: Line 3632  Arguments:
3632    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3633    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3634    options       the options word    options       the options word
3635    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3636    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3637    
3638  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3639                  the pointer to extra data is updated                  the pointer to extra data is updated
3640  */  */
3641    
3642  static int  static int
3643  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3644    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3645  {  {
3646    BOOL utf = (options & PCRE_UTF8) != 0;
3647  int n8 = 0;  int n8 = 0;
3648  if (p[0] > 0)  if (p[0] > 0)
3649    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);
3650  while (p[0] < NOTACHAR)  while (p[0] < NOTACHAR)
3651    {    {
3652    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3653    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3654      (p[1] == NOTACHAR)? 0x10ffff : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3655    p++;    p++;
3656    }    }
3657  return n8;  return n8;
3658  }  }
3659    
3660    
3661    
# Line 3628  Arguments: Line 3674  Arguments:
3674    codeptr        points to the pointer to the current code point    codeptr        points to the pointer to the current code point
3675    ptrptr         points to the current pattern pointer    ptrptr         points to the current pattern pointer
3676    errorcodeptr   points to error code variable    errorcodeptr   points to error code variable
3677    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr    place to put the first required character
3678    reqcharptr     set to the last literal character required, else < 0    firstcharflagsptr place to put the first character flags, or a negative number
3679      reqcharptr     place to put the last required character
3680      reqcharflagsptr place to put the last required character flags, or a negative number
3681    bcptr          points to current branch chain    bcptr          points to current branch chain
3682    cond_depth     conditional nesting depth    cond_depth     conditional nesting depth
3683    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
# Line 3642  Returns:         TRUE on success Line 3690  Returns:         TRUE on success
3690    
3691  static BOOL  static BOOL
3692  compile_branch(int *optionsptr, pcre_uchar **codeptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3693    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,    const pcre_uchar **ptrptr, int *errorcodeptr,
3694    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,    pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
3695      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
3696      branch_chain *bcptr, int cond_depth,
3697    compile_data *cd, int *lengthptr)    compile_data *cd, int *lengthptr)
3698  {  {
3699  int repeat_type, op_type;  int repeat_type, op_type;
3700  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3701  int bravalue = 0;  int bravalue = 0;
3702  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3703  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
3704  pcre_int32 zeroreqchar, zerofirstchar;  pcre_int32 firstcharflags, reqcharflags;
3705    pcre_uint32 zeroreqchar, zerofirstchar;
3706    pcre_int32 zeroreqcharflags, zerofirstcharflags;
3707  pcre_int32 req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3708  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3709  int after_manual_callout = 0;  int after_manual_callout = 0;
3710  int length_prevgroup = 0;  int length_prevgroup = 0;
3711  register int c;  register pcre_uint32 c;
3712    int escape;
3713  register pcre_uchar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3714  pcre_uchar *last_code = code;  pcre_uchar *last_code = code;
3715  pcre_uchar *orig_code = code;  pcre_uchar *orig_code = code;
# Line 3676  must not do this for other options (e.g. Line 3729  must not do this for other options (e.g.
3729  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3730    
3731  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3732  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3733  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3734    #ifndef COMPILE_PCRE32
3735  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3736    #endif
3737  #else  #else
3738  BOOL utf = FALSE;  BOOL utf = FALSE;
3739  #endif  #endif
3740    
3741  /* Helper variables for OP_XCLASS opcode (for characters > 255). */  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3742    class_uchardata always so that it can be passed to add_to_class() always,
3743    though it will not be used in non-UTF 8-bit cases. This avoids having to supply
3744    alternative calls for the different cases. */
3745    
3746    pcre_uchar *class_uchardata;
3747  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3748  BOOL xclass;  BOOL xclass;
 pcre_uchar *class_uchardata;  
3749  pcre_uchar *class_uchardata_base;  pcre_uchar *class_uchardata_base;
3750  #endif  #endif
3751    
# Line 3710  to take the zero repeat into account. Th Line 3768  to take the zero repeat into account. Th
3768  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3769  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3770    
3771  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = 0;
3772    firstcharflags = reqcharflags = zerofirstcharflags = zeroreqcharflags = REQ_UNSET;
3773    
3774  /* The variable req_caseopt contains either the REQ_CASELESS value  /* The variable req_caseopt contains either the REQ_CASELESS value
3775  or zero, according to the current setting of the caseless flag. The  or zero, according to the current setting of the caseless flag. The
# Line 3736  for (;; ptr++) Line 3795  for (;; ptr++)
3795    int recno;    int recno;
3796    int refsign;    int refsign;
3797    int skipbytes;    int skipbytes;
3798    int subreqchar;    pcre_uint32 subreqchar, subfirstchar;
3799    int subfirstchar;    pcre_int32 subreqcharflags, subfirstcharflags;
3800    int terminator;    int terminator;
3801    int mclength;    unsigned int mclength;
3802    int tempbracount;    unsigned int tempbracount;
3803      pcre_uint32 ec;
3804    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3805    
3806    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 3750  for (;; ptr++) Line 3810  for (;; ptr++)
3810    /* If we are at the end of a nested substitution, revert to the outer level    /* If we are at the end of a nested substitution, revert to the outer level
3811    string. Nesting only happens one level deep. */    string. Nesting only happens one level deep. */
3812    
3813    if (c == 0 && nestptr != NULL)    if (c == CHAR_NULL && nestptr != NULL)
3814      {      {
3815      ptr = nestptr;      ptr = nestptr;
3816      nestptr = NULL;      nestptr = NULL;
# Line 3825  for (;; ptr++) Line 3885  for (;; ptr++)
3885    
3886    /* If in \Q...\E, check for the end; if not, we have a literal */    /* If in \Q...\E, check for the end; if not, we have a literal */
3887    
3888    if (inescq && c != 0)    if (inescq && c != CHAR_NULL)
3889      {      {
3890      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)
3891        {        {
# Line 3873  for (;; ptr++) Line 3933  for (;; ptr++)
3933      if (c == CHAR_NUMBER_SIGN)      if (c == CHAR_NUMBER_SIGN)
3934        {        {
3935        ptr++;        ptr++;
3936        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3937          {          {
3938          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3939          ptr++;          ptr++;
# Line 3881  for (;; ptr++) Line 3941  for (;; ptr++)
3941          if (utf) FORWARDCHAR(ptr);          if (utf) FORWARDCHAR(ptr);
3942  #endif  #endif
3943          }          }
3944        if (*ptr != 0) continue;        if (*ptr != CHAR_NULL) continue;
3945    
3946        /* Else fall through to handle end of string */        /* Else fall through to handle end of string */
3947        c = 0;        c = 0;
# Line 3903  for (;; ptr++) Line 3963  for (;; ptr++)
3963      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3964      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3965      *firstcharptr = firstchar;      *firstcharptr = firstchar;
3966        *firstcharflagsptr = firstcharflags;
3967      *reqcharptr = reqchar;      *reqcharptr = reqchar;
3968        *reqcharflagsptr = reqcharflags;
3969      *codeptr = code;      *codeptr = code;
3970      *ptrptr = ptr;      *ptrptr = ptr;
3971      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3927  for (;; ptr++) Line 3989  for (;; ptr++)
3989      previous = NULL;      previous = NULL;
3990      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3991        {        {
3992        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
3993        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3994        }        }
3995      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3942  for (;; ptr++) Line 4004  for (;; ptr++)
4004      repeats. The value of reqchar doesn't change either. */      repeats. The value of reqchar doesn't change either. */
4005    
4006      case CHAR_DOT:      case CHAR_DOT:
4007      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4008      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4009        zerofirstcharflags = firstcharflags;
4010      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4011        zeroreqcharflags = reqcharflags;
4012      previous = code;      previous = code;
4013      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
4014      break;      break;
# Line 4018  for (;; ptr++) Line 4082  for (;; ptr++)
4082          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
4083        {        {
4084        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
4085        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4086        zerofirstchar = firstchar;        zerofirstchar = firstchar;
4087          zerofirstcharflags = firstcharflags;
4088        break;        break;
4089        }        }
4090    
# Line 4054  for (;; ptr++) Line 4119  for (;; ptr++)
4119      means that an initial ] is taken as a data character. At the start of the      means that an initial ] is taken as a data character. At the start of the
4120      loop, c contains the first byte of the character. */      loop, c contains the first byte of the character. */
4121    
4122      if (c != 0) do      if (c != CHAR_NULL) do
4123        {        {
4124        const pcre_uchar *oldptr;        const pcre_uchar *oldptr;
4125    
# Line 4069  for (;; ptr++) Line 4134  for (;; ptr++)
4134        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
4135        data and reset the pointer. This is so that very large classes that        data and reset the pointer. This is so that very large classes that
4136        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
4137        (which is on the stack). We have to remember that there was XCLASS data,        (which is on the stack). We have to remember that there was XCLASS data,
4138        however. */        however. */
4139    
4140        if (lengthptr != NULL && class_uchardata > class_uchardata_base)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
# Line 4210  for (;; ptr++) Line 4275  for (;; ptr++)
4275    
4276        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4277          {          {
4278          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,
4279              TRUE);
4280          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4281            if (escape == 0) c = ec;
4282          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */          else if (escape == ESC_b) c = CHAR_BS; /* \b is backspace in a class */
4283          else if (-c == ESC_N)            /* \N is not supported in a class */          else if (escape == ESC_N)          /* \N is not supported in a class */
4284            {            {
4285            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4286            goto FAILED;            goto FAILED;
4287            }            }
4288          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (escape == ESC_Q)            /* Handle start of quoted string */
4289            {            {
4290            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
4291              {              {
# Line 4228  for (;; ptr++) Line 4294  for (;; ptr++)
4294            else inescq = TRUE;            else inescq = TRUE;
4295            continue;            continue;
4296            }            }
4297          else if (-c == ESC_E) continue;  /* Ignore orphan \E */          else if (escape == ESC_E) continue;  /* Ignore orphan \E */
4298    
4299          if (c < 0)          else
4300            {            {
4301            register const pcre_uint8 *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
4302            /* Every class contains at least two < 256 characters. */            /* Every class contains at least two < 256 characters. */
# Line 4238  for (;; ptr++) Line 4304  for (;; ptr++)
4304            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4305            class_one_char += 2;            class_one_char += 2;
4306    
4307            switch (-c)            switch (escape)
4308              {              {
4309  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4310              case ESC_du:     /* These are the values given for \d etc */              case ESC_du:     /* These are the values given for \d etc */
# Line 4248  for (;; ptr++) Line 4314  for (;; ptr++)
4314              case ESC_su:     /* of the default ASCII testing. */              case ESC_su:     /* of the default ASCII testing. */
4315              case ESC_SU:              case ESC_SU:
4316              nestptr = ptr;              nestptr = ptr;
4317              ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */              ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
4318              class_has_8bitchar--;                /* Undo! */              class_has_8bitchar--;                /* Undo! */
4319              continue;              continue;
4320  #endif  #endif
# Line 4286  for (;; ptr++) Line 4352  for (;; ptr++)
4352              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4353              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4354              continue;              continue;
4355    
4356              /* The rest apply in both UCP and non-UCP cases. */              /* The rest apply in both UCP and non-UCP cases. */
4357    
4358              case ESC_h:              case ESC_h:
4359              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4360                PRIV(hspace_list), NOTACHAR);                PRIV(hspace_list), NOTACHAR);
4361              continue;              continue;
4362    
4363              case ESC_H:              case ESC_H:
4364              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4365                cd, PRIV(hspace_list));                cd, PRIV(hspace_list));
4366              continue;              continue;
4367    
4368              case ESC_v:              case ESC_v:
4369              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4370                PRIV(vspace_list), NOTACHAR);                PRIV(vspace_list), NOTACHAR);
4371              continue;              continue;
4372    
4373              case ESC_V:              case ESC_V:
4374              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4375                cd, PRIV(vspace_list));                cd, PRIV(vspace_list));
4376              continue;              continue;
4377    
4378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4314  for (;; ptr++) Line 4380  for (;; ptr++)
4380              case ESC_P:              case ESC_P:
4381                {                {
4382                BOOL negated;                BOOL negated;
4383                int pdata;                unsigned int ptype = 0, pdata = 0;
4384                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
4385                if (ptype < 0) goto FAILED;                  goto FAILED;
4386                *class_uchardata++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4387                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4388                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
4389                *class_uchardata++ = pdata;                *class_uchardata++ = pdata;
# Line 4344  for (;; ptr++) Line 4410  for (;; ptr++)
4410    
4411          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4412          This may be greater than 256. */          This may be greater than 256. */
4413    
4414            escape = 0;
4415    
4416          }   /* End of backslash handling */          }   /* End of backslash handling */
4417    
4418        /* A character may be followed by '-' to form a range. However, Perl does        /* A character may be followed by '-' to form a range. However, Perl does
# Line 4368  for (;; ptr++) Line 4436  for (;; ptr++)
4436    
4437        if (!inescq && ptr[1] == CHAR_MINUS)        if (!inescq && ptr[1] == CHAR_MINUS)
4438          {          {
4439          int d;          pcre_uint32 d;
4440          ptr += 2;          ptr += 2;
4441          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;
4442    
# Line 4383  for (;; ptr++) Line 4451  for (;; ptr++)
4451            inescq = TRUE;            inescq = TRUE;
4452            break;            break;
4453            }            }
4454    
4455          /* Minus (hyphen) at the end of a class is treated as a literal, so put          /* Minus (hyphen) at the end of a class is treated as a literal, so put
4456          back the pointer and jump to handle the character that preceded it. */          back the pointer and jump to handle the character that preceded it. */
4457    
4458          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))          if (*ptr == CHAR_NULL || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))
4459            {            {
4460            ptr = oldptr;            ptr = oldptr;
4461            goto CLASS_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4462            }            }
4463    
4464          /* Otherwise, we have a potential range; pick up the next character */          /* Otherwise, we have a potential range; pick up the next character */
4465    
4466  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 4410  for (;; ptr++) Line 4478  for (;; ptr++)
4478    
4479          if (!inescq && d == CHAR_BACKSLASH)          if (!inescq && d == CHAR_BACKSLASH)
4480            {            {
4481            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);            int descape;
4482              descape = check_escape(&ptr, &d, errorcodeptr, cd->bracount, options, TRUE);
4483            if (*errorcodeptr != 0) goto FAILED;            if (*errorcodeptr != 0) goto FAILED;
4484    
4485            /* \b is backspace; any other special means the '-' was literal. */            /* \b is backspace; any other special means the '-' was literal. */
4486    
4487            if (d < 0)            if (descape != 0)
4488              {              {
4489              if (d == -ESC_b) d = CHAR_BS; else              if (descape == ESC_b) d = CHAR_BS; else
4490                {                {
4491                ptr = oldptr;                ptr = oldptr;
4492                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
# Line 4438  for (;; ptr++) Line 4507  for (;; ptr++)
4507          /* We have found a character range, so single character optimizations          /* We have found a character range, so single character optimizations
4508          cannot be done anymore. Any value greater than 1 indicates that there          cannot be done anymore. Any value greater than 1 indicates that there
4509          is more than one character. */          is more than one character. */
4510    
4511          class_one_char = 2;          class_one_char = 2;
4512    
4513          /* Remember an explicit \r or \n, and add the range to the class. */          /* Remember an explicit \r or \n, and add the range to the class. */
4514    
4515          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4516    
4517          class_has_8bitchar +=          class_has_8bitchar +=
4518            add_to_class(classbits, &class_uchardata, options, cd, c, d);            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4519    
4520          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4521          }          }
4522    
4523        /* Handle a single character - we can get here for a normal non-escape        /* Handle a single character - we can get here for a normal non-escape
4524        char, or after \ that introduces a single character or for an apparent        char, or after \ that introduces a single character or for an apparent
4525        range that isn't. Only the value 1 matters for class_one_char, so don't        range that isn't. Only the value 1 matters for class_one_char, so don't
4526        increase it if it is already 2 or more ... just in case there's a class        increase it if it is already 2 or more ... just in case there's a class
4527        with a zillion characters in it. */        with a zillion characters in it. */
4528    
4529        CLASS_SINGLE_CHARACTER:        CLASS_SINGLE_CHARACTER:
# Line 4473  for (;; ptr++) Line 4542  for (;; ptr++)
4542          {          {
4543          ptr++;          ptr++;
4544          zeroreqchar = reqchar;          zeroreqchar = reqchar;
4545            zeroreqcharflags = reqcharflags;
4546    
4547          if (negate_class)          if (negate_class)
4548            {            {
4549            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;  #ifdef SUPPORT_UCP
4550              int d;
4551    #endif
4552              if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4553            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4554            *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;            zerofirstcharflags = firstcharflags;
4555  #ifdef SUPPORT_UTF  
4556            if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)            /* For caseless UTF-8 mode when UCP support is available, check
4557              code += PRIV(ord2utf)(c, code);            whether this character has more than one other case. If so, generate
4558              a special OP_NOTPROP item instead of OP_NOTI. */
4559    
4560    #ifdef SUPPORT_UCP
4561              if (utf && (options & PCRE_CASELESS) != 0 &&
4562                  (d = UCD_CASESET(c)) != 0)
4563                {
4564                *code++ = OP_NOTPROP;
4565                *code++ = PT_CLIST;
4566                *code++ = d;
4567                }
4568            else            else
4569  #endif  #endif
4570              *code++ = c;            /* Char has only one other case, or UCP not available */
4571            goto NOT_CHAR;  
4572                {
4573                *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4574    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4575                if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4576                  code += PRIV(ord2utf)(c, code);
4577                else
4578    #endif
4579                  *code++ = c;
4580                }
4581    
4582              /* We are finished with this character class */
4583    
4584              goto END_CLASS;
4585            }            }
4586    
4587          /* For a single, positive character, get the value into mcbuffer, and          /* For a single, positive character, get the value into mcbuffer, and
4588          then we can handle this with the normal one-character code. */          then we can handle this with the normal one-character code. */
4589    
4590  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4591          if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)          if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4592            mclength = PRIV(ord2utf)(c, mcbuffer);            mclength = PRIV(ord2utf)(c, mcbuffer);
4593          else          else
# Line 4502  for (;; ptr++) Line 4598  for (;; ptr++)
4598            }            }
4599          goto ONE_CHAR;          goto ONE_CHAR;
4600          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4601    
4602        /* There is more than one character in the class, or an XCLASS item        /* There is more than one character in the class, or an XCLASS item
4603        has been generated. Add this character to the class. */        has been generated. Add this character to the class. */
4604    
4605        class_has_8bitchar +=        class_has_8bitchar +=
4606          add_to_class(classbits, &class_uchardata, options, cd, c, c);          add_to_class(classbits, &class_uchardata, options, cd, c, c);
4607        }        }
4608    
# Line 4514  for (;; ptr++) Line 4610  for (;; ptr++)
4610      If we are at the end of an internal nested string, revert to the outer      If we are at the end of an internal nested string, revert to the outer
4611      string. */      string. */
4612    
4613      while (((c = *(++ptr)) != 0 ||      while (((c = *(++ptr)) != CHAR_NULL ||
4614             (nestptr != NULL &&             (nestptr != NULL &&
4615               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != 0)) &&               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != CHAR_NULL)) &&
4616             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));
4617    
4618      /* Check for missing terminating ']' */      /* Check for missing terminating ']' */
4619    
4620      if (c == 0)      if (c == CHAR_NULL)
4621        {        {
4622        *errorcodeptr = ERR6;        *errorcodeptr = ERR6;
4623        goto FAILED;        goto FAILED;
4624        }        }
4625    
4626      /* We will need an XCLASS if data has been placed in class_uchardata. In      /* We will need an XCLASS if data has been placed in class_uchardata. In
4627      the second phase this is a sufficient test. However, in the pre-compile      the second phase this is a sufficient test. However, in the pre-compile
4628      phase, class_uchardata gets emptied to prevent workspace overflow, so it      phase, class_uchardata gets emptied to prevent workspace overflow, so it
4629      only if the very last character in the class needs XCLASS will it contain      only if the very last character in the class needs XCLASS will it contain
4630      anything at this point. For this reason, xclass gets set TRUE above when      anything at this point. For this reason, xclass gets set TRUE above when
4631      uchar_classdata is emptied, and that's why this code is the way it is here      uchar_classdata is emptied, and that's why this code is the way it is here
4632      instead of just doing a test on class_uchardata below. */      instead of just doing a test on class_uchardata below. */
4633    
4634  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4635      if (class_uchardata > class_uchardata_base) xclass = TRUE;      if (class_uchardata > class_uchardata_base) xclass = TRUE;
4636  #endif  #endif
# Line 4543  for (;; ptr++) Line 4639  for (;; ptr++)
4639      setting, whatever the repeat count. Any reqchar setting must remain      setting, whatever the repeat count. Any reqchar setting must remain
4640      unchanged after any kind of repeat. */      unchanged after any kind of repeat. */
4641    
4642      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4643      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4644        zerofirstcharflags = firstcharflags;
4645      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4646        zeroreqcharflags = reqcharflags;
4647    
4648      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4649      extended class, with its own opcode, unless there was a negated special      extended class, with its own opcode, unless there was a negated special
# Line 4601  for (;; ptr++) Line 4699  for (;; ptr++)
4699        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4700        }        }
4701      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4702      NOT_CHAR:  
4703        END_CLASS:
4704      break;      break;
4705    
4706    
# Line 4639  for (;; ptr++) Line 4738  for (;; ptr++)
4738      if (repeat_min == 0)      if (repeat_min == 0)
4739        {        {
4740        firstchar = zerofirstchar;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4741          firstcharflags = zerofirstcharflags;
4742        reqchar = zeroreqchar;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4743          reqcharflags = zeroreqcharflags;
4744        }        }
4745    
4746      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4725  for (;; ptr++) Line 4826  for (;; ptr++)
4826        hold the length of the character in bytes, plus UTF_LENGTH to flag that        hold the length of the character in bytes, plus UTF_LENGTH to flag that
4827        it's a length rather than a small character. */        it's a length rather than a small character. */
4828    
4829  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4830        if (utf && NOT_FIRSTCHAR(code[-1]))        if (utf && NOT_FIRSTCHAR(code[-1]))
4831          {          {
4832          pcre_uchar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
# Line 4742  for (;; ptr++) Line 4843  for (;; ptr++)
4843          {          {
4844          c = code[-1];          c = code[-1];
4845          if (*previous <= OP_CHARI && repeat_min > 1)          if (*previous <= OP_CHARI && repeat_min > 1)
4846            reqchar = c | req_caseopt | cd->req_varyopt;            {
4847              reqchar = c;
4848              reqcharflags = req_caseopt | cd->req_varyopt;
4849              }
4850          }          }
4851    
4852        /* If the repetition is unlimited, it pays to see if the next thing on        /* If the repetition is unlimited, it pays to see if the next thing on
# Line 4799  for (;; ptr++) Line 4903  for (;; ptr++)
4903    
4904        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
4905    
       /*--------------------------------------------------------------------*/  
       /* This code is obsolete from release 8.00; the restriction was finally  
       removed: */  
   
       /* All real repeats make it impossible to handle partial matching (maybe  
       one day we will be able to remove this restriction). */  
   
       /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */  
       /*--------------------------------------------------------------------*/  
   
4906        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
4907    
4908        repeat_type += op_type;        repeat_type += op_type;
# Line 4861  for (;; ptr++) Line 4955  for (;; ptr++)
4955    
4956          if (repeat_max < 0)          if (repeat_max < 0)
4957            {            {
4958  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4959            if (utf && (c & UTF_LENGTH) != 0)            if (utf && (c & UTF_LENGTH) != 0)
4960              {              {
4961              memcpy(code, utf_chars, IN_UCHARS(c & 7));              memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4886  for (;; ptr++) Line 4980  for (;; ptr++)
4980    
4981          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4982            {            {
4983  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4984            if (utf && (c & UTF_LENGTH) != 0)            if (utf && (c & UTF_LENGTH) != 0)
4985              {              {
4986              memcpy(code, utf_chars, IN_UCHARS(c & 7));              memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4916  for (;; ptr++) Line 5010  for (;; ptr++)
5010    
5011        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
5012    
5013  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
5014        if (utf && (c & UTF_LENGTH) != 0)        if (utf && (c & UTF_LENGTH) != 0)
5015          {          {
5016          memcpy(code, utf_chars, IN_UCHARS(c & 7));          memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4955  for (;; ptr++) Line 5049  for (;; ptr++)
5049          goto END_REPEAT;          goto END_REPEAT;
5050          }          }
5051    
       /*--------------------------------------------------------------------*/  
       /* This code is obsolete from release 8.00; the restriction was finally  
       removed: */  
   
       /* All real repeats make it impossible to handle partial matching (maybe  
       one day we will be able to remove this restriction). */  
   
       /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */  
       /*--------------------------------------------------------------------*/  
   
5052        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
5053          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
5054        else if (repeat_min == 1 && repeat_max == -1)        else if (repeat_min == 1 && repeat_max == -1)
# Line 5124  for (;; ptr++) Line 5208  for (;; ptr++)
5208    
5209            else            else
5210              {              {
5211              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;              if (groupsetfirstchar && reqcharflags < 0)
5212                  {
5213                  reqchar = firstchar;
5214                  reqcharflags = firstcharflags;
5215                  }
5216    
5217              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5218                {                {
# Line 5499  for (;; ptr++) Line 5587  for (;; ptr++)
5587        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
5588          {          {
5589          arg = ++ptr;          arg = ++ptr;
5590          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5591          arglen = (int)(ptr - arg);          arglen = (int)(ptr - arg);
5592          if (arglen > (int)MAX_MARK)          if ((unsigned int)arglen > MAX_MARK)
5593            {            {
5594            *errorcodeptr = ERR75;            *errorcodeptr = ERR75;
5595            goto FAILED;            goto FAILED;
# Line 5544  for (;; ptr++) Line 5632  for (;; ptr++)
5632                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5633    
5634              /* Do not set firstchar after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5635              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;              if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
5636              }              }
5637    
5638            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5613  for (;; ptr++) Line 5701  for (;; ptr++)
5701          {          {
5702          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */
5703          ptr++;          ptr++;
5704          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5705          if (*ptr == 0)          if (*ptr == CHAR_NULL)
5706            {            {
5707            *errorcodeptr = ERR18;            *errorcodeptr = ERR18;
5708            goto FAILED;            goto FAILED;
# Line 5637  for (;; ptr++) Line 5725  for (;; ptr++)
5725          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5726          case CHAR_LEFT_PARENTHESIS:          case CHAR_LEFT_PARENTHESIS:
5727          bravalue = OP_COND;       /* Conditional group */          bravalue = OP_COND;       /* Conditional group */
5728            tempptr = ptr;
5729    
5730          /* A condition can be an assertion, a number (referring to a numbered          /* A condition can be an assertion, a number (referring to a numbered
5731          group), a name (referring to a named group), or 'R', referring to          group), a name (referring to a named group), or 'R', referring to
# Line 5649  for (;; ptr++) Line 5738  for (;; ptr++)
5738          be the recursive thing or the name 'R' (and similarly for 'R' followed          be the recursive thing or the name 'R' (and similarly for 'R' followed
5739          by digits), and (b) a number could be a name that consists of digits.          by digits), and (b) a number could be a name that consists of digits.
5740          In both cases, we look for a name first; if not found, we try the other          In both cases, we look for a name first; if not found, we try the other
5741          cases. */          cases.
5742    
5743            For compatibility with auto-callouts, we allow a callout to be
5744            specified before a condition that is an assertion. First, check for the
5745            syntax of a callout; if found, adjust the temporary pointer that is
5746            used to check for an assertion condition. That's all that is needed! */
5747    
5748            if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)
5749              {
5750              for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
5751              if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
5752                tempptr += i + 1;
5753              }
5754    
5755          /* For conditions that are assertions, check the syntax, and then exit          /* For conditions that are assertions, check the syntax, and then exit
5756          the switch. This will take control down to where bracketed groups,          the switch. This will take control down to where bracketed groups,
5757          including assertions, are processed. */          including assertions, are processed. */
5758    
5759          if (ptr[1] == CHAR_QUESTION_MARK && (ptr[2] == CHAR_EQUALS_SIGN ||          if (tempptr[1] == CHAR_QUESTION_MARK &&
5760              ptr[2] == CHAR_EXCLAMATION_MARK || ptr[2] == CHAR_LESS_THAN_SIGN))                (tempptr[2] == CHAR_EQUALS_SIGN ||
5761                   tempptr[2] == CHAR_EXCLAMATION_MARK ||
5762                   tempptr[2] == CHAR_LESS_THAN_SIGN))
5763            break;            break;
5764    
5765          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
# Line 5690  for (;; ptr++) Line 5793  for (;; ptr++)
5793            }            }
5794          else          else
5795            {            {
5796            terminator = 0;            terminator = CHAR_NULL;
5797            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);
5798            }            }
5799    
# Line 5710  for (;; ptr++) Line 5813  for (;; ptr++)
5813          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)
5814            {            {
5815            if (recno >= 0)            if (recno >= 0)
5816              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;              recno = (IS_DIGIT(*ptr))? recno * 10 + (int)(*ptr - CHAR_0) : -1;
5817            ptr++;            ptr++;
5818            }            }
5819          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
5820    
5821          if ((terminator > 0 && *ptr++ != terminator) ||          if ((terminator > 0 && *ptr++ != (pcre_uchar)terminator) ||
5822              *ptr++ != CHAR_RIGHT_PARENTHESIS)              *ptr++ != CHAR_RIGHT_PARENTHESIS)
5823            {            {
5824            ptr--;      /* Error offset */            ptr--;      /* Error offset */
# Line 5780  for (;; ptr++) Line 5883  for (;; ptr++)
5883            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
5884            }            }
5885    
5886          /* If terminator == 0 it means that the name followed directly after          /* If terminator == CHAR_NULL it means that the name followed directly
5887          the opening parenthesis [e.g. (?(abc)...] and in this case there are          after the opening parenthesis [e.g. (?(abc)...] and in this case there
5888          some further alternatives to try. For the cases where terminator != 0          are some further alternatives to try. For the cases where terminator !=
5889          [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have          0 [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have
5890          now checked all the possibilities, so give an error. */          now checked all the possibilities, so give an error. */
5891    
5892          else if (terminator != 0)          else if (terminator != CHAR_NULL)
5893            {            {
5894            *errorcodeptr = ERR15;            *errorcodeptr = ERR15;
5895            goto FAILED;            goto FAILED;
# Line 5955  for (;; ptr++) Line 6058  for (;; ptr++)
6058    
6059            if (lengthptr != NULL)            if (lengthptr != NULL)
6060              {              {
6061              if (*ptr != terminator)              if (*ptr != (pcre_uchar)terminator)
6062                {                {
6063                *errorcodeptr = ERR42;                *errorcodeptr = ERR42;
6064                goto FAILED;                goto FAILED;
# Line 6097  for (;; ptr++) Line 6200  for (;; ptr++)
6200              *errorcodeptr = ERR62;              *errorcodeptr = ERR62;
6201              goto FAILED;              goto FAILED;
6202              }              }
6203            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6204              {              {
6205              *errorcodeptr = ERR42;              *errorcodeptr = ERR42;
6206              goto FAILED;              goto FAILED;
# Line 6203  for (;; ptr++) Line 6306  for (;; ptr++)
6306            while(IS_DIGIT(*ptr))            while(IS_DIGIT(*ptr))
6307              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6308    
6309            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6310              {              {
6311              *errorcodeptr = ERR29;              *errorcodeptr = ERR29;
6312              goto FAILED;              goto FAILED;
# Line 6307  for (;; ptr++) Line 6410  for (;; ptr++)
6410    
6411          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6412    
6413          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6414          continue;          continue;
6415    
6416    
# Line 6441  for (;; ptr++) Line 6544  for (;; ptr++)
6544           cond_depth +           cond_depth +
6545             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6546           &subfirstchar,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6547             &subfirstcharflags,
6548           &subreqchar,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6549             &subreqcharflags,
6550           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6551           cd,                              /* Tables block */           cd,                              /* Tables block */
6552           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 6502  for (;; ptr++) Line 6607  for (;; ptr++)
6607            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6608            goto FAILED;            goto FAILED;
6609            }            }
6610          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;          if (condcount == 1) subfirstcharflags = subreqcharflags = REQ_NONE;
6611          }          }
6612        }        }
6613    
# Line 6551  for (;; ptr++) Line 6656  for (;; ptr++)
6656      back off. */      back off. */
6657    
6658      zeroreqchar = reqchar;      zeroreqchar = reqchar;
6659        zeroreqcharflags = reqcharflags;
6660      zerofirstchar = firstchar;      zerofirstchar = firstchar;
6661        zerofirstcharflags = firstcharflags;
6662      groupsetfirstchar = FALSE;      groupsetfirstchar = FALSE;
6663    
6664      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
# Line 6562  for (;; ptr++) Line 6669  for (;; ptr++)
6669        no firstchar, set "none" for the whole branch. In both cases, a zero        no firstchar, set "none" for the whole branch. In both cases, a zero
6670        repeat forces firstchar to "none". */        repeat forces firstchar to "none". */
6671    
6672        if (firstchar == REQ_UNSET)        if (firstcharflags == REQ_UNSET)
6673          {          {
6674          if (subfirstchar >= 0)          if (subfirstcharflags >= 0)
6675            {            {
6676            firstchar = subfirstchar;            firstchar = subfirstchar;
6677              firstcharflags = subfirstcharflags;
6678            groupsetfirstchar = TRUE;            groupsetfirstchar = TRUE;
6679            }            }
6680          else firstchar = REQ_NONE;          else firstcharflags = REQ_NONE;
6681          zerofirstchar = REQ_NONE;          zerofirstcharflags = REQ_NONE;
6682          }          }
6683    
6684        /* If firstchar was previously set, convert the subpattern's firstchar        /* If firstchar was previously set, convert the subpattern's firstchar
6685        into reqchar if there wasn't one, using the vary flag that was in        into reqchar if there wasn't one, using the vary flag that was in
6686        existence beforehand. */        existence beforehand. */
6687    
6688        else if (subfirstchar >= 0 && subreqchar < 0)        else if (subfirstcharflags >= 0 && subreqcharflags < 0)
6689          subreqchar = subfirstchar | tempreqvary;          {
6690            subreqchar = subfirstchar;
6691            subreqcharflags = subfirstcharflags | tempreqvary;
6692            }
6693    
6694        /* If the subpattern set a required byte (or set a first byte that isn't        /* If the subpattern set a required byte (or set a first byte that isn't
6695        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6696    
6697        if (subreqchar >= 0) reqchar = subreqchar;        if (subreqcharflags >= 0)
6698            {
6699            reqchar = subreqchar;
6700            reqcharflags = subreqcharflags;
6701            }
6702        }        }
6703    
6704      /* For a forward assertion, we take the reqchar, if set. This can be      /* For a forward assertion, we take the reqchar, if set. This can be
# Line 6594  for (;; ptr++) Line 6709  for (;; ptr++)
6709      of a firstchar. This is overcome by a scan at the end if there's no      of a firstchar. This is overcome by a scan at the end if there's no
6710      firstchar, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6711    
6712      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;      else if (bravalue == OP_ASSERT && subreqcharflags >= 0)
6713          {
6714          reqchar = subreqchar;
6715          reqcharflags = subreqcharflags;
6716          }
6717      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6718    
6719    
# Line 6602  for (;; ptr++) Line 6721  for (;; ptr++)
6721      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values
6722      are arranged to be the negation of the corresponding OP_values in the      are arranged to be the negation of the corresponding OP_values in the
6723      default case when PCRE_UCP is not set. For the back references, the values      default case when PCRE_UCP is not set. For the back references, the values
6724      are ESC_REF plus the reference number. Only back references and those types      are negative the reference number. Only back references and those types
6725      that consume a character may be repeated. We can test for values between      that consume a character may be repeated. We can test for values between
6726      ESC_b and ESC_Z for the latter; this may have to change if any new ones are      ESC_b and ESC_Z for the latter; this may have to change if any new ones are
6727      ever created. */      ever created. */
6728    
6729      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6730      tempptr = ptr;      tempptr = ptr;
6731      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
6732      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6733    
6734      if (c < 0)      if (escape == 0)                  /* The escape coded a single character */
6735          c = ec;
6736        else
6737        {        {
6738        if (-c == ESC_Q)            /* Handle start of quoted string */        if (escape == ESC_Q)            /* Handle start of quoted string */
6739          {          {
6740          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
6741            ptr += 2;               /* avoid empty string */            ptr += 2;               /* avoid empty string */
# Line 6622  for (;; ptr++) Line 6743  for (;; ptr++)
6743          continue;          continue;
6744          }          }
6745    
6746        if (-c == ESC_E) continue;  /* Perl ignores an orphan \E */        if (escape == ESC_E) continue;  /* Perl ignores an orphan \E */
6747    
6748        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6749        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6750    
6751        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstcharflags == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6752          firstchar = REQ_NONE;          firstcharflags = REQ_NONE;
6753    
6754        /* Set values to reset to if this is followed by a zero repeat. */        /* Set values to reset to if this is followed by a zero repeat. */
6755    
6756        zerofirstchar = firstchar;        zerofirstchar = firstchar;
6757          zerofirstcharflags = firstcharflags;
6758        zeroreqchar = reqchar;        zeroreqchar = reqchar;
6759          zeroreqcharflags = reqcharflags;
6760    
6761        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'        /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
6762        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
6763        -ESC_g is returned only for these cases. So we don't need to check for <        ESC_g is returned only for these cases. So we don't need to check for <
6764        or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is        or ' if the value is ESC_g. For the Perl syntax \g{n} the value is
6765        -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as        -n, and for the Perl syntax \g{name} the result is ESC_k (as
6766        that is a synonym for a named back reference). */        that is a synonym for a named back reference). */
6767    
6768        if (-c == ESC_g)        if (escape == ESC_g)
6769          {          {
6770          const pcre_uchar *p;          const pcre_uchar *p;
6771          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
# Line 6662  for (;; ptr++) Line 6785  for (;; ptr++)
6785          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)
6786            {            {
6787            BOOL is_a_number = TRUE;            BOOL is_a_number = TRUE;
6788            for (p = ptr + 1; *p != 0 && *p != terminator; p++)            for (p = ptr + 1; *p != CHAR_NULL && *p != (pcre_uchar)terminator; p++)
6789              {              {
6790              if (!MAX_255(*p)) { is_a_number = FALSE; break; }              if (!MAX_255(*p)) { is_a_number = FALSE; break; }
6791              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;
6792              if ((cd->ctypes[*p] & ctype_word) == 0) break;              if ((cd->ctypes[*p] & ctype_word) == 0) break;
6793              }              }
6794            if (*p != terminator)            if (*p != (pcre_uchar)terminator)
6795              {              {
6796              *errorcodeptr = ERR57;              *errorcodeptr = ERR57;
6797              break;              break;
# Line 6686  for (;; ptr++) Line 6809  for (;; ptr++)
6809    
6810          p = ptr + 2;          p = ptr + 2;
6811          while (IS_DIGIT(*p)) p++;          while (IS_DIGIT(*p)) p++;
6812          if (*p != terminator)          if (*p != (pcre_uchar)terminator)
6813            {            {
6814            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
6815            break;            break;
# Line 6698  for (;; ptr++) Line 6821  for (;; ptr++)
6821        /* \k<name> or \k'name' is a back reference by name (Perl syntax).        /* \k<name> or \k'name' is a back reference by name (Perl syntax).
6822        We also support \k{name} (.NET syntax).  */        We also support \k{name} (.NET syntax).  */
6823    
6824        if (-c == ESC_k)        if (escape == ESC_k)
6825          {          {
6826          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&
6827            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))
# Line 6717  for (;; ptr++) Line 6840  for (;; ptr++)
6840        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
6841        ':' later. */        ':' later. */
6842    
6843        if (-c >= ESC_REF)        if (escape < 0)
6844          {          {
6845          open_capitem *oc;          open_capitem *oc;
6846          recno = -c - ESC_REF;          recno = -escape;
6847    
6848          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6849          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6850          previous = code;          previous = code;
6851          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6852          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6747  for (;; ptr++) Line 6870  for (;; ptr++)
6870        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
6871    
6872  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6873        else if (-c == ESC_P || -c == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6874          {          {
6875          BOOL negated;          BOOL negated;
6876          int pdata;          unsigned int ptype = 0, pdata = 0;
6877          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
6878          if (ptype < 0) goto FAILED;            goto FAILED;
6879          previous = code;          previous = code;
6880          *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6881          *code++ = ptype;          *code++ = ptype;
6882          *code++ = pdata;          *code++ = pdata;
6883          }          }
# Line 6763  for (;; ptr++) Line 6886  for (;; ptr++)
6886        /* If Unicode properties are not supported, \X, \P, and \p are not        /* If Unicode properties are not supported, \X, \P, and \p are not
6887        allowed. */        allowed. */
6888    
6889        else if (-c == ESC_X || -c == ESC_P || -c == ESC_p)        else if (escape == ESC_X || escape == ESC_P || escape == ESC_p)
6890          {          {
6891          *errorcodeptr = ERR45;          *errorcodeptr = ERR45;
6892          goto FAILED;          goto FAILED;
# Line 6774  for (;; ptr++) Line 6897  for (;; ptr++)
6897        can obtain the OP value by negating the escape value in the default        can obtain the OP value by negating the escape value in the default
6898        situation when PCRE_UCP is not set. When it *is* set, we substitute        situation when PCRE_UCP is not set. When it *is* set, we substitute
6899        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6900        lookbehind. */        lookbehind, and \A also behaves as if it does. */
6901    
6902        else        else
6903          {          {
6904          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&
6905                 cd->max_lookbehind == 0)
6906            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6907  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6908          if (-c >= ESC_DU && -c <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
6909            {            {
6910            nestptr = ptr + 1;                   /* Where to resume */            nestptr = ptr + 1;                   /* Where to resume */
6911            ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */            ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
6912            }            }
6913          else          else
6914  #endif  #endif
# Line 6792  for (;; ptr++) Line 6916  for (;; ptr++)
6916          so that it works in DFA mode and in lookbehinds. */          so that it works in DFA mode and in lookbehinds. */
6917    
6918            {            {
6919            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (escape > ESC_b && escape < ESC_Z)? code : NULL;
6920            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;            *code++ = (!utf && escape == ESC_C)? OP_ALLANY : escape;
6921            }            }
6922          }          }
6923        continue;        continue;
# Line 6803  for (;; ptr++) Line 6927  for (;; ptr++)
6927      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
6928      handle it as a data character. */      handle it as a data character. */
6929    
6930  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
6931      if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)      if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
6932        mclength = PRIV(ord2utf)(c, mcbuffer);        mclength = PRIV(ord2utf)(c, mcbuffer);
6933      else      else
# Line 6836  for (;; ptr++) Line 6960  for (;; ptr++)
6960    
6961      ONE_CHAR:      ONE_CHAR:
6962      previous = code;      previous = code;
6963    
6964        /* For caseless UTF-8 mode when UCP support is available, check whether
6965        this character has more than one other case. If so, generate a special
6966        OP_PROP item instead of OP_CHARI. */
6967    
6968    #ifdef SUPPORT_UCP
6969        if (utf && (options & PCRE_CASELESS) != 0)
6970          {
6971          GETCHAR(c, mcbuffer);
6972          if ((c = UCD_CASESET(c)) != 0)
6973            {
6974            *code++ = OP_PROP;
6975            *code++ = PT_CLIST;
6976            *code++ = c;
6977            if (firstcharflags == REQ_UNSET) firstcharflags = zerofirstcharflags = REQ_NONE;
6978            break;
6979            }
6980          }
6981    #endif
6982    
6983        /* Caseful matches, or not one of the multicase characters. */
6984    
6985      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6986      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6987    
# Line 6849  for (;; ptr++) Line 6995  for (;; ptr++)
6995      Otherwise, leave the firstchar value alone, and don't change it on a zero      Otherwise, leave the firstchar value alone, and don't change it on a zero
6996      repeat. */      repeat. */
6997    
6998      if (firstchar == REQ_UNSET)      if (firstcharflags == REQ_UNSET)
6999        {        {
7000        zerofirstchar = REQ_NONE;        zerofirstcharflags = REQ_NONE;
7001        zeroreqchar = reqchar;        zeroreqchar = reqchar;
7002          zeroreqcharflags = reqcharflags;
7003    
7004        /* If the character is more than one byte long, we can set firstchar        /* If the character is more than one byte long, we can set firstchar
7005        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
# Line 6860  for (;; ptr++) Line 7007  for (;; ptr++)
7007        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
7008          {          {
7009          firstchar = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
7010          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;          firstchar = mcbuffer[0];
7011            firstcharflags = req_caseopt;
7012    
7013            if (mclength != 1)
7014              {
7015              reqchar = code[-1];
7016              reqcharflags = cd->req_varyopt;
7017              }
7018          }          }
7019        else firstchar = reqchar = REQ_NONE;        else firstcharflags = reqcharflags = REQ_NONE;
7020        }        }
7021    
7022      /* firstchar was previously set; we can set reqchar only if the length is      /* firstchar was previously set; we can set reqchar only if the length is
# Line 6871  for (;; ptr++) Line 7025  for (;; ptr++)
7025      else      else
7026        {        {
7027        zerofirstchar = firstchar;        zerofirstchar = firstchar;
7028          zerofirstcharflags = firstcharflags;
7029        zeroreqchar = reqchar;        zeroreqchar = reqchar;
7030          zeroreqcharflags = reqcharflags;
7031        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
7032          reqchar = code[-1] | req_caseopt | cd->req_varyopt;          {
7033            reqchar = code[-1];
7034            reqcharflags = req_caseopt | cd->req_varyopt;
7035            }
7036        }        }
7037    
7038      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6892  return FALSE; Line 7051  return FALSE;
7051    
7052    
7053    
   
7054  /*************************************************  /*************************************************
7055  *     Compile sequence of alternatives           *  *     Compile sequence of alternatives           *
7056  *************************************************/  *************************************************/
# Line 6913  Arguments: Line 7071  Arguments:
7071    reset_bracount TRUE to reset the count for each branch    reset_bracount TRUE to reset the count for each branch
7072    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes      skip this many bytes at start (for brackets and OP_COND)
7073    cond_depth     depth of nesting for conditional subpatterns    cond_depth     depth of nesting for conditional subpatterns
7074    firstcharptr   place to put the first required character, or a negative number    firstcharptr    place to put the first required character
7075    reqcharptr     place to put the last required character, or a negative number    firstcharflagsptr place to put the first character flags, or a negative number
7076      reqcharptr     place to put the last required character
7077      reqcharflagsptr place to put the last required character flags, or a negative number
7078    bcptr          pointer to the chain of currently open branches    bcptr          pointer to the chain of currently open branches
7079    cd             points to the data block with tables pointers etc.    cd             points to the data block with tables pointers etc.
7080    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
# Line 6926  Returns:         TRUE on success Line 7086  Returns:         TRUE on success
7086  static BOOL  static BOOL
7087  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
7088    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
7089    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,    int cond_depth,
7090      pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
7091      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
7092    branch_chain *bcptr, compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
7093  {  {
7094  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
# Line 6936  pcre_uchar *start_bracket = code; Line 7098  pcre_uchar *start_bracket = code;
7098  pcre_uchar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
7099  open_capitem capitem;  open_capitem capitem;
7100  int capnumber = 0;  int capnumber = 0;
7101  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
7102  pcre_int32 branchfirstchar, branchreqchar;  pcre_int32 firstcharflags, reqcharflags;
7103    pcre_uint32 branchfirstchar, branchreqchar;
7104    pcre_int32 branchfirstcharflags, branchreqcharflags;
7105  int length;  int length;
7106  int orig_bracount;  unsigned int orig_bracount;
7107  int max_bracount;  unsigned int max_bracount;
7108  branch_chain bc;  branch_chain bc;
7109    
7110  bc.outer = bcptr;  bc.outer = bcptr;
7111  bc.current_branch = code;  bc.current_branch = code;
7112    
7113  firstchar = reqchar = REQ_UNSET;  firstchar = reqchar = 0;
7114    firstcharflags = reqcharflags = REQ_UNSET;
7115    
7116  /* Accumulate the length for use in the pre-compile phase. Start with the  /* Accumulate the length for use in the pre-compile phase. Start with the
7117  length of the BRA and KET and any extra bytes that are required at the  length of the BRA and KET and any extra bytes that are required at the
# Line 7006  for (;;) Line 7171  for (;;)
7171    into the length. */    into the length. */
7172    
7173    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
7174          &branchreqchar, &bc, cond_depth, cd,          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,
7175          (lengthptr == NULL)? NULL : &length))          cond_depth, cd, (lengthptr == NULL)? NULL : &length))
7176      {      {
7177      *ptrptr = ptr;      *ptrptr = ptr;
7178      return FALSE;      return FALSE;
# Line 7028  for (;;) Line 7193  for (;;)
7193      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
7194        {        {
7195        firstchar = branchfirstchar;        firstchar = branchfirstchar;
7196          firstcharflags = branchfirstcharflags;
7197        reqchar = branchreqchar;        reqchar = branchreqchar;
7198          reqcharflags = branchreqcharflags;
7199        }        }
7200    
7201      /* If this is not the first branch, the first char and reqchar have to      /* If this is not the first branch, the first char and reqchar have to
# Line 7042  for (;;) Line 7209  for (;;)
7209        we have to abandon the firstchar for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
7210        previously no reqchar, it takes on the value of the old firstchar. */        previously no reqchar, it takes on the value of the old firstchar. */
7211    
7212        if (firstchar >= 0 && firstchar != branchfirstchar)        if (firstcharflags >= 0 &&
7213              (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))
7214          {          {
7215          if (reqchar < 0) reqchar = firstchar;          if (reqcharflags < 0)
7216          firstchar = REQ_NONE;            {
7217              reqchar = firstchar;
7218              reqcharflags = firstcharflags;
7219              }
7220            firstcharflags = REQ_NONE;
7221          }          }
7222    
7223        /* If we (now or from before) have no firstchar, a firstchar from the        /* If we (now or from before) have no firstchar, a firstchar from the
7224        branch becomes a reqchar if there isn't a branch reqchar. */        branch becomes a reqchar if there isn't a branch reqchar. */
7225    
7226        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)        if (firstcharflags < 0 && branchfirstcharflags >= 0 && branchreqcharflags < 0)
7227            branchreqchar = branchfirstchar;          {
7228            branchreqchar = branchfirstchar;
7229            branchreqcharflags = branchfirstcharflags;
7230            }
7231    
7232        /* Now ensure that the reqchars match */        /* Now ensure that the reqchars match */
7233    
7234        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))        if (((reqcharflags & ~REQ_VARY) != (branchreqcharflags & ~REQ_VARY)) ||
7235          reqchar = REQ_NONE;            reqchar != branchreqchar)
7236        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */          reqcharflags = REQ_NONE;
7237          else
7238            {
7239            reqchar = branchreqchar;
7240            reqcharflags |= branchreqcharflags; /* To "or" REQ_VARY */
7241            }
7242        }        }
7243    
7244      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
# Line 7154  for (;;) Line 7334  for (;;)
7334      *codeptr = code;      *codeptr = code;
7335      *ptrptr = ptr;      *ptrptr = ptr;
7336      *firstcharptr = firstchar;      *firstcharptr = firstchar;
7337        *firstcharflagsptr = firstcharflags;
7338      *reqcharptr = reqchar;      *reqcharptr = reqchar;
7339        *reqcharflagsptr = reqcharflags;
7340      if (lengthptr != NULL)      if (lengthptr != NULL)
7341        {        {
7342        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 7389  do { Line 7571  do {
7571       {       {
7572       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7573       }       }
7574    
7575     /* Atomic brackets */     /* Atomic brackets */
7576    
7577     else if (op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
# Line 7441  we return that char, otherwise -1. Line 7623  we return that char, otherwise -1.
7623    
7624  Arguments:  Arguments:
7625    code       points to start of expression (the bracket)    code       points to start of expression (the bracket)
7626      flags       points to the first char flags, or to REQ_NONE
7627    inassert   TRUE if in an assertion    inassert   TRUE if in an assertion
7628    
7629  Returns:     -1 or the fixed first char  Returns:     the fixed first char, or 0 with REQ_NONE in flags
7630  */  */
7631    
7632  static int  static pcre_uint32
7633  find_firstassertedchar(const pcre_uchar *code, BOOL inassert)  find_firstassertedchar(const pcre_uchar *code, pcre_int32 *flags,
7634      BOOL inassert)
7635  {  {
7636  register int c = -1;  register pcre_uint32 c = 0;
7637    int cflags = REQ_NONE;
7638    
7639    *flags = REQ_NONE;
7640  do {  do {
7641     int d;     pcre_uint32 d;
7642       int dflags;
7643     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||
7644               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;
7645     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,
7646       TRUE);       TRUE);
7647     register int op = *scode;     register pcre_uchar op = *scode;
7648    
7649     switch(op)     switch(op)
7650       {       {
7651       default:       default:
7652       return -1;       return 0;
7653    
7654       case OP_BRA:       case OP_BRA:
7655       case OP_BRAPOS:       case OP_BRAPOS:
# Line 7473  do { Line 7661  do {
7661       case OP_ONCE:       case OP_ONCE:
7662       case OP_ONCE_NC:       case OP_ONCE_NC:
7663       case OP_COND:       case OP_COND:
7664       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       d = find_firstassertedchar(scode, &dflags, op == OP_ASSERT);
7665         return -1;       if (dflags < 0)
7666       if (c < 0) c = d; else if (c != d) return -1;         return 0;
7667         if (cflags < 0) { c = d; cflags = dflags; } else if (c != d || cflags != dflags) return 0;
7668       break;       break;
7669    
7670       case OP_EXACT:       case OP_EXACT:
# Line 7486  do { Line 7675  do {
7675       case OP_PLUS:       case OP_PLUS:
7676       case OP_MINPLUS:       case OP_MINPLUS:
7677       case OP_POSPLUS:       case OP_POSPLUS:
7678       if (!inassert) return -1;       if (!inassert) return 0;
7679       if (c < 0) c = scode[1];       if (cflags < 0) { c = scode[1]; cflags = 0; }
7680         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7681       break;       break;
7682    
7683       case OP_EXACTI:       case OP_EXACTI:
# Line 7499  do { Line 7688  do {
7688       case OP_PLUSI:       case OP_PLUSI:
7689       case OP_MINPLUSI:       case OP_MINPLUSI:
7690       case OP_POSPLUSI:       case OP_POSPLUSI:
7691       if (!inassert) return -1;       if (!inassert) return 0;
7692       if (c < 0) c = scode[1] | REQ_CASELESS;       if (cflags < 0) { c = scode[1]; cflags = REQ_CASELESS; }
7693         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7694       break;       break;
7695       }       }
7696    
7697     code += GET(code, 1);     code += GET(code, 1);
7698     }     }
7699  while (*code == OP_ALT);  while (*code == OP_ALT);
7700    
7701    *flags = cflags;
7702  return c;  return c;
7703  }  }
7704    
# Line 7535  Returns:        pointer to compiled data Line 7726  Returns:        pointer to compiled data
7726                  with errorptr and erroroffset set                  with errorptr and erroroffset set
7727  */  */
7728    
7729  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7730  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7731  pcre_compile(const char *pattern, int options, const char **errorptr,  pcre_compile(const char *pattern, int options, const char **errorptr,
7732    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7733  #else  #elif defined COMPILE_PCRE16
7734  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION
7735  pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,  pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,
7736    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7737    #elif defined COMPILE_PCRE32
7738    PCRE_EXP_DEFN pcre32 * PCRE_CALL_CONVENTION
7739    pcre32_compile(PCRE_SPTR32 pattern, int options, const char **errorptr,
7740      int *erroroffset, const unsigned char *tables)
7741  #endif  #endif
7742  {  {
7743  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7744  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7745  #else  #elif defined COMPILE_PCRE16
7746  return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7747    #elif defined COMPILE_PCRE32
7748    return pcre32_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7749  #endif  #endif
7750  }  }
7751    
7752    
7753  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7754  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7755  pcre_compile2(const char *pattern, int options, int *errorcodeptr,  pcre_compile2(const char *pattern, int options, int *errorcodeptr,
7756    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7757  #else  #elif defined COMPILE_PCRE16
7758  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION
7759  pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,  pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,
7760    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7761    #elif defined COMPILE_PCRE32
7762    PCRE_EXP_DEFN pcre32 * PCRE_CALL_CONVENTION
7763    pcre32_compile2(PCRE_SPTR32 pattern, int options, int *errorcodeptr,
7764      const char **errorptr, int *erroroffset, const unsigned char *tables)
7765  #endif  #endif
7766  {  {
7767  REAL_PCRE *re;  REAL_PCRE *re;
7768  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7769  pcre_int32 firstchar, reqchar;  pcre_int32 firstcharflags, reqcharflags;
7770    pcre_uint32 firstchar, reqchar;
7771    pcre_uint32 limit_match = PCRE_UINT32_MAX;
7772    pcre_uint32 limit_recursion = PCRE_UINT32_MAX;
7773  int newline;  int newline;
7774  int errorcode = 0;  int errorcode = 0;
7775  int skipatstart = 0;  int skipatstart = 0;
7776  BOOL utf;  BOOL utf;
7777    BOOL never_utf = FALSE;
7778  size_t size;  size_t size;
7779  pcre_uchar *code;  pcre_uchar *code;
7780  const pcre_uchar *codestart;  const pcre_uchar *codestart;
# Line 7629  if ((options & ~PUBLIC_COMPILE_OPTIONS) Line 7834  if ((options & ~PUBLIC_COMPILE_OPTIONS)
7834    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
7835    }    }
7836    
7837    /* If PCRE_NEVER_UTF is set, remember it. */
7838    
7839    if ((options & PCRE_NEVER_UTF) != 0) never_utf = TRUE;
7840    
7841  /* Check for global one-time settings at the start of the pattern, and remember  /* Check for global one-time settings at the start of the pattern, and remember
7842  the offset for later. */  the offset for later. */
7843    
7844    cd->external_flags = 0;   /* Initialize here for LIMIT_MATCH/RECURSION */
7845    
7846  while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS &&  while (ptr[skipatstart] == CHAR_LEFT_PARENTHESIS &&
7847         ptr[skipatstart+1] == CHAR_ASTERISK)         ptr[skipatstart+1] == CHAR_ASTERISK)
7848    {    {
7849    int newnl = 0;    int newnl = 0;
7850    int newbsr = 0;    int newbsr = 0;
7851    
7852    /* For completeness and backward compatibility, (*UTFn) is supported in the
7853    relevant libraries, but (*UTF) is generic and always supported. Note that
7854    PCRE_UTF8 == PCRE_UTF16 == PCRE_UTF32. */
7855    
7856  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
7857    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
7858      { skipatstart += 7; options |= PCRE_UTF8; continue; }      { skipatstart += 7; options |= PCRE_UTF8; continue; }
7859  #endif  #endif
7860  #ifdef COMPILE_PCRE16  #ifdef COMPILE_PCRE16
7861    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 6) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF16_RIGHTPAR, 6) == 0)
7862      { skipatstart += 8; options |= PCRE_UTF16; continue; }      { skipatstart += 8; options |= PCRE_UTF16; continue; }
7863  #endif  #endif
7864    #ifdef COMPILE_PCRE32
7865      if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF32_RIGHTPAR, 6) == 0)
7866        { skipatstart += 8; options |= PCRE_UTF32; continue; }
7867    #endif
7868    
7869      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF_RIGHTPAR, 4) == 0)
7870        { skipatstart += 6; options |= PCRE_UTF8; continue; }
7871    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
7872      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7873    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
7874      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }
7875    
7876      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LIMIT_MATCH_EQ, 12) == 0)
7877        {
7878        pcre_uint32 c = 0;
7879        int p = skipatstart + 14;
7880        while (isdigit(ptr[p]))
7881          {
7882          if (c > PCRE_UINT32_MAX / 10 - 1) break;   /* Integer overflow */
7883          c = c*10 + ptr[p++] - CHAR_0;
7884          }
7885        if (ptr[p++] != CHAR_RIGHT_PARENTHESIS) break;
7886        if (c < limit_match)
7887          {
7888          limit_match = c;
7889          cd->external_flags |= PCRE_MLSET;
7890          }
7891        skipatstart = p;
7892        continue;
7893        }
7894    
7895      else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LIMIT_RECURSION_EQ, 16) == 0)
7896        {
7897        pcre_uint32 c = 0;
7898        int p = skipatstart + 18;
7899        while (isdigit(ptr[p]))
7900          {
7901          if (c > PCRE_UINT32_MAX / 10 - 1) break;   /* Integer overflow check */
7902          c = c*10 + ptr[p++] - CHAR_0;
7903          }
7904        if (ptr[p++] != CHAR_RIGHT_PARENTHESIS) break;
7905        if (c < limit_recursion)
7906          {
7907          limit_recursion = c;
7908          cd->external_flags |= PCRE_RLSET;
7909          }
7910        skipatstart = p;
7911        continue;
7912        }
7913    
7914    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)
7915      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
7916    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)
# Line 7674  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7934  while (ptr[skipatstart] == CHAR_LEFT_PAR
7934    else break;    else break;
7935    }    }
7936    
7937  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF(16|32) have the same value as PCRE_UTF8. */
7938  utf = (options & PCRE_UTF8) != 0;  utf = (options & PCRE_UTF8) != 0;
7939    if (utf && never_utf)
7940      {
7941      errorcode = ERR78;
7942      goto PCRE_EARLY_ERROR_RETURN2;
7943      }
7944    
7945  /* Can't support UTF unless PCRE has been compiled to include the code. The  /* Can't support UTF unless PCRE has been compiled to include the code. The
7946  return of an error code from PRIV(valid_utf)() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
# Line 7686  not used here. */ Line 7951  not used here. */
7951  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&
7952       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)
7953    {    {
7954  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7955    errorcode = ERR44;    errorcode = ERR44;
7956  #else  #elif defined COMPILE_PCRE16
7957    errorcode = ERR74;    errorcode = ERR74;
7958    #elif defined COMPILE_PCRE32
7959      errorcode = ERR77;
7960  #endif  #endif
7961    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
7962    }    }
# Line 7796  cd->req_varyopt = 0; Line 8063  cd->req_varyopt = 0;
8063  cd->assert_depth = 0;  cd->assert_depth = 0;
8064  cd->max_lookbehind = 0;  cd->max_lookbehind = 0;
8065  cd->external_options = options;  cd->external_options = options;
 cd->external_flags = 0;  
8066  cd->open_caps = NULL;  cd->open_caps = NULL;
8067    
8068  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we
# Line 7809  ptr += skipatstart; Line 8075  ptr += skipatstart;
8075  code = cworkspace;  code = cworkspace;
8076  *code = OP_BRA;  *code = OP_BRA;
8077  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,
8078    FALSE, 0, 0, &firstchar, &reqchar, NULL, cd, &length);    FALSE, 0, 0, &firstchar, &firstcharflags, &reqchar, &reqcharflags, NULL,
8079      cd, &length);
8080  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
8081    
8082  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,
# Line 7845  re->magic_number = MAGIC_NUMBER; Line 8112  re->magic_number = MAGIC_NUMBER;
8112  re->size = (int)size;  re->size = (int)size;
8113  re->options = cd->external_options;  re->options = cd->external_options;
8114  re->flags = cd->external_flags;  re->flags = cd->external_flags;
8115    re->limit_match = limit_match;
8116    re->limit_recursion = limit_recursion;
8117  re->first_char = 0;  re->first_char = 0;
8118  re->req_char = 0;  re->req_char = 0;
8119  re->name_table_offset = sizeof(REAL_PCRE) / sizeof(pcre_uchar);  re->name_table_offset = sizeof(REAL_PCRE) / sizeof(pcre_uchar);
# Line 7853  re->name_count = cd->names_found; Line 8122  re->name_count = cd->names_found;
8122  re->ref_count = 0;  re->ref_count = 0;
8123  re->tables = (tables == PRIV(default_tables))? NULL : tables;  re->tables = (tables == PRIV(default_tables))? NULL : tables;
8124  re->nullpad = NULL;  re->nullpad = NULL;
8125    #ifdef COMPILE_PCRE32
8126    re->dummy = 0;
8127    #else
8128    re->dummy1 = re->dummy2 = re->dummy3 = 0;
8129    #endif
8130    
8131  /* The starting points of the name/number translation table and of the code are  /* The starting points of the name/number translation table and of the code are
8132  passed around in the compile data block. The start/end pattern and initial  passed around in the compile data block. The start/end pattern and initial
# Line 7884  ptr = (const pcre_uchar *)pattern + skip Line 8158  ptr = (const pcre_uchar *)pattern + skip
8158  code = (pcre_uchar *)codestart;  code = (pcre_uchar *)codestart;
8159  *code = OP_BRA;  *code = OP_BRA;
8160  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,
8161    &firstchar, &reqchar, NULL, cd, NULL);    &firstchar, &firstcharflags, &reqchar, &reqcharflags, NULL, cd, NULL);
8162  re->top_bracket = cd->bracount;  re->top_bracket = cd->bracount;
8163  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
8164  re->max_lookbehind = cd->max_lookbehind;  re->max_lookbehind = cd->max_lookbehind;
8165  re->flags = cd->external_flags | PCRE_MODE;  re->flags = cd->external_flags | PCRE_MODE;
8166    
8167  if (cd->had_accept) reqchar = REQ_NONE;   /* Must disable after (*ACCEPT) */  if (cd->had_accept)
8168      {
8169      reqchar = 0;              /* Must disable after (*ACCEPT) */
8170      reqcharflags = REQ_NONE;
8171      }
8172    
8173  /* 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. */
8174    
8175  if (errorcode == 0 && *ptr != 0) errorcode = ERR22;  if (errorcode == 0 && *ptr != CHAR_NULL) errorcode = ERR22;
8176    
8177  /* Fill in the terminating state and check for disastrous overflow, but  /* Fill in the terminating state and check for disastrous overflow, but
8178  if debugging, leave the test till after things are printed out. */  if debugging, leave the test till after things are printed out. */
# Line 7905  if debugging, leave the test till after Line 8183  if debugging, leave the test till after
8183  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
8184  #endif  #endif
8185    
8186    #ifdef SUPPORT_VALGRIND
8187    /* If the estimated length exceeds the really used length, mark the extra
8188    allocated memory as unaddressable, so that any out-of-bound reads can be
8189    detected. */
8190    VALGRIND_MAKE_MEM_NOACCESS(code, (length - (code - codestart)) * sizeof(pcre_uchar));
8191    #endif
8192    
8193  /* Fill in any forward references that are required. There may be repeated  /* Fill in any forward references that are required. There may be repeated
8194  references; optimize for them, as searching a large regex takes time. */  references; optimize for them, as searching a large regex takes time. */
8195    
# Line 7940  if (errorcode == 0 && re->top_backref > Line 8225  if (errorcode == 0 && re->top_backref >
8225    
8226  /* If there were any lookbehind assertions that contained OP_RECURSE  /* If there were any lookbehind assertions that contained OP_RECURSE
8227  (recursions or subroutine calls), a flag is set for them to be checked here,  (recursions or subroutine calls), a flag is set for them to be checked here,
8228  because they may contain forward references. Actual recursions can't be fixed  because they may contain forward references. Actual recursions cannot be fixed
8229  length, but subroutine calls can. It is done like this so that those without  length, but subroutine calls can. It is done like this so that those without
8230  OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The  OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The
8231  exceptional ones forgo this. We scan the pattern to check that they are fixed  exceptional ones forgo this. We scan the pattern to check that they are fixed
# Line 8011  if ((re->options & PCRE_ANCHORED) == 0) Line 8296  if ((re->options & PCRE_ANCHORED) == 0)
8296    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;    if (is_anchored(codestart, 0, cd, 0)) re->options |= PCRE_ANCHORED;
8297    else    else
8298      {      {
8299      if (firstchar < 0)      if (firstcharflags < 0)
8300        firstchar = find_firstassertedchar(codestart, FALSE);        firstchar = find_firstassertedchar(codestart, &firstcharflags, FALSE);
8301      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */      if (firstcharflags >= 0)   /* Remove caseless flag for non-caseable chars */
8302        {        {
8303  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8304        re->first_char = firstchar & 0xff;        re->first_char = firstchar & 0xff;
8305  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
8306        re->first_char = firstchar & 0xffff;        re->first_char = firstchar & 0xffff;
8307    #elif defined COMPILE_PCRE32
8308          re->first_char = firstchar;
8309  #endif  #endif
8310  #endif        if ((firstcharflags & REQ_CASELESS) != 0)
       if ((firstchar & REQ_CASELESS) != 0)  
8311          {          {
8312  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
8313          /* We ignore non-ASCII first chars in 8 bit mode. */          /* We ignore non-ASCII first chars in 8 bit mode. */
# Line 8054  if ((re->options & PCRE_ANCHORED) == 0) Line 8339  if ((re->options & PCRE_ANCHORED) == 0)
8339  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
8340  bytes. */  bytes. */
8341    
8342  if (reqchar >= 0 &&  if (reqcharflags >= 0 &&
8343       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))       ((re->options & PCRE_ANCHORED) == 0 || (reqcharflags & REQ_VARY) != 0))
8344    {    {
8345  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8346    re->req_char = reqchar & 0xff;    re->req_char = reqchar & 0xff;
8347  #else  #elif defined COMPILE_PCRE16
 #ifdef COMPILE_PCRE16  
8348    re->req_char = reqchar & 0xffff;    re->req_char = reqchar & 0xffff;
8349    #elif defined COMPILE_PCRE32
8350      re->req_char = reqchar;
8351  #endif  #endif
8352  #endif    if ((reqcharflags & REQ_CASELESS) != 0)
   if ((reqchar & REQ_CASELESS) != 0)  
8353      {      {
8354  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)  #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
8355      /* We ignore non-ASCII first chars in 8 bit mode. */      /* We ignore non-ASCII first chars in 8 bit mode. */
# Line 8114  if ((re->flags & PCRE_REQCHSET) != 0) Line 8399  if ((re->flags & PCRE_REQCHSET) != 0)
8399      else printf("Req char = \\x%02x%s\n", ch, caseless);      else printf("Req char = \\x%02x%s\n", ch, caseless);
8400    }    }
8401    
8402  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8403  pcre_printint((pcre *)re, stdout, TRUE);  pcre_printint((pcre *)re, stdout, TRUE);
8404  #else  #elif defined COMPILE_PCRE16
8405  pcre16_printint((pcre *)re, stdout, TRUE);  pcre16_printint((pcre *)re, stdout, TRUE);
8406    #elif defined COMPILE_PCRE32
8407    pcre32_printint((pcre *)re, stdout, TRUE);
8408  #endif  #endif
8409    
8410  /* This check is done here in the debugging case so that the code that  /* This check is done here in the debugging case so that the code that
# Line 8133  if (code - codestart > length) Line 8420  if (code - codestart > length)
8420    }    }
8421  #endif   /* PCRE_DEBUG */  #endif   /* PCRE_DEBUG */
8422    
8423  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
8424  return (pcre *)re;  return (pcre *)re;
8425  #else  #elif defined COMPILE_PCRE16
8426  return (pcre16 *)re;  return (pcre16 *)re;
8427    #elif defined COMPILE_PCRE32
8428    return (pcre32 *)re;
8429  #endif  #endif
8430  }  }
8431    

Legend:
Removed from v.1045  
changed lines
  Added in v.1325

  ViewVC Help
Powered by ViewVC 1.1.5