/[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 964 by ph10, Fri May 4 13:03:39 2012 UTC revision 1313 by ph10, Wed Apr 24 12:07:09 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 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 68  COMPILE_PCREx macro will already be appr Line 68  COMPILE_PCREx macro will already be appr
68    
69  /* Macro for setting individual bits in class bitmaps. */  /* Macro for setting individual bits in class bitmaps. */
70    
71  #define SETBIT(a,b) a[b/8] |= (1 << (b%8))  #define SETBIT(a,b) a[(b)/8] |= (1 << ((b)&7))
72    
73  /* Maximum length value to check against when making sure that the integer that  /* Maximum length value to check against when making sure that the integer that
74  holds the compiled pattern length does not overflow. We make it a bit less than  holds the compiled pattern length does not overflow. We make it a bit less than
# Line 77  to check them every time. */ Line 77  to check them every time. */
77    
78  #define OFLOW_MAX (INT_MAX - 20)  #define OFLOW_MAX (INT_MAX - 20)
79    
80    /* Definitions to allow mutual recursion */
81    
82    static int
83      add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84        const pcre_uint32 *, unsigned int);
85    
86    static BOOL
87      compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
88        pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,
89        compile_data *, int *);
90    
91    
92    
93  /*************************************************  /*************************************************
94  *      Code parameters and static tables         *  *      Code parameters and static tables         *
# Line 110  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 472  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 490  static const char error_texts[] = Line 505  static const char error_texts[] =
505    "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0"    "disallowed Unicode code point (>= 0xd800 && <= 0xdfff)\0"
506    "invalid UTF-16 string\0"    "invalid UTF-16 string\0"
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"
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 630  static const pcre_uint8 ebcdic_chartab[] Line 648  static const pcre_uint8 ebcdic_chartab[]
648  #endif  #endif
649    
650    
 /* Definition to allow mutual recursion */  
   
 static BOOL  
   compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,  
     int *, int *, branch_chain *, compile_data *, int *);  
   
   
651    
652  /*************************************************  /*************************************************
653  *            Find an error text                  *  *            Find an error text                  *
# Line 657  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 741  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 775  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 784  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 < '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 797  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 822  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 831  else Line 847  else
847            c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
848  #endif  #endif
849            }            }
850    
851    #if defined COMPILE_PCRE8
852            if (c > (utf ? 0x10ffffU : 0xffU))
853    #elif defined COMPILE_PCRE16
854            if (c > (utf ? 0x10ffffU : 0xffffU))
855    #elif defined COMPILE_PCRE32
856            if (utf && c > 0x10ffffU)
857    #endif
858              {
859              *errorcodeptr = ERR76;
860              }
861            else if (utf && c >= 0xd800 && c <= 0xdfff) *errorcodeptr = ERR73;
862          }          }
863        }        }
864      else      else
# Line 857  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 872  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 892  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 916  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 924  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 954  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 1020  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 1038  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 1051  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 1082  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 1101  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 1141  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 1171  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 1202  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 1227  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 1279  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 1294  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 1349  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 1371  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 1395  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 1408  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 1425  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 1433  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 1452  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 1500  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 1521  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 1529  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 1539  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 1583  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 1604  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 1686  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 1712  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 1832  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 1841  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 1876  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 1899  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 2015  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 2026  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 2049  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 2079  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 2102  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 2154  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 2164  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 2199  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 2222  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 2308  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 2318  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 2352  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 2525  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 2541  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 2573  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 2607  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 2673  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 2722  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 2754  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 2777  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 2790  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 2858  PUT(previous_callout, 2 + LINK_SIZE, len Line 2898  PUT(previous_callout, 2 + LINK_SIZE, len
2898  *************************************************/  *************************************************/
2899    
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 internal 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.  start address. A character with multiple other cases is returned on its own
2904    with a special return value.
2905    
2906  Arguments:  Arguments:
2907    cptr        points to starting character value; updated    cptr        points to starting character value; updated
# Line 2868  Arguments: Line 2909  Arguments:
2909    ocptr       where to put start of othercase range    ocptr       where to put start of othercase range
2910    odptr       where to put end of othercase range    odptr       where to put end of othercase range
2911    
2912  Yield:        TRUE when range returned; FALSE when no more  Yield:        -1 when no more
2913                   0 when a range is returned
2914                  >0 the CASESET offset for char with multiple other cases
2915                    in this case, ocptr contains the original
2916  */  */
2917    
2918  static BOOL  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    unsigned int co;
2924    
2925    /* Find the first character that has an other case. If it has multiple other
2926    cases, return its case offset value. */
2927    
2928  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2929    { if ((othercase = UCD_OTHERCASE(c)) != c) break; }    {
2930      if ((co = UCD_CASESET(c)) != 0)
2931        {
2932        *ocptr = c++;   /* Character that has the set */
2933        *cptr = c;      /* Rest of input range */
2934        return (int)co;
2935        }
2936      if ((othercase = UCD_OTHERCASE(c)) != c) break;
2937      }
2938    
2939  if (c > d) return FALSE;  if (c > d) return -1;  /* Reached end of range */
2940    
2941  *ocptr = othercase;  *ocptr = othercase;
2942  next = othercase + 1;  next = othercase + 1;
# Line 2891  for (++c; c <= d; c++) Line 2947  for (++c; c <= d; c++)
2947    next++;    next++;
2948    }    }
2949    
2950  *odptr = next - 1;  *odptr = next - 1;     /* End of othercase range */
2951  *cptr = c;  *cptr = c;             /* Rest of input range */
2952    return 0;
 return TRUE;  
2953  }  }
2954    
2955    
# Line 2916  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 2956  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 2973  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 2985  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 2998  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 3017  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 3040  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 3059  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      case 0x09:        HSPACE_CASES:
3241      case 0x20:        return op_code == OP_NOT_HSPACE;
     case 0xa0:  
     case 0x1680:  
     case 0x180e:  
     case 0x2000:  
     case 0x2001:  
     case 0x2002:  
     case 0x2003:  
     case 0x2004:  
     case 0x2005:  
     case 0x2006:  
     case 0x2007:  
     case 0x2008:  
     case 0x2009:  
     case 0x200A:  
     case 0x202f:  
     case 0x205f:  
     case 0x3000:  
     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      case 0x0a:      case OP_VSPACE:
3249      case 0x0b:      case OP_NOT_VSPACE:
3250      case 0x0c:      switch(next)
3251      case 0x0d:        {
3252      case 0x85:        VSPACE_CASES:
3253      case 0x2028:        return op_code == OP_NOT_VSPACE;
3254      case 0x2029:  
3255      return op_code == OP_NOT_VSPACE;        default:
3256      default:        return op_code != OP_NOT_VSPACE;
3257      return op_code != OP_NOT_VSPACE;        }
     }  
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 3219  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 3248  switch(op_code) Line 3303  switch(op_code)
3303      case ESC_H:      case ESC_H:
3304      switch(c)      switch(c)
3305        {        {
3306        case 0x09:        HSPACE_CASES:
3307        case 0x20:        return escape != ESC_h;
3308        case 0xa0:  
       case 0x1680:  
       case 0x180e:  
       case 0x2000:  
       case 0x2001:  
       case 0x2002:  
       case 0x2003:  
       case 0x2004:  
       case 0x2005:  
       case 0x2006:  
       case 0x2007:  
       case 0x2008:  
       case 0x2009:  
       case 0x200A:  
       case 0x202f:  
       case 0x205f:  
       case 0x3000:  
       return -next != ESC_h;  
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        case 0x0a:        VSPACE_CASES:
3318        case 0x0b:        return escape != ESC_v;
3319        case 0x0c:  
       case 0x0d:  
       case 0x85:  
       case 0x2028:  
       case 0x2029:  
       return -next != ESC_v;  
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 3301  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 3311  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 3329  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 3344  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 3388  switch(op_code) Line 3422  switch(op_code)
3422    
3423    
3424  /*************************************************  /*************************************************
3425    *        Add a character or range to a class     *
3426    *************************************************/
3427    
3428    /* 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
3430    valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3431    mutually recursive with the function immediately below.
3432    
3433    Arguments:
3434      classbits     the bit map for characters < 256
3435      uchardptr     points to the pointer for extra data
3436      options       the options word
3437      cd            contains pointers to tables etc.
3438      start         start of range character
3439      end           end of range character
3440    
3441    Returns:        the number of < 256 characters added
3442                    the pointer to extra data is updated
3443    */
3444    
3445    static int
3446    add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3447      compile_data *cd, pcre_uint32 start, pcre_uint32 end)
3448    {
3449    pcre_uint32 c;
3450    int n8 = 0;
3451    
3452    /* 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
3454    are greater than 255 and vice-versa. Sometimes we can just extend the original
3455    range. */
3456    
3457    if ((options & PCRE_CASELESS) != 0)
3458      {
3459    #ifdef SUPPORT_UCP
3460      if ((options & PCRE_UTF8) != 0)
3461        {
3462        int rc;
3463        pcre_uint32 oc, od;
3464    
3465        options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3466        c = start;
3467    
3468        while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3469          {
3470          /* 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,
3473            PRIV(ucd_caseless_sets) + rc, oc);
3474    
3475          /* Do nothing if the other case range is within the original range. */
3476    
3477          else if (oc >= start && od <= end) continue;
3478    
3479          /* 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
3481          range. Otherwise, use a recursive call to add the additional range. */
3482    
3483          else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3484          else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3485          else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
3486          }
3487        }
3488      else
3489    #endif  /* SUPPORT_UCP */
3490    
3491      /* Not UTF-mode, or no UCP */
3492    
3493      for (c = start; c <= end && c < 256; c++)
3494        {
3495        SETBIT(classbits, cd->fcc[c]);
3496        n8++;
3497        }
3498      }
3499    
3500    /* 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
3502    in all cases. */
3503    
3504    #if defined COMPILE_PCRE8
3505    #ifdef SUPPORT_UTF
3506      if ((options & PCRE_UTF8) == 0)
3507    #endif
3508      if (end > 0xff) end = 0xff;
3509    
3510    #elif defined COMPILE_PCRE16
3511    #ifdef SUPPORT_UTF
3512      if ((options & PCRE_UTF16) == 0)
3513    #endif
3514      if (end > 0xffff) end = 0xffff;
3515    
3516    #endif /* COMPILE_PCRE[8|16] */
3517    
3518    /* If all characters are less than 256, use the bit map. Otherwise use extra
3519    data. */
3520    
3521    if (end < 0x100)
3522      {
3523      for (c = start; c <= end; c++)
3524        {
3525        n8++;
3526        SETBIT(classbits, c);
3527        }
3528      }
3529    
3530    else
3531      {
3532      pcre_uchar *uchardata = *uchardptr;
3533    
3534    #ifdef SUPPORT_UTF
3535      if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3536        {
3537        if (start < end)
3538          {
3539          *uchardata++ = XCL_RANGE;
3540          uchardata += PRIV(ord2utf)(start, uchardata);
3541          uchardata += PRIV(ord2utf)(end, uchardata);
3542          }
3543        else if (start == end)
3544          {
3545          *uchardata++ = XCL_SINGLE;
3546          uchardata += PRIV(ord2utf)(start, uchardata);
3547          }
3548        }
3549      else
3550    #endif  /* SUPPORT_UTF */
3551    
3552      /* Without UTF support, character values are constrained by the bit length,
3553      and can only be > 256 for 16-bit and 32-bit libraries. */
3554    
3555    #ifdef COMPILE_PCRE8
3556        {}
3557    #else
3558      if (start < end)
3559        {
3560        *uchardata++ = XCL_RANGE;
3561        *uchardata++ = start;
3562        *uchardata++ = end;
3563        }
3564      else if (start == end)
3565        {
3566        *uchardata++ = XCL_SINGLE;
3567        *uchardata++ = start;
3568        }
3569    #endif
3570    
3571      *uchardptr = uchardata;   /* Updata extra data pointer */
3572      }
3573    
3574    return n8;    /* Number of 8-bit characters */
3575    }
3576    
3577    
3578    
3579    
3580    /*************************************************
3581    *        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
3585    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
3587    handled appropriately. This function is mutually recursive with the function
3588    above.
3589    
3590    Arguments:
3591      classbits     the bit map for characters < 256
3592      uchardptr     points to the pointer for extra data
3593      options       the options word
3594      cd            contains pointers to tables etc.
3595      p             points to row of 32-bit values, terminated by NOTACHAR
3596      except        character to omit; this is used when adding lists of
3597                      case-equivalent characters to avoid including the one we
3598                      already know about
3599    
3600    Returns:        the number of < 256 characters added
3601                    the pointer to extra data is updated
3602    */
3603    
3604    static int
3605    add_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3606      compile_data *cd, const pcre_uint32 *p, unsigned int except)
3607    {
3608    int n8 = 0;
3609    while (p[0] < NOTACHAR)
3610      {
3611      int n = 0;
3612      if (p[0] != except)
3613        {
3614        while(p[n+1] == p[0] + n + 1) n++;
3615        n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3616        }
3617      p += n + 1;
3618      }
3619    return n8;
3620    }
3621    
3622    
3623    
3624    /*************************************************
3625    *    Add characters not in a list to a class     *
3626    *************************************************/
3627    
3628    /* This function is used for adding the complement of a list of horizontal or
3629    vertical whitespace to a class. The list must be in order.
3630    
3631    Arguments:
3632      classbits     the bit map for characters < 256
3633      uchardptr     points to the pointer for extra data
3634      options       the options word
3635      cd            contains pointers to tables etc.
3636      p             points to row of 32-bit values, terminated by NOTACHAR
3637    
3638    Returns:        the number of < 256 characters added
3639                    the pointer to extra data is updated
3640    */
3641    
3642    static int
3643    add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3644      int options, compile_data *cd, const pcre_uint32 *p)
3645    {
3646    BOOL utf = (options & PCRE_UTF8) != 0;
3647    int n8 = 0;
3648    if (p[0] > 0)
3649      n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);
3650    while (p[0] < NOTACHAR)
3651      {
3652      while (p[1] == p[0] + 1) p++;
3653      n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3654        (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3655      p++;
3656      }
3657    return n8;
3658    }
3659    
3660    
3661    
3662    /*************************************************
3663  *           Compile one branch                   *  *           Compile one branch                   *
3664  *************************************************/  *************************************************/
3665    
# Line 3402  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 3416  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 3450  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 3484  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 3505  for (;; ptr++) Line 3790  for (;; ptr++)
3790    BOOL is_recurse;    BOOL is_recurse;
3791    BOOL reset_bracount;    BOOL reset_bracount;
3792    int class_has_8bitchar;    int class_has_8bitchar;
3793    int class_single_char;    int class_one_char;
3794    int newoptions;    int newoptions;
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 3524  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 3599  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 3647  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 3655  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 3677  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 3701  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 3716  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 3792  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 3803  for (;; ptr++) Line 4094  for (;; ptr++)
4094    
4095      should_flip_negation = FALSE;      should_flip_negation = FALSE;
4096    
4097      /* For optimization purposes, we track some properties of the class.      /* For optimization purposes, we track some properties of the class:
4098      class_has_8bitchar will be non-zero, if the class contains at least one      class_has_8bitchar will be non-zero if the class contains at least one <
4099      < 256 character. class_single_char will be 1 if the class contains only      256 character; class_one_char will be 1 if the class contains just one
4100      a single character. */      character. */
4101    
4102      class_has_8bitchar = 0;      class_has_8bitchar = 0;
4103      class_single_char = 0;      class_one_char = 0;
4104    
4105      /* Initialize the 32-char bit map to all zeros. We build the map in a      /* Initialize the 32-char bit map to all zeros. We build the map in a
4106      temporary bit of memory, in case the class contains only 1 character (less      temporary bit of memory, in case the class contains fewer than two
4107      than 256), because in that case the compiled code doesn't use the bit map.      8-bit characters because in that case the compiled code doesn't use the bit
4108      */      map. */
4109    
4110      memset(classbits, 0, 32 * sizeof(pcre_uint8));      memset(classbits, 0, 32 * sizeof(pcre_uint8));
4111    
4112  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4113      xclass = FALSE;                           /* No chars >= 256 */      xclass = FALSE;
4114      class_uchardata = code + LINK_SIZE + 2;   /* For UTF-8 items */      class_uchardata = code + LINK_SIZE + 2;   /* For XCLASS items */
4115      class_uchardata_base = class_uchardata;   /* For resetting in pass 1 */      class_uchardata_base = class_uchardata;   /* Save the start */
4116  #endif  #endif
4117    
4118      /* Process characters until ] is reached. By writing this as a "do" it      /* Process characters until ] is reached. By writing this as a "do" it
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 3843  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). */        (which is on the stack). We have to remember that there was XCLASS data,
4138          however. */
4139    
4140        if (lengthptr != NULL)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
4141          {          {
4142            xclass = TRUE;
4143          *lengthptr += class_uchardata - class_uchardata_base;          *lengthptr += class_uchardata - class_uchardata_base;
4144          class_uchardata = class_uchardata_base;          class_uchardata = class_uchardata_base;
4145          }          }
# Line 3948  for (;; ptr++) Line 4241  for (;; ptr++)
4241              for (c = 0; c < 32; c++) pbits[c] &= ~cbits[c + taboffset];              for (c = 0; c < 32; c++) pbits[c] &= ~cbits[c + taboffset];
4242            }            }
4243    
4244          /* Not see if we need to remove any special characters. An option          /* Now see if we need to remove any special characters. An option
4245          value of 1 removes vertical space and 2 removes underscore. */          value of 1 removes vertical space and 2 removes underscore. */
4246    
4247          if (tabopt < 0) tabopt = -tabopt;          if (tabopt < 0) tabopt = -tabopt;
# Line 3964  for (;; ptr++) Line 4257  for (;; ptr++)
4257            for (c = 0; c < 32; c++) classbits[c] |= pbits[c];            for (c = 0; c < 32; c++) classbits[c] |= pbits[c];
4258    
4259          ptr = tempptr + 1;          ptr = tempptr + 1;
4260          /* Every class contains at least one < 256 characters. */          /* Every class contains at least one < 256 character. */
4261          class_has_8bitchar = 1;          class_has_8bitchar = 1;
4262          /* Every class contains at least two characters. */          /* Every class contains at least two characters. */
4263          class_single_char = 2;          class_one_char = 2;
4264          continue;    /* End of POSIX syntax handling */          continue;    /* End of POSIX syntax handling */
4265          }          }
4266    
# Line 3975  for (;; ptr++) Line 4268  for (;; ptr++)
4268        of the specials, which just set a flag. The sequence \b is a special        of the specials, which just set a flag. The sequence \b is a special
4269        case. Inside a class (and only there) it is treated as backspace. We        case. Inside a class (and only there) it is treated as backspace. We
4270        assume that other escapes have more than one character in them, so        assume that other escapes have more than one character in them, so
4271        speculatively set both class_has_8bitchar and class_single_char bigger        speculatively set both class_has_8bitchar and class_one_char bigger
4272        than one. Unrecognized escapes fall through and are either treated        than one. Unrecognized escapes fall through and are either treated
4273        as literal characters (by default), or are faulted if        as literal characters (by default), or are faulted if
4274        PCRE_EXTRA is set. */        PCRE_EXTRA is set. */
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 4000  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. */
4303            class_has_8bitchar++;            class_has_8bitchar++;
4304            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4305            class_single_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 4020  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 4044  for (;; ptr++) Line 4338  for (;; ptr++)
4338    
4339              /* Perl 5.004 onwards omits VT from \s, but we must preserve it              /* Perl 5.004 onwards omits VT from \s, but we must preserve it
4340              if it was previously set by something earlier in the character              if it was previously set by something earlier in the character
4341              class. */              class. Luckily, the value of CHAR_VT is 0x0b in both ASCII and
4342                EBCDIC, so we lazily just adjust the appropriate bit. */
4343    
4344              case ESC_s:              case ESC_s:
4345              classbits[0] |= cbits[cbit_space];              classbits[0] |= cbits[cbit_space];
# Line 4058  for (;; ptr++) Line 4353  for (;; ptr++)
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              case ESC_h:              /* The rest apply in both UCP and non-UCP cases. */
4357              SETBIT(classbits, 0x09); /* VT */  
4358              SETBIT(classbits, 0x20); /* SPACE */              case ESC_h:
4359              SETBIT(classbits, 0xa0); /* NSBP */              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4360  #ifndef COMPILE_PCRE8                PRIV(hspace_list), NOTACHAR);
             xclass = TRUE;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x1680;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x180e;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2000;  
             *class_uchardata++ = 0x200a;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x202f;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x205f;  
             *class_uchardata++ = XCL_SINGLE;  
             *class_uchardata++ = 0x3000;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x1680, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x180e, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2000, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x200a, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x202f, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x205f, class_uchardata);  
               *class_uchardata++ = XCL_SINGLE;  
               class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);  
               }  
 #endif  
4361              continue;              continue;
4362    
4363              case ESC_H:              case ESC_H:
4364              for (c = 0; c < 32; c++)              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4365                {                cd, PRIV(hspace_list));
               int x = 0xff;  
               switch (c)  
                 {  
                 case 0x09/8: x ^= 1 << (0x09%8); break;  
                 case 0x20/8: x ^= 1 << (0x20%8); break;  
                 case 0xa0/8: x ^= 1 << (0xa0%8); break;  
                 default: break;  
                 }  
               classbits[c] |= x;  
               }  
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x0100;  
             *class_uchardata++ = 0x167f;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x1681;  
             *class_uchardata++ = 0x180d;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x180f;  
             *class_uchardata++ = 0x1fff;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x200b;  
             *class_uchardata++ = 0x202e;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2030;  
             *class_uchardata++ = 0x205e;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2060;  
             *class_uchardata++ = 0x2fff;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x3001;  
 #ifdef SUPPORT_UTF  
             if (utf)  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
             else  
 #endif  
               *class_uchardata++ = 0xffff;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x167f, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x1681, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x180d, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x180f, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x1fff, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x200b, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x202e, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2030, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x205e, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2060, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x2fff, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x3001, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
               }  
 #endif  
4366              continue;              continue;
4367    
4368              case ESC_v:              case ESC_v:
4369              SETBIT(classbits, 0x0a); /* LF */              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4370              SETBIT(classbits, 0x0b); /* VT */                PRIV(vspace_list), NOTACHAR);
             SETBIT(classbits, 0x0c); /* FF */  
             SETBIT(classbits, 0x0d); /* CR */  
             SETBIT(classbits, 0x85); /* NEL */  
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x2028;  
             *class_uchardata++ = 0x2029;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x2028, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);  
               }  
 #endif  
4371              continue;              continue;
4372    
4373              case ESC_V:              case ESC_V:
4374              for (c = 0; c < 32; c++)              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4375                {                cd, PRIV(vspace_list));
               int x = 0xff;  
               switch (c)  
                 {  
                 case 0x0a/8: x ^= 1 << (0x0a%8);  
                              x ^= 1 << (0x0b%8);  
                              x ^= 1 << (0x0c%8);  
                              x ^= 1 << (0x0d%8);  
                              break;  
                 case 0x85/8: x ^= 1 << (0x85%8); break;  
                 default: break;  
                 }  
               classbits[c] |= x;  
               }  
   
 #ifndef COMPILE_PCRE8  
             xclass = TRUE;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x0100;  
             *class_uchardata++ = 0x2027;  
             *class_uchardata++ = XCL_RANGE;  
             *class_uchardata++ = 0x202a;  
 #ifdef SUPPORT_UTF  
             if (utf)  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
             else  
 #endif  
               *class_uchardata++ = 0xffff;  
 #elif defined SUPPORT_UTF  
             if (utf)  
               {  
               xclass = TRUE;  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x2027, class_uchardata);  
               *class_uchardata++ = XCL_RANGE;  
               class_uchardata += PRIV(ord2utf)(0x202a, class_uchardata);  
               class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);  
               }  
 #endif  
4376              continue;              continue;
4377    
4378  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4239  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                xclass = TRUE;                *class_uchardata++ = ((escape == ESC_p) != negated)?
               *class_uchardata++ = ((-c == 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 4262  for (;; ptr++) Line 4402  for (;; ptr++)
4402                goto FAILED;                goto FAILED;
4403                }                }
4404              class_has_8bitchar--;    /* Undo the speculative increase. */              class_has_8bitchar--;    /* Undo the speculative increase. */
4405              class_single_char -= 2;  /* Undo the speculative increase. */              class_one_char -= 2;     /* Undo the speculative increase. */
4406              c = *ptr;                /* Get the final character and fall through */              c = *ptr;                /* Get the final character and fall through */
4407              break;              break;
4408              }              }
4409            }            }
4410    
4411          /* Fall through if we have a single character (c >= 0). This may be          /* Fall through if the escape just defined a single character (c >= 0).
4412          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 single character may be followed by '-' to form a range. However,        /* A character may be followed by '-' to form a range. However, Perl does
4419        Perl does not permit ']' to be the end of the range. A '-' character        not permit ']' to be the end of the range. A '-' character at the end is
4420        at the end is treated as a literal. Perl ignores orphaned \E sequences        treated as a literal. Perl ignores orphaned \E sequences entirely. The
4421        entirely. The code for handling \Q and \E is messy. */        code for handling \Q and \E is messy. */
4422    
4423        CHECK_RANGE:        CHECK_RANGE:
4424        while (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)        while (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
# Line 4284  for (;; ptr++) Line 4426  for (;; ptr++)
4426          inescq = FALSE;          inescq = FALSE;
4427          ptr += 2;          ptr += 2;
4428          }          }
   
4429        oldptr = ptr;        oldptr = ptr;
4430    
4431        /* Remember \r or \n */        /* Remember if \r or \n were explicitly used */
4432    
4433        if (c == CHAR_CR || c == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;        if (c == CHAR_CR || c == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4434    
# Line 4295  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 4311  for (;; ptr++) Line 4452  for (;; ptr++)
4452            break;            break;
4453            }            }
4454    
4455          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))          /* 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. */
4457    
4458            if (*ptr == CHAR_NULL || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))
4459            {            {
4460            ptr = oldptr;            ptr = oldptr;
4461            goto LONE_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4462            }            }
4463    
4464            /* Otherwise, we have a potential range; pick up the next character */
4465    
4466  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
4467          if (utf)          if (utf)
4468            {                           /* Braces are required because the */            {                           /* Braces are required because the */
# Line 4332  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 LONE_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
4493                }                }
4494              }              }
4495            }            }
4496    
4497          /* Check that the two values are in the correct order. Optimize          /* Check that the two values are in the correct order. Optimize
4498          one-character ranges */          one-character ranges. */
4499    
4500          if (d < c)          if (d < c)
4501            {            {
4502            *errorcodeptr = ERR8;            *errorcodeptr = ERR8;
4503            goto FAILED;            goto FAILED;
4504            }            }
4505            if (d == c) goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
4506    
4507            /* We have found a character range, so single character optimizations
4508            cannot be done anymore. Any value greater than 1 indicates that there
4509            is more than one character. */
4510    
4511          if (d == c) goto LONE_SINGLE_CHARACTER;  /* A few lines below */          class_one_char = 2;
4512    
4513          /* Remember \r or \n */          /* 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          /* Since we found a character range, single character optimizations          class_has_8bitchar +=
4518          cannot be done anymore. */            add_to_class(classbits, &class_uchardata, options, cd, c, d);
         class_single_char = 2;  
   
         /* In UTF-8 mode, if the upper limit is > 255, or > 127 for caseless  
         matching, we have to use an XCLASS with extra data items. Caseless  
         matching for characters > 127 is available only if UCP support is  
         available. */  
   
 #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)  
         if ((d > 255) || (utf && ((options & PCRE_CASELESS) != 0 && d > 127)))  
 #elif defined  SUPPORT_UTF  
         if (utf && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))  
 #elif !(defined COMPILE_PCRE8)  
         if (d > 255)  
 #endif  
 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)  
           {  
           xclass = TRUE;  
   
           /* With UCP support, we can find the other case equivalents of  
           the relevant characters. There may be several ranges. Optimize how  
           they fit with the basic range. */  
4519    
4520  #ifdef SUPPORT_UCP          continue;   /* Go get the next char in the class */
4521  #ifndef COMPILE_PCRE8          }
           if (utf && (options & PCRE_CASELESS) != 0)  
 #else  
           if ((options & PCRE_CASELESS) != 0)  
 #endif  
             {  
             unsigned int occ, ocd;  
             unsigned int cc = c;  
             unsigned int origd = d;  
             while (get_othercase_range(&cc, origd, &occ, &ocd))  
               {  
               if (occ >= (unsigned int)c &&  
                   ocd <= (unsigned int)d)  
                 continue;                          /* Skip embedded ranges */  
   
               if (occ < (unsigned int)c  &&  
                   ocd >= (unsigned int)c - 1)      /* Extend the basic range */  
                 {                                  /* if there is overlap,   */  
                 c = occ;                           /* noting that if occ < c */  
                 continue;                          /* we can't have ocd > d  */  
                 }                                  /* because a subrange is  */  
               if (ocd > (unsigned int)d &&  
                   occ <= (unsigned int)d + 1)      /* always shorter than    */  
                 {                                  /* the basic range.       */  
                 d = ocd;  
                 continue;  
                 }  
4522    
4523                if (occ == ocd)        /* 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
4525                  *class_uchardata++ = XCL_SINGLE;        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
4527                else        with a zillion characters in it. */
4528                  {  
4529                  *class_uchardata++ = XCL_RANGE;        CLASS_SINGLE_CHARACTER:
4530                  class_uchardata += PRIV(ord2utf)(occ, class_uchardata);        if (class_one_char < 2) class_one_char++;
4531                  }  
4532                class_uchardata += PRIV(ord2utf)(ocd, class_uchardata);        /* If class_one_char is 1, we have the first single character in the
4533                }        class, and there have been no prior ranges, or XCLASS items generated by
4534              }        escapes. If this is the final character in the class, we can optimize by
4535  #endif  /* SUPPORT_UCP */        turning the item into a 1-character OP_CHAR[I] if it's positive, or
4536          OP_NOT[I] if it's negative. In the positive case, it can cause firstchar
4537          to be set. Otherwise, there can be no first char if this item is first,
4538          whatever repeat count may follow. In the case of reqchar, save the
4539          previous value for reinstating. */
4540    
4541            /* Now record the original range, possibly modified for UCP caseless        if (class_one_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
4542            overlapping ranges. */          {
4543            ptr++;
4544            zeroreqchar = reqchar;
4545            zeroreqcharflags = reqcharflags;
4546    
4547            *class_uchardata++ = XCL_RANGE;          if (negate_class)
4548  #ifdef SUPPORT_UTF            {
4549  #ifndef COMPILE_PCRE8  #ifdef SUPPORT_UCP
4550            if (utf)            int d;
             {  
             class_uchardata += PRIV(ord2utf)(c, class_uchardata);  
             class_uchardata += PRIV(ord2utf)(d, class_uchardata);  
             }  
           else  
             {  
             *class_uchardata++ = c;  
             *class_uchardata++ = d;  
             }  
 #else  
           class_uchardata += PRIV(ord2utf)(c, class_uchardata);  
           class_uchardata += PRIV(ord2utf)(d, class_uchardata);  
4551  #endif  #endif
4552  #else /* SUPPORT_UTF */            if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4553            *class_uchardata++ = c;            zerofirstchar = firstchar;
4554            *class_uchardata++ = d;            zerofirstcharflags = firstcharflags;
 #endif /* SUPPORT_UTF */  
4555    
4556            /* With UCP support, we are done. Without UCP support, there is no            /* For caseless UTF-8 mode when UCP support is available, check
4557            caseless matching for UTF characters > 127; we can use the bit map            whether this character has more than one other case. If so, generate
4558            for the smaller ones. As for 16 bit characters without UTF, we            a special OP_NOTPROP item instead of OP_NOTI. */
           can still use  */  
4559    
4560  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4561  #ifndef COMPILE_PCRE8            if (utf && (options & PCRE_CASELESS) != 0 &&
4562            if (utf)                (d = UCD_CASESET(c)) != 0)
 #endif  
             continue;    /* With next character in the class */  
 #endif  /* SUPPORT_UCP */  
   
 #if defined SUPPORT_UTF && !defined(SUPPORT_UCP) && !(defined COMPILE_PCRE8)  
           if (utf)  
4563              {              {
4564              if ((options & PCRE_CASELESS) == 0 || c > 127) continue;              *code++ = OP_NOTPROP;
4565              /* Adjust upper limit and fall through to set up the map */              *code++ = PT_CLIST;
4566              d = 127;              *code++ = d;
4567              }              }
4568            else            else
4569              {  #endif
4570              if (c > 255) continue;            /* Char has only one other case, or UCP not available */
             /* Adjust upper limit and fall through to set up the map */  
             d = 255;  
             }  
 #elif defined SUPPORT_UTF && !defined(SUPPORT_UCP)  
           if ((options & PCRE_CASELESS) == 0 || c > 127) continue;  
           /* Adjust upper limit and fall through to set up the map */  
           d = 127;  
 #else  
           if (c > 255) continue;  
           /* Adjust upper limit and fall through to set up the map */  
           d = 255;  
 #endif  /* SUPPORT_UTF && !SUPPORT_UCP && !COMPILE_PCRE8 */  
           }  
 #endif  /* SUPPORT_UTF || !COMPILE_PCRE8 */  
   
         /* We use the bit map for 8 bit mode, or when the characters fall  
         partially or entirely to [0-255] ([0-127] for UCP) ranges. */  
   
         class_has_8bitchar = 1;  
   
         /* We can save a bit of time by skipping this in the pre-compile. */  
4571    
         if (lengthptr == NULL) for (; c <= d; c++)  
           {  
           classbits[c/8] |= (1 << (c&7));  
           if ((options & PCRE_CASELESS) != 0)  
4572              {              {
4573              int uc = cd->fcc[c]; /* flip case */              *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4574              classbits[uc/8] |= (1 << (uc&7));  #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              }              }
           }  
   
         continue;   /* Go get the next char in the class */  
         }  
4581    
4582        /* Handle a lone single character - we can get here for a normal            /* We are finished with this character class */
       non-escape char, or after \ that introduces a single character or for an  
       apparent range that isn't. */  
   
       LONE_SINGLE_CHARACTER:  
   
       /* Only the value of 1 matters for class_single_char. */  
   
       if (class_single_char < 2) class_single_char++;  
   
       /* If class_charcount is 1, we saw precisely one character. As long as  
       there was no use of \p or \P, in other words, no use of any XCLASS  
       features, we can optimize.  
   
       The optimization throws away the bit map. We turn the item into a  
       1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.  
       In the positive case, it can cause firstchar to be set. Otherwise, there  
       can be no first char if this item is first, whatever repeat count may  
       follow. In the case of reqchar, save the previous value for reinstating. */  
4583    
4584        if (class_single_char == 1 && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)            goto END_CLASS;
         {  
         ptr++;  
         zeroreqchar = reqchar;  
   
         if (negate_class)  
           {  
           if (firstchar == REQ_UNSET) firstchar = REQ_NONE;  
           zerofirstchar = firstchar;  
           *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;  
 #ifdef SUPPORT_UTF  
           if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)  
             code += PRIV(ord2utf)(c, code);  
           else  
 #endif  
             *code++ = c;  
           goto NOT_CHAR;  
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 4565  for (;; ptr++) Line 4599  for (;; ptr++)
4599          goto ONE_CHAR;          goto ONE_CHAR;
4600          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4601    
4602        /* Handle a character that cannot go in the bit map. */        /* There is more than one character in the class, or an XCLASS item
4603          has been generated. Add this character to the class. */
 #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)  
       if ((c > 255) || (utf && ((options & PCRE_CASELESS) != 0 && c > 127)))  
 #elif defined SUPPORT_UTF  
       if (utf && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))  
 #elif !(defined COMPILE_PCRE8)  
       if (c > 255)  
 #endif  
   
 #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)  
         {  
         xclass = TRUE;  
         *class_uchardata++ = XCL_SINGLE;  
 #ifdef SUPPORT_UTF  
 #ifndef COMPILE_PCRE8  
         /* In non 8 bit mode, we can get here even if we are not in UTF mode. */  
         if (!utf)  
           *class_uchardata++ = c;  
         else  
 #endif  
           class_uchardata += PRIV(ord2utf)(c, class_uchardata);  
 #else /* SUPPORT_UTF */  
         *class_uchardata++ = c;  
 #endif /* SUPPORT_UTF */  
   
 #ifdef SUPPORT_UCP  
 #ifdef COMPILE_PCRE8  
         if ((options & PCRE_CASELESS) != 0)  
 #else  
         /* In non 8 bit mode, we can get here even if we are not in UTF mode. */  
         if (utf && (options & PCRE_CASELESS) != 0)  
 #endif  
           {  
           unsigned int othercase;  
           if ((int)(othercase = UCD_OTHERCASE(c)) != c)  
             {  
             *class_uchardata++ = XCL_SINGLE;  
             class_uchardata += PRIV(ord2utf)(othercase, class_uchardata);  
             }  
           }  
 #endif  /* SUPPORT_UCP */  
   
         }  
       else  
 #endif  /* SUPPORT_UTF || COMPILE_PCRE16 */  
4604    
4605        /* Handle a single-byte character */        class_has_8bitchar +=
4606          {          add_to_class(classbits, &class_uchardata, options, cd, c, c);
         class_has_8bitchar = 1;  
         classbits[c/8] |= (1 << (c&7));  
         if ((options & PCRE_CASELESS) != 0)  
           {  
           c = cd->fcc[c]; /* flip case */  
           classbits[c/8] |= (1 << (c&7));  
           }  
         }  
4607        }        }
4608    
4609      /* Loop until ']' reached. This "while" is the end of the "do" far above.      /* Loop until ']' reached. This "while" is the end of the "do" far above.
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
4627        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
4629        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
4631        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. */
4633    
4634    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4635        if (class_uchardata > class_uchardata_base) xclass = TRUE;
4636    #endif
4637    
4638      /* If this is the first thing in the branch, there can be no first char      /* If this is the first thing in the branch, there can be no first char
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 4703  for (;; ptr++) Line 4699  for (;; ptr++)
4699        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4700        }        }
4701      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4702      NOT_CHAR:  
4703        END_CLASS:
4704      break;      break;
4705    
4706    
# Line 4741  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 4813  for (;; ptr++) Line 4812  for (;; ptr++)
4812      if (*previous == OP_CHAR || *previous == OP_CHARI      if (*previous == OP_CHAR || *previous == OP_CHARI
4813          || *previous == OP_NOT || *previous == OP_NOTI)          || *previous == OP_NOT || *previous == OP_NOTI)
4814        {        {
4815        switch (*previous)        switch (*previous)
4816          {          {
4817          default: /* Make compiler happy. */          default: /* Make compiler happy. */
4818          case OP_CHAR:  op_type = OP_STAR - OP_STAR; break;          case OP_CHAR:  op_type = OP_STAR - OP_STAR; break;
# Line 4827  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 4844  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 4901  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 4963  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 4988  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 5018  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 5057  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 5226  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 5593  for (;; ptr++) Line 5579  for (;; ptr++)
5579        ptr++;        ptr++;
5580        while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;        while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_letter) != 0) ptr++;
5581        namelen = (int)(ptr - name);        namelen = (int)(ptr - name);
5582    
5583        /* It appears that Perl allows any characters whatsoever, other than        /* It appears that Perl allows any characters whatsoever, other than
5584        a closing parenthesis, to appear in arguments, so we no longer insist on        a closing parenthesis, to appear in arguments, so we no longer insist on
5585        letters, digits, and underscores. */        letters, digits, and underscores. */
# Line 5601  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;
5596            }            }
5597          }          }
5598    
5599        if (*ptr != CHAR_RIGHT_PARENTHESIS)        if (*ptr != CHAR_RIGHT_PARENTHESIS)
# Line 5623  for (;; ptr++) Line 5609  for (;; ptr++)
5609          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
5610              STRNCMP_UC_C8(name, vn, namelen) == 0)              STRNCMP_UC_C8(name, vn, namelen) == 0)
5611            {            {
5612              int setverb;
5613    
5614            /* Check for open captures before ACCEPT and convert it to            /* Check for open captures before ACCEPT and convert it to
5615            ASSERT_ACCEPT if in an assertion. */            ASSERT_ACCEPT if in an assertion. */
5616    
# Line 5640  for (;; ptr++) Line 5628  for (;; ptr++)
5628                *code++ = OP_CLOSE;                *code++ = OP_CLOSE;
5629                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5630                }                }
5631              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              setverb = *code++ =
5632                  (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 5655  for (;; ptr++) Line 5644  for (;; ptr++)
5644                *errorcodeptr = ERR66;                *errorcodeptr = ERR66;
5645                goto FAILED;                goto FAILED;
5646                }                }
5647              *code = verbs[i].op;              setverb = *code++ = verbs[i].op;
             if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;  
5648              }              }
5649    
5650            else            else
# Line 5666  for (;; ptr++) Line 5654  for (;; ptr++)
5654                *errorcodeptr = ERR59;                *errorcodeptr = ERR59;
5655                goto FAILED;                goto FAILED;
5656                }                }
5657              *code = verbs[i].op_arg;              setverb = *code++ = verbs[i].op_arg;
             if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;  
5658              *code++ = arglen;              *code++ = arglen;
5659              memcpy(code, arg, IN_UCHARS(arglen));              memcpy(code, arg, IN_UCHARS(arglen));
5660              code += arglen;              code += arglen;
5661              *code++ = 0;              *code++ = 0;
5662              }              }
5663    
5664              switch (setverb)
5665                {
5666                case OP_THEN:
5667                case OP_THEN_ARG:
5668                cd->external_flags |= PCRE_HASTHEN;
5669                break;
5670    
5671                case OP_PRUNE:
5672                case OP_PRUNE_ARG:
5673                case OP_SKIP:
5674                case OP_SKIP_ARG:
5675                cd->had_pruneorskip = TRUE;
5676                break;
5677                }
5678    
5679            break;  /* Found verb, exit loop */            break;  /* Found verb, exit loop */
5680            }            }
5681    
# Line 5699  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 5723  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 5735  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 5776  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 5796  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 5866  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 6041  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 6183  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 6289  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 6393  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 6527  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 6588  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 6637  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 6648  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 6680  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 6688  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 6708  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 6748  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 6772  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 6784  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 6803  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 6833  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 6849  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 6859  for (;; ptr++) Line 6896  for (;; ptr++)
6896        /* For the rest (including \X when Unicode properties are supported), we        /* For the rest (including \X when Unicode properties are supported), we
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 = 1;               cd->max_lookbehind == 0)
6906              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 6878  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 6889  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 6922  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 6935  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 6946  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 6957  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 6978  return FALSE; Line 7051  return FALSE;
7051    
7052    
7053    
   
7054  /*************************************************  /*************************************************
7055  *     Compile sequence of alternatives           *  *     Compile sequence of alternatives           *
7056  *************************************************/  *************************************************/
# Line 6999  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 7012  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 7022  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 7092  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 7114  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 7128  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 7173  for (;;) Line 7267  for (;;)
7267          *ptrptr = ptr;          *ptrptr = ptr;
7268          return FALSE;          return FALSE;
7269          }          }
7270        else        else
7271          {          {
7272          if (fixed_length > cd->max_lookbehind)          if (fixed_length > cd->max_lookbehind)
7273            cd->max_lookbehind = fixed_length;            cd->max_lookbehind = fixed_length;
7274          PUT(reverse_count, 0, fixed_length);          PUT(reverse_count, 0, fixed_length);
7275          }          }
7276        }        }
7277      }      }
# Line 7240  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 7310  and the highest back reference was great Line 7406  and the highest back reference was great
7406  However, by keeping a bitmap of the first 31 back references, we can catch some  However, by keeping a bitmap of the first 31 back references, we can catch some
7407  of the more common cases more precisely.  of the more common cases more precisely.
7408    
7409    ... A second exception is when the .* appears inside an atomic group, because
7410    this prevents the number of characters it matches from being adjusted.
7411    
7412  Arguments:  Arguments:
7413    code           points to start of expression (the bracket)    code           points to start of expression (the bracket)
7414    bracket_map    a bitmap of which brackets we are inside while testing; this    bracket_map    a bitmap of which brackets we are inside while testing; this
7415                    handles up to substring 31; after that we just have to take                    handles up to substring 31; after that we just have to take
7416                    the less precise approach                    the less precise approach
7417    backref_map    the back reference bitmap    cd             points to the compile data block
7418      atomcount      atomic group level
7419    
7420  Returns:     TRUE or FALSE  Returns:     TRUE or FALSE
7421  */  */
7422    
7423  static BOOL  static BOOL
7424  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,
7425    unsigned int backref_map)    compile_data *cd, int atomcount)
7426  {  {
7427  do {  do {
7428     const pcre_uchar *scode = first_significant_code(     const pcre_uchar *scode = first_significant_code(
# Line 7334  do { Line 7434  do {
7434     if (op == OP_BRA  || op == OP_BRAPOS ||     if (op == OP_BRA  || op == OP_BRAPOS ||
7435         op == OP_SBRA || op == OP_SBRAPOS)         op == OP_SBRA || op == OP_SBRAPOS)
7436       {       {
7437       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
7438       }       }
7439    
7440     /* Capturing brackets */     /* Capturing brackets */
# Line 7344  do { Line 7444  do {
7444       {       {
7445       int n = GET2(scode, 1+LINK_SIZE);       int n = GET2(scode, 1+LINK_SIZE);
7446       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
7447       if (!is_anchored(scode, new_map, backref_map)) return FALSE;       if (!is_anchored(scode, new_map, cd, atomcount)) return FALSE;
7448         }
7449    
7450       /* Positive forward assertions and conditions */
7451    
7452       else if (op == OP_ASSERT || op == OP_COND)
7453         {
7454         if (!is_anchored(scode, bracket_map, cd, atomcount)) return FALSE;
7455       }       }
7456    
7457     /* Other brackets */     /* Atomic groups */
7458    
7459     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC ||     else if (op == OP_ONCE || op == OP_ONCE_NC)
             op == OP_COND)  
7460       {       {
7461       if (!is_anchored(scode, bracket_map, backref_map)) return FALSE;       if (!is_anchored(scode, bracket_map, cd, atomcount + 1))
7462           return FALSE;
7463       }       }
7464    
7465     /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and     /* .* is not anchored unless DOTALL is set (which generates OP_ALLANY) and
7466     it isn't in brackets that are or may be referenced. */     it isn't in brackets that are or may be referenced or inside an atomic
7467       group. */
7468    
7469     else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||     else if ((op == OP_TYPESTAR || op == OP_TYPEMINSTAR ||
7470               op == OP_TYPEPOSSTAR))               op == OP_TYPEPOSSTAR))
7471       {       {
7472       if (scode[1] != OP_ALLANY || (bracket_map & backref_map) != 0)       if (scode[1] != OP_ALLANY || (bracket_map & cd->backref_map) != 0 ||
7473             atomcount > 0 || cd->had_pruneorskip)
7474         return FALSE;         return FALSE;
7475       }       }
7476    
7477     /* Check for explicit anchoring */     /* Check for explicit anchoring */
7478    
7479     else if (op != OP_SOD && op != OP_SOM && op != OP_CIRC) return FALSE;     else if (op != OP_SOD && op != OP_SOM && op != OP_CIRC) return FALSE;
7480    
7481     code += GET(code, 1);     code += GET(code, 1);
7482     }     }
7483  while (*code == OP_ALT);   /* Loop for each alternative */  while (*code == OP_ALT);   /* Loop for each alternative */
# Line 7385  return TRUE; Line 7495  return TRUE;
7495  matching and for non-DOTALL patterns that start with .* (which must start at  matching and for non-DOTALL patterns that start with .* (which must start at
7496  the beginning or after \n). As in the case of is_anchored() (see above), we  the beginning or after \n). As in the case of is_anchored() (see above), we
7497  have to take account of back references to capturing brackets that contain .*  have to take account of back references to capturing brackets that contain .*
7498  because in that case we can't make the assumption.  because in that case we can't make the assumption. Also, the appearance of .*
7499    inside atomic brackets or in a pattern that contains *PRUNE or *SKIP does not
7500    count, because once again the assumption no longer holds.
7501    
7502  Arguments:  Arguments:
7503    code           points to start of expression (the bracket)    code           points to start of expression (the bracket)
7504    bracket_map    a bitmap of which brackets we are inside while testing; this    bracket_map    a bitmap of which brackets we are inside while testing; this
7505                    handles up to substring 31; after that we just have to take                    handles up to substring 31; after that we just have to take
7506                    the less precise approach                    the less precise approach
7507    backref_map    the back reference bitmap    cd             points to the compile data
7508      atomcount      atomic group level
7509    
7510  Returns:         TRUE or FALSE  Returns:         TRUE or FALSE
7511  */  */
7512    
7513  static BOOL  static BOOL
7514  is_startline(const pcre_uchar *code, unsigned int bracket_map,  is_startline(const pcre_uchar *code, unsigned int bracket_map,
7515    unsigned int backref_map)    compile_data *cd, int atomcount)
7516  {  {
7517  do {  do {
7518     const pcre_uchar *scode = first_significant_code(     const pcre_uchar *scode = first_significant_code(
# Line 7425  do { Line 7538  do {
7538         return FALSE;         return FALSE;
7539    
7540         default:     /* Assertion */         default:     /* Assertion */
7541         if (!is_startline(scode, bracket_map, backref_map)) return FALSE;         if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7542         do scode += GET(scode, 1); while (*scode == OP_ALT);         do scode += GET(scode, 1); while (*scode == OP_ALT);
7543         scode += 1 + LINK_SIZE;         scode += 1 + LINK_SIZE;
7544         break;         break;
# Line 7439  do { Line 7552  do {
7552     if (op == OP_BRA  || op == OP_BRAPOS ||     if (op == OP_BRA  || op == OP_BRAPOS ||
7553         op == OP_SBRA || op == OP_SBRAPOS)         op == OP_SBRA || op == OP_SBRAPOS)
7554       {       {
7555       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7556       }       }
7557    
7558     /* Capturing brackets */     /* Capturing brackets */
# Line 7449  do { Line 7562  do {
7562       {       {
7563       int n = GET2(scode, 1+LINK_SIZE);       int n = GET2(scode, 1+LINK_SIZE);
7564       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);       int new_map = bracket_map | ((n < 32)? (1 << n) : 1);
7565       if (!is_startline(scode, new_map, backref_map)) return FALSE;       if (!is_startline(scode, new_map, cd, atomcount)) return FALSE;
7566         }
7567    
7568       /* Positive forward assertions */
7569    
7570       else if (op == OP_ASSERT)
7571         {
7572         if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7573       }       }
7574    
7575     /* Other brackets */     /* Atomic brackets */
7576    
7577     else if (op == OP_ASSERT || op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
7578       {       {
7579       if (!is_startline(scode, bracket_map, backref_map)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount + 1)) return FALSE;
7580       }       }
7581    
7582     /* .* means "start at start or after \n" if it isn't in brackets that     /* .* means "start at start or after \n" if it isn't in atomic brackets or
7583     may be referenced. */     brackets that may be referenced, as long as the pattern does not contain
7584       *PRUNE or *SKIP, because these break the feature. Consider, for example,
7585       /.*?a(*PRUNE)b/ with the subject "aab", which matches "ab", i.e. not at the
7586       start of a line. */
7587    
7588     else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)     else if (op == OP_TYPESTAR || op == OP_TYPEMINSTAR || op == OP_TYPEPOSSTAR)
7589       {       {
7590       if (scode[1] != OP_ANY || (bracket_map & backref_map) != 0) return FALSE;       if (scode[1] != OP_ANY || (bracket_map & cd->backref_map) != 0 ||
7591             atomcount > 0 || cd->had_pruneorskip)
7592           return FALSE;
7593       }       }
7594    
7595     /* Check for explicit circumflex */     /* Check for explicit circumflex; anything else gives a FALSE result. Note
7596       in particular that this includes atomic brackets OP_ONCE and OP_ONCE_NC
7597       because the number of characters matched by .* cannot be adjusted inside
7598       them. */
7599    
7600     else if (op != OP_CIRC && op != OP_CIRCM) return FALSE;     else if (op != OP_CIRC && op != OP_CIRCM) return FALSE;
7601    
# Line 7495  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;