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

Diff of /code/trunk/pcre_compile.c

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

revision 1045 by ph10, Sun Sep 23 16:50:00 2012 UTC revision 1360 by ph10, Tue Sep 3 10:25:39 2013 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2012 University of Cambridge             Copyright (c) 1997-2013 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 53  supporting internal functions that are n Line 53  supporting internal functions that are n
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    
56  /* When PCRE_DEBUG is defined, we need the pcre(16)_printint() function, which  /* When PCRE_DEBUG is defined, we need the pcre(16|32)_printint() function, which
57  is also used by pcretest. PCRE_DEBUG is not defined when building a production  is also used by pcretest. PCRE_DEBUG is not defined when building a production
58  library. We do not need to select pcre16_printint.c specially, because the  library. We do not need to select pcre16_printint.c specially, because the
59  COMPILE_PCREx macro will already be appropriately set. */  COMPILE_PCREx macro will already be appropriately set. */
# Line 80  to check them every time. */ Line 80  to check them every time. */
80  /* Definitions to allow mutual recursion */  /* Definitions to allow mutual recursion */
81    
82  static int  static int
83    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,    add_list_to_class(pcre_uint8 *, pcre_uchar **, int, compile_data *,
84      const pcre_uint32 *, unsigned int);      const pcre_uint32 *, unsigned int);
85    
86  static BOOL  static BOOL
87    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
88      int, int, int *, int *, branch_chain *, compile_data *, int *);      pcre_uint32 *, pcre_int32 *, pcre_uint32 *, pcre_int32 *, branch_chain *,
89        compile_data *, int *);
90    
91    
92    
# Line 114  kicks in at the same number of forward r Line 115  kicks in at the same number of forward r
115  #define COMPILE_WORK_SIZE (2048*LINK_SIZE)  #define COMPILE_WORK_SIZE (2048*LINK_SIZE)
116  #define COMPILE_WORK_SIZE_MAX (100*COMPILE_WORK_SIZE)  #define COMPILE_WORK_SIZE_MAX (100*COMPILE_WORK_SIZE)
117    
118    /* This value determines the size of the initial vector that is used for
119    remembering named groups during the pre-compile. It is allocated on the stack,
120    but if it is too small, it is expanded using malloc(), in a similar way to the
121    workspace. The value is the number of slots in the list. */
122    
123    #define NAMED_GROUP_LIST_SIZE  20
124    
125  /* The overrun tests check for a slightly smaller size so that they detect the  /* The overrun tests check for a slightly smaller size so that they detect the
126  overrun before it actually does run off the end of the data block. */  overrun before it actually does run off the end of the data block. */
127    
# Line 121  overrun before it actually does run off Line 129  overrun before it actually does run off
129    
130  /* Private flags added to firstchar and reqchar. */  /* Private flags added to firstchar and reqchar. */
131    
132  #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */  #define REQ_CASELESS    (1 << 0)        /* Indicates caselessness */
133  #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */  #define REQ_VARY        (1 << 1)        /* Reqchar followed non-literal item */
134    /* Negative values for the firstchar and reqchar flags */
135    #define REQ_UNSET       (-2)
136    #define REQ_NONE        (-1)
137    
138  /* Repeated character flags. */  /* Repeated character flags. */
139    
# Line 483  static const char error_texts[] = Line 494  static const char error_texts[] =
494    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
495    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
496    /* 60 */    /* 60 */
497    "(*VERB) not recognized\0"    "(*VERB) not recognized or malformed\0"
498    "number is too big\0"    "number is too big\0"
499    "subpattern name expected\0"    "subpattern name expected\0"
500    "digit expected after (?+\0"    "digit expected after (?+\0"
# Line 503  static const char error_texts[] = Line 514  static const char error_texts[] =
514    /* 75 */    /* 75 */
515    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"    "name is too long in (*MARK), (*PRUNE), (*SKIP), or (*THEN)\0"
516    "character value in \\u.... sequence is too large\0"    "character value in \\u.... sequence is too large\0"
517      "invalid UTF-32 string\0"
518      "setting UTF is disabled by the application\0"
519    ;    ;
520    
521  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 643  static const pcre_uint8 ebcdic_chartab[] Line 656  static const pcre_uint8 ebcdic_chartab[]
656    
657    
658    
   
659  /*************************************************  /*************************************************
660  *            Find an error text                  *  *            Find an error text                  *
661  *************************************************/  *************************************************/
# Line 663  find_error_text(int n) Line 675  find_error_text(int n)
675  const char *s = error_texts;  const char *s = error_texts;
676  for (; n > 0; n--)  for (; n > 0; n--)
677    {    {
678    while (*s++ != 0) {};    while (*s++ != CHAR_NULL) {};
679    if (*s == 0) return "Error text not found (please report)";    if (*s == CHAR_NULL) return "Error text not found (please report)";
680    }    }
681  return s;  return s;
682  }  }
# Line 747  return (*p == CHAR_RIGHT_CURLY_BRACKET); Line 759  return (*p == CHAR_RIGHT_CURLY_BRACKET);
759  *************************************************/  *************************************************/
760    
761  /* 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
762  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
763  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
764  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
765  UTF-8 is enabled, a positive value greater than 255 may be returned. On entry,  be returned in chptr.
766  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
767  sequence.  escape sequence.
768    
769  Arguments:  Arguments:
770    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
771      chptr          points to the data character
772    errorcodeptr   points to the errorcode variable    errorcodeptr   points to the errorcode variable
773    bracount       number of previous extracting brackets    bracount       number of previous extracting brackets
774    options        the options bits    options        the options bits
775    isclass        TRUE if inside a character class    isclass        TRUE if inside a character class
776    
777  Returns:         zero or positive => a data character  Returns:         zero => a data character
778                   negative => a special escape sequence                   positive => a special escape sequence
779                     negative => a back reference
780                   on error, errorcodeptr is set                   on error, errorcodeptr is set
781  */  */
782    
783  static int  static int
784  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, pcre_uint32 *chptr, int *errorcodeptr,
785    int options, BOOL isclass)    int bracount, int options, BOOL isclass)
786  {  {
787  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
788  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
789  const pcre_uchar *ptr = *ptrptr + 1;  const pcre_uchar *ptr = *ptrptr + 1;
790  pcre_int32 c;  pcre_uint32 c;
791    int escape = 0;
792  int i;  int i;
793    
794  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
# Line 781  ptr--;                            /* Set Line 796  ptr--;                            /* Set
796    
797  /* 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. */
798    
799  if (c == 0) *errorcodeptr = ERR1;  if (c == CHAR_NULL) *errorcodeptr = ERR1;
800    
801  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup  /* Non-alphanumerics are literals. For digits or letters, do an initial lookup
802  in a table. A non-zero result is something that can be returned immediately.  in a table. A non-zero result is something that can be returned immediately.
# Line 790  Otherwise further processing may be requ Line 805  Otherwise further processing may be requ
805  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
806  /* Not alphanumeric */  /* Not alphanumeric */
807  else if (c < CHAR_0 || c > CHAR_z) {}  else if (c < CHAR_0 || c > CHAR_z) {}
808  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0)
809      { if (i > 0) c = (pcre_uint32)i; else escape = -i; }
810    
811  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
812  /* Not alphanumeric */  /* Not alphanumeric */
813  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}  else if (c < CHAR_a || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
814  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; }
815  #endif  #endif
816    
817  /* Escapes that need further processing, or are illegal. */  /* Escapes that need further processing, or are illegal. */
# Line 803  else if ((i = escapes[c - 0x48]) != 0) Line 819  else if ((i = escapes[c - 0x48]) != 0)
819  else  else
820    {    {
821    const pcre_uchar *oldptr;    const pcre_uchar *oldptr;
822    BOOL braced, negated;    BOOL braced, negated, overflow;
823      int s;
824    
825    switch (c)    switch (c)
826      {      {
# Line 828  else Line 845  else
845          c = 0;          c = 0;
846          for (i = 0; i < 4; ++i)          for (i = 0; i < 4; ++i)
847            {            {
848            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
849  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
850            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
851            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 838  else Line 855  else
855  #endif  #endif
856            }            }
857    
858  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
859          if (c > (utf ? 0x10ffff : 0xff))          if (c > (utf ? 0x10ffffU : 0xffU))
860  #else  #elif defined COMPILE_PCRE16
861  #ifdef COMPILE_PCRE16          if (c > (utf ? 0x10ffffU : 0xffffU))
862          if (c > (utf ? 0x10ffff : 0xffff))  #elif defined COMPILE_PCRE32
863  #endif          if (utf && c > 0x10ffffU)
864  #endif  #endif
865            {            {
866            *errorcodeptr = ERR76;            *errorcodeptr = ERR76;
# Line 875  else Line 892  else
892      (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
893      number either in angle brackets or in single quotes. However, these are      number either in angle brackets or in single quotes. However, these are
894      (possibly recursive) subroutine calls, _not_ backreferences. Just return      (possibly recursive) subroutine calls, _not_ backreferences. Just return
895      the -ESC_g code (cf \k). */      the ESC_g code (cf \k). */
896    
897      case CHAR_g:      case CHAR_g:
898      if (isclass) break;      if (isclass) break;
899      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)
900        {        {
901        c = -ESC_g;        escape = ESC_g;
902        break;        break;
903        }        }
904    
# Line 890  else Line 907  else
907      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
908        {        {
909        const pcre_uchar *p;        const pcre_uchar *p;
910        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++)
911          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
912        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != CHAR_NULL && *p != CHAR_RIGHT_CURLY_BRACKET)
913          {          {
914          c = -ESC_k;          escape = ESC_k;
915          break;          break;
916          }          }
917        braced = TRUE;        braced = TRUE;
# Line 910  else Line 927  else
927      else negated = FALSE;      else negated = FALSE;
928    
929      /* The integer range is limited by the machine's int representation. */      /* The integer range is limited by the machine's int representation. */
930      c = 0;      s = 0;
931        overflow = FALSE;
932      while (IS_DIGIT(ptr[1]))      while (IS_DIGIT(ptr[1]))
933        {        {
934        if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */        if (s > INT_MAX / 10 - 1) /* Integer overflow */
935          {          {
936          c = -1;          overflow = TRUE;
937          break;          break;
938          }          }
939        c = c * 10 + *(++ptr) - CHAR_0;        s = s * 10 + (int)(*(++ptr) - CHAR_0);
940        }        }
941      if (((unsigned int)c) > INT_MAX) /* Integer overflow */      if (overflow) /* Integer overflow */
942        {        {
943        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
944          ptr++;          ptr++;
# Line 934  else Line 952  else
952        break;        break;
953        }        }
954    
955      if (c == 0)      if (s == 0)
956        {        {
957        *errorcodeptr = ERR58;        *errorcodeptr = ERR58;
958        break;        break;
# Line 942  else Line 960  else
960    
961      if (negated)      if (negated)
962        {        {
963        if (c > bracount)        if (s > bracount)
964          {          {
965          *errorcodeptr = ERR15;          *errorcodeptr = ERR15;
966          break;          break;
967          }          }
968        c = bracount - (c - 1);        s = bracount - (s - 1);
969        }        }
970    
971      c = -(ESC_REF + c);      escape = -s;
972      break;      break;
973    
974      /* The handling of escape sequences consisting of a string of digits      /* The handling of escape sequences consisting of a string of digits
# Line 972  else Line 990  else
990        {        {
991        oldptr = ptr;        oldptr = ptr;
992        /* The integer range is limited by the machine's int representation. */        /* The integer range is limited by the machine's int representation. */
993        c -= CHAR_0;        s = (int)(c -CHAR_0);
994          overflow = FALSE;
995        while (IS_DIGIT(ptr[1]))        while (IS_DIGIT(ptr[1]))
996          {          {
997          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */          if (s > INT_MAX / 10 - 1) /* Integer overflow */
998            {            {
999            c = -1;            overflow = TRUE;
1000            break;            break;
1001            }            }
1002          c = c * 10 + *(++ptr) - CHAR_0;          s = s * 10 + (int)(*(++ptr) - CHAR_0);
1003          }          }
1004        if (((unsigned int)c) > INT_MAX) /* Integer overflow */        if (overflow) /* Integer overflow */
1005          {          {
1006          while (IS_DIGIT(ptr[1]))          while (IS_DIGIT(ptr[1]))
1007            ptr++;            ptr++;
1008          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
1009          break;          break;
1010          }          }
1011        if (c < 10 || c <= bracount)        if (s < 10 || s <= bracount)
1012          {          {
1013          c = -(ESC_REF + c);          escape = -s;
1014          break;          break;
1015          }          }
1016        ptr = oldptr;      /* Put the pointer back and fall through */        ptr = oldptr;      /* Put the pointer back and fall through */
# Line 1038  else Line 1057  else
1057          c = 0;          c = 0;
1058          for (i = 0; i < 2; ++i)          for (i = 0; i < 2; ++i)
1059            {            {
1060            register int cc = *(++ptr);            register pcre_uint32 cc = *(++ptr);
1061  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1062            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */            if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1063            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));            c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1056  else Line 1075  else
1075        const pcre_uchar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
1076    
1077        c = 0;        c = 0;
1078          overflow = FALSE;
1079        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
1080          {          {
1081          register int cc = *pt++;          register pcre_uint32 cc = *pt++;
1082          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
1083    
1084    #ifdef COMPILE_PCRE32
1085            if (c >= 0x10000000l) { overflow = TRUE; break; }
1086    #endif
1087    
1088  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1089          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
1090          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
# Line 1069  else Line 1093  else
1093          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
1094  #endif  #endif
1095    
1096  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
1097          if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }          if (c > (utf ? 0x10ffffU : 0xffU)) { overflow = TRUE; break; }
1098  #else  #elif defined COMPILE_PCRE16
1099  #ifdef COMPILE_PCRE16          if (c > (utf ? 0x10ffffU : 0xffffU)) { overflow = TRUE; break; }
1100          if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }  #elif defined COMPILE_PCRE32
1101  #endif          if (utf && c > 0x10ffffU) { overflow = TRUE; break; }
1102  #endif  #endif
1103          }          }
1104    
1105        if (c < 0)        if (overflow)
1106          {          {
1107          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;          while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1108          *errorcodeptr = ERR34;          *errorcodeptr = ERR34;
# Line 1100  else Line 1124  else
1124      c = 0;      c = 0;
1125      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)
1126        {        {
1127        int cc;                                  /* Some compilers don't like */        pcre_uint32 cc;                          /* Some compilers don't like */
1128        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
1129  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
1130        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */        if (cc >= CHAR_a) cc -= 32;              /* Convert to upper case */
# Line 1119  else Line 1143  else
1143    
1144      case CHAR_c:      case CHAR_c:
1145      c = *(++ptr);      c = *(++ptr);
1146      if (c == 0)      if (c == CHAR_NULL)
1147        {        {
1148        *errorcodeptr = ERR2;        *errorcodeptr = ERR2;
1149        break;        break;
# Line 1159  else Line 1183  else
1183  newline". PCRE does not support \N{name}. However, it does support  newline". PCRE does not support \N{name}. However, it does support
1184  quantification such as \N{2,3}. */  quantification such as \N{2,3}. */
1185    
1186  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&  if (escape == ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&
1187       !is_counted_repeat(ptr+2))       !is_counted_repeat(ptr+2))
1188    *errorcodeptr = ERR37;    *errorcodeptr = ERR37;
1189    
1190  /* If PCRE_UCP is set, we change the values for \d etc. */  /* If PCRE_UCP is set, we change the values for \d etc. */
1191    
1192  if ((options & PCRE_UCP) != 0 && c <= -ESC_D && c >= -ESC_w)  if ((options & PCRE_UCP) != 0 && escape >= ESC_D && escape <= ESC_w)
1193    c -= (ESC_DU - ESC_D);    escape += (ESC_DU - ESC_D);
1194    
1195  /* Set the pointer to the final character before returning. */  /* Set the pointer to the final character before returning. */
1196    
1197  *ptrptr = ptr;  *ptrptr = ptr;
1198  return c;  *chptr = c;
1199    return escape;
1200  }  }
1201    
   
   
1202  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1203  /*************************************************  /*************************************************
1204  *               Handle \P and \p                 *  *               Handle \P and \p                 *
# Line 1189  escape sequence. Line 1212  escape sequence.
1212  Argument:  Argument:
1213    ptrptr         points to the pattern position pointer    ptrptr         points to the pattern position pointer
1214    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
1215    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
1216      pdataptr       points to an unsigned int that is set to the detailed property value
1217    errorcodeptr   points to the error code variable    errorcodeptr   points to the error code variable
1218    
1219  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
1220  */  */
1221    
1222  static int  static BOOL
1223  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, unsigned int *ptypeptr,
1224      unsigned int *pdataptr, int *errorcodeptr)
1225  {  {
1226  int c, i, bot, top;  pcre_uchar c;
1227    int i, bot, top;
1228  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
1229  pcre_uchar name[32];  pcre_uchar name[32];
1230    
1231  c = *(++ptr);  c = *(++ptr);
1232  if (c == 0) goto ERROR_RETURN;  if (c == CHAR_NULL) goto ERROR_RETURN;
1233    
1234  *negptr = FALSE;  *negptr = FALSE;
1235    
# Line 1220  if (c == CHAR_LEFT_CURLY_BRACKET) Line 1246  if (c == CHAR_LEFT_CURLY_BRACKET)
1246    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)    for (i = 0; i < (int)(sizeof(name) / sizeof(pcre_uchar)) - 1; i++)
1247      {      {
1248      c = *(++ptr);      c = *(++ptr);
1249      if (c == 0) goto ERROR_RETURN;      if (c == CHAR_NULL) goto ERROR_RETURN;
1250      if (c == CHAR_RIGHT_CURLY_BRACKET) break;      if (c == CHAR_RIGHT_CURLY_BRACKET) break;
1251      name[i] = c;      name[i] = c;
1252      }      }
# Line 1245  top = PRIV(utt_size); Line 1271  top = PRIV(utt_size);
1271    
1272  while (bot < top)  while (bot < top)
1273    {    {
1274      int r;
1275    i = (bot + top) >> 1;    i = (bot + top) >> 1;
1276    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);
1277    if (c == 0)    if (r == 0)
1278      {      {
1279      *dptr = PRIV(utt)[i].value;      *ptypeptr = PRIV(utt)[i].type;
1280      return PRIV(utt)[i].type;      *pdataptr = PRIV(utt)[i].value;
1281        return TRUE;
1282      }      }
1283    if (c > 0) bot = i + 1; else top = i;    if (r > 0) bot = i + 1; else top = i;
1284    }    }
1285    
1286  *errorcodeptr = ERR47;  *errorcodeptr = ERR47;
1287  *ptrptr = ptr;  *ptrptr = ptr;
1288  return -1;  return FALSE;
1289    
1290  ERROR_RETURN:  ERROR_RETURN:
1291  *errorcodeptr = ERR46;  *errorcodeptr = ERR46;
1292  *ptrptr = ptr;  *ptrptr = ptr;
1293  return -1;  return FALSE;
1294  }  }
1295  #endif  #endif
1296    
# Line 1297  int max = -1; Line 1325  int max = -1;
1325  /* 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
1326  an integer overflow. */  an integer overflow. */
1327    
1328  while (IS_DIGIT(*p)) min = min * 10 + *p++ - CHAR_0;  while (IS_DIGIT(*p)) min = min * 10 + (int)(*p++ - CHAR_0);
1329  if (min < 0 || min > 65535)  if (min < 0 || min > 65535)
1330    {    {
1331    *errorcodeptr = ERR5;    *errorcodeptr = ERR5;
# Line 1312  if (*p == CHAR_RIGHT_CURLY_BRACKET) max Line 1340  if (*p == CHAR_RIGHT_CURLY_BRACKET) max
1340    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)
1341      {      {
1342      max = 0;      max = 0;
1343      while(IS_DIGIT(*p)) max = max * 10 + *p++ - CHAR_0;      while(IS_DIGIT(*p)) max = max * 10 + (int)(*p++ - CHAR_0);
1344      if (max < 0 || max > 65535)      if (max < 0 || max > 65535)
1345        {        {
1346        *errorcodeptr = ERR5;        *errorcodeptr = ERR5;
# Line 1337  return p; Line 1365  return p;
1365    
1366    
1367  /*************************************************  /*************************************************
 *  Subroutine for finding forward reference      *  
 *************************************************/  
   
 /* This recursive function is called only from find_parens() below. The  
 top-level call starts at the beginning of the pattern. All other calls must  
 start at a parenthesis. It scans along a pattern's text looking for capturing  
 subpatterns, and counting them. If it finds a named pattern that matches the  
 name it is given, it returns its number. Alternatively, if the name is NULL, it  
 returns when it reaches a given numbered subpattern. Recursion is used to keep  
 track of subpatterns that reset the capturing group numbers - the (?| feature.  
   
 This function was originally called only from the second pass, in which we know  
 that if (?< or (?' or (?P< is encountered, the name will be correctly  
 terminated because that is checked in the first pass. There is now one call to  
 this function in the first pass, to check for a recursive back reference by  
 name (so that we can make the whole group atomic). In this case, we need check  
 only up to the current position in the pattern, and that is still OK because  
 and previous occurrences will have been checked. To make this work, the test  
 for "end of pattern" is a check against cd->end_pattern in the main loop,  
 instead of looking for a binary zero. This means that the special first-pass  
 call can adjust cd->end_pattern temporarily. (Checks for binary zero while  
 processing items within the loop are OK, because afterwards the main loop will  
 terminate.)  
   
 Arguments:  
   ptrptr       address of the current character pointer (updated)  
   cd           compile background data  
   name         name to seek, or NULL if seeking a numbered subpattern  
   lorn         name length, or subpattern number if name is NULL  
   xmode        TRUE if we are in /x mode  
   utf          TRUE if we are in UTF-8 / UTF-16 mode  
   count        pointer to the current capturing subpattern number (updated)  
   
 Returns:       the number of the named subpattern, or -1 if not found  
 */  
   
 static int  
 find_parens_sub(pcre_uchar **ptrptr, compile_data *cd, const pcre_uchar *name, int lorn,  
   BOOL xmode, BOOL utf, int *count)  
 {  
 pcre_uchar *ptr = *ptrptr;  
 int start_count = *count;  
 int hwm_count = start_count;  
 BOOL dup_parens = FALSE;  
   
 /* If the first character is a parenthesis, check on the type of group we are  
 dealing with. The very first call may not start with a parenthesis. */  
   
 if (ptr[0] == CHAR_LEFT_PARENTHESIS)  
   {  
   /* Handle specials such as (*SKIP) or (*UTF8) etc. */  
   
   if (ptr[1] == CHAR_ASTERISK) ptr += 2;  
   
   /* Handle a normal, unnamed capturing parenthesis. */  
   
   else if (ptr[1] != CHAR_QUESTION_MARK)  
     {  
     *count += 1;  
     if (name == NULL && *count == lorn) return *count;  
     ptr++;  
     }  
   
   /* All cases now have (? at the start. Remember when we are in a group  
   where the parenthesis numbers are duplicated. */  
   
   else if (ptr[2] == CHAR_VERTICAL_LINE)  
     {  
     ptr += 3;  
     dup_parens = TRUE;  
     }  
   
   /* Handle comments; all characters are allowed until a ket is reached. */  
   
   else if (ptr[2] == CHAR_NUMBER_SIGN)  
     {  
     for (ptr += 3; *ptr != 0; ptr++) if (*ptr == CHAR_RIGHT_PARENTHESIS) break;  
     goto FAIL_EXIT;  
     }  
   
   /* Handle a condition. If it is an assertion, just carry on so that it  
   is processed as normal. If not, skip to the closing parenthesis of the  
   condition (there can't be any nested parens). */  
   
   else if (ptr[2] == CHAR_LEFT_PARENTHESIS)  
     {  
     ptr += 2;  
     if (ptr[1] != CHAR_QUESTION_MARK)  
       {  
       while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;  
       if (*ptr != 0) ptr++;  
       }  
     }  
   
   /* Start with (? but not a condition. */  
   
   else  
     {  
     ptr += 2;  
     if (*ptr == CHAR_P) ptr++;                      /* Allow optional P */  
   
     /* We have to disambiguate (?<! and (?<= from (?<name> for named groups */  
   
     if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&  
         ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)  
       {  
       int term;  
       const pcre_uchar *thisname;  
       *count += 1;  
       if (name == NULL && *count == lorn) return *count;  
       term = *ptr++;  
       if (term == CHAR_LESS_THAN_SIGN) term = CHAR_GREATER_THAN_SIGN;  
       thisname = ptr;  
       while (*ptr != term) ptr++;  
       if (name != NULL && lorn == ptr - thisname &&  
           STRNCMP_UC_UC(name, thisname, lorn) == 0)  
         return *count;  
       term++;  
       }  
     }  
   }  
   
 /* Past any initial parenthesis handling, scan for parentheses or vertical  
 bars. Stop if we get to cd->end_pattern. Note that this is important for the  
 first-pass call when this value is temporarily adjusted to stop at the current  
 position. So DO NOT change this to a test for binary zero. */  
   
 for (; ptr < cd->end_pattern; ptr++)  
   {  
   /* Skip over backslashed characters and also entire \Q...\E */  
   
   if (*ptr == CHAR_BACKSLASH)  
     {  
     if (*(++ptr) == 0) goto FAIL_EXIT;  
     if (*ptr == CHAR_Q) for (;;)  
       {  
       while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};  
       if (*ptr == 0) goto FAIL_EXIT;  
       if (*(++ptr) == CHAR_E) break;  
       }  
     continue;  
     }  
   
   /* Skip over character classes; this logic must be similar to the way they  
   are handled for real. If the first character is '^', skip it. Also, if the  
   first few characters (either before or after ^) are \Q\E or \E we skip them  
   too. This makes for compatibility with Perl. Note the use of STR macros to  
   encode "Q\\E" so that it works in UTF-8 on EBCDIC platforms. */  
   
   if (*ptr == CHAR_LEFT_SQUARE_BRACKET)  
     {  
     BOOL negate_class = FALSE;  
     for (;;)  
       {  
       if (ptr[1] == CHAR_BACKSLASH)  
         {  
         if (ptr[2] == CHAR_E)  
           ptr+= 2;  
         else if (STRNCMP_UC_C8(ptr + 2,  
                  STR_Q STR_BACKSLASH STR_E, 3) == 0)  
           ptr += 4;  
         else  
           break;  
         }  
       else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT)  
         {  
         negate_class = TRUE;  
         ptr++;  
         }  
       else break;  
       }  
   
     /* If the next character is ']', it is a data character that must be  
     skipped, except in JavaScript compatibility mode. */  
   
     if (ptr[1] == CHAR_RIGHT_SQUARE_BRACKET &&  
         (cd->external_options & PCRE_JAVASCRIPT_COMPAT) == 0)  
       ptr++;  
   
     while (*(++ptr) != CHAR_RIGHT_SQUARE_BRACKET)  
       {  
       if (*ptr == 0) return -1;  
       if (*ptr == CHAR_BACKSLASH)  
         {  
         if (*(++ptr) == 0) goto FAIL_EXIT;  
         if (*ptr == CHAR_Q) for (;;)  
           {  
           while (*(++ptr) != 0 && *ptr != CHAR_BACKSLASH) {};  
           if (*ptr == 0) goto FAIL_EXIT;  
           if (*(++ptr) == CHAR_E) break;  
           }  
         continue;  
         }  
       }  
     continue;  
     }  
   
   /* Skip comments in /x mode */  
   
   if (xmode && *ptr == CHAR_NUMBER_SIGN)  
     {  
     ptr++;  
     while (*ptr != 0)  
       {  
       if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }  
       ptr++;  
 #ifdef SUPPORT_UTF  
       if (utf) FORWARDCHAR(ptr);  
 #endif  
       }  
     if (*ptr == 0) goto FAIL_EXIT;  
     continue;  
     }  
   
   /* Check for the special metacharacters */  
   
   if (*ptr == CHAR_LEFT_PARENTHESIS)  
     {  
     int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);  
     if (rc > 0) return rc;  
     if (*ptr == 0) goto FAIL_EXIT;  
     }  
   
   else if (*ptr == CHAR_RIGHT_PARENTHESIS)  
     {  
     if (dup_parens && *count < hwm_count) *count = hwm_count;  
     goto FAIL_EXIT;  
     }  
   
   else if (*ptr == CHAR_VERTICAL_LINE && dup_parens)  
     {  
     if (*count > hwm_count) hwm_count = *count;  
     *count = start_count;  
     }  
   }  
   
 FAIL_EXIT:  
 *ptrptr = ptr;  
 return -1;  
 }  
   
   
   
   
 /*************************************************  
 *       Find forward referenced subpattern       *  
 *************************************************/  
   
 /* This function scans along a pattern's text looking for capturing  
 subpatterns, and counting them. If it finds a named pattern that matches the  
 name it is given, it returns its number. Alternatively, if the name is NULL, it  
 returns when it reaches a given numbered subpattern. This is used for forward  
 references to subpatterns. We used to be able to start this scan from the  
 current compiling point, using the current count value from cd->bracount, and  
 do it all in a single loop, but the addition of the possibility of duplicate  
 subpattern numbers means that we have to scan from the very start, in order to  
 take account of such duplicates, and to use a recursive function to keep track  
 of the different types of group.  
   
 Arguments:  
   cd           compile background data  
   name         name to seek, or NULL if seeking a numbered subpattern  
   lorn         name length, or subpattern number if name is NULL  
   xmode        TRUE if we are in /x mode  
   utf          TRUE if we are in UTF-8 / UTF-16 mode  
   
 Returns:       the number of the found subpattern, or -1 if not found  
 */  
   
 static int  
 find_parens(compile_data *cd, const pcre_uchar *name, int lorn, BOOL xmode,  
   BOOL utf)  
 {  
 pcre_uchar *ptr = (pcre_uchar *)cd->start_pattern;  
 int count = 0;  
 int rc;  
   
 /* If the pattern does not start with an opening parenthesis, the first call  
 to find_parens_sub() will scan right to the end (if necessary). However, if it  
 does start with a parenthesis, find_parens_sub() will return when it hits the  
 matching closing parens. That is why we have to have a loop. */  
   
 for (;;)  
   {  
   rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);  
   if (rc > 0 || *ptr++ == 0) break;  
   }  
   
 return rc;  
 }  
   
   
   
   
 /*************************************************  
1368  *      Find first significant op code            *  *      Find first significant op code            *
1369  *************************************************/  *************************************************/
1370    
# Line 1704  and doing the check at the end; a flag s Line 1437  and doing the check at the end; a flag s
1437    
1438  Arguments:  Arguments:
1439    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1440    utf      TRUE in UTF-8 / UTF-16 mode    utf      TRUE in UTF-8 / UTF-16 / UTF-32 mode
1441    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1442    cd       the "compile data" structure    cd       the "compile data" structure
1443    
# Line 1730  for (;;) Line 1463  for (;;)
1463    {    {
1464    int d;    int d;
1465    pcre_uchar *ce, *cs;    pcre_uchar *ce, *cs;
1466    register int op = *cc;    register pcre_uchar op = *cc;
1467    
1468    switch (op)    switch (op)
1469      {      {
# Line 1850  for (;;) Line 1583  for (;;)
1583      case OP_EXACTI:      case OP_EXACTI:
1584      case OP_NOTEXACT:      case OP_NOTEXACT:
1585      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1586      branchlength += GET2(cc,1);      branchlength += (int)GET2(cc,1);
1587      cc += 2 + IMM2_SIZE;      cc += 2 + IMM2_SIZE;
1588  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
1589      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
# Line 1859  for (;;) Line 1592  for (;;)
1592    
1593      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1594      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1595      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)
1596          cc += 2;
1597      cc += 1 + IMM2_SIZE + 1;      cc += 1 + IMM2_SIZE + 1;
1598      break;      break;
1599    
# Line 1894  for (;;) Line 1628  for (;;)
1628    
1629      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1630    
 #if defined SUPPORT_UTF || defined COMPILE_PCRE16  
     case OP_XCLASS:  
     cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];  
     /* Fall through */  
 #endif  
   
1631      case OP_CLASS:      case OP_CLASS:
1632      case OP_NCLASS:      case OP_NCLASS:
1633    #if defined SUPPORT_UTF || defined COMPILE_PCRE16 || defined COMPILE_PCRE32
1634        case OP_XCLASS:
1635        /* The original code caused an unsigned overflow in 64 bit systems,
1636        so now we use a conditional statement. */
1637        if (op == OP_XCLASS)
1638          cc += GET(cc, 1);
1639        else
1640          cc += PRIV(OP_lengths)[OP_CLASS];
1641    #else
1642      cc += PRIV(OP_lengths)[OP_CLASS];      cc += PRIV(OP_lengths)[OP_CLASS];
1643    #endif
1644    
1645      switch (*cc)      switch (*cc)
1646        {        {
# Line 1917  for (;;) Line 1655  for (;;)
1655        case OP_CRRANGE:        case OP_CRRANGE:
1656        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1657        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1658        branchlength += GET2(cc,1);        branchlength += (int)GET2(cc,1);
1659        cc += 1 + 2 * IMM2_SIZE;        cc += 1 + 2 * IMM2_SIZE;
1660        break;        break;
1661    
# Line 2033  length. Line 1771  length.
1771    
1772  Arguments:  Arguments:
1773    code        points to start of expression    code        points to start of expression
1774    utf         TRUE in UTF-8 / UTF-16 mode    utf         TRUE in UTF-8 / UTF-16 / UTF-32 mode
1775    number      the required bracket number or negative to find a lookbehind    number      the required bracket number or negative to find a lookbehind
1776    
1777  Returns:      pointer to the opcode for the bracket, or NULL if not found  Returns:      pointer to the opcode for the bracket, or NULL if not found
# Line 2044  PRIV(find_bracket)(const pcre_uchar *cod Line 1782  PRIV(find_bracket)(const pcre_uchar *cod
1782  {  {
1783  for (;;)  for (;;)
1784    {    {
1785    register int c = *code;    register pcre_uchar c = *code;
1786    
1787    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
1788    
# Line 2067  for (;;) Line 1805  for (;;)
1805    else if (c == OP_CBRA || c == OP_SCBRA ||    else if (c == OP_CBRA || c == OP_SCBRA ||
1806             c == OP_CBRAPOS || c == OP_SCBRAPOS)             c == OP_CBRAPOS || c == OP_SCBRAPOS)
1807      {      {
1808      int n = GET2(code, 1+LINK_SIZE);      int n = (int)GET2(code, 1+LINK_SIZE);
1809      if (n == number) return (pcre_uchar *)code;      if (n == number) return (pcre_uchar *)code;
1810      code += PRIV(OP_lengths)[c];      code += PRIV(OP_lengths)[c];
1811      }      }
# Line 2097  for (;;) Line 1835  for (;;)
1835        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
1836        case OP_TYPEEXACT:        case OP_TYPEEXACT:
1837        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
1838        if (code[1 + IMM2_SIZE] == OP_PROP        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
1839          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;          code += 2;
1840        break;        break;
1841    
1842        case OP_MARK:        case OP_MARK:
1843        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
1844        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
1845        case OP_THEN_ARG:        case OP_THEN_ARG:
1846        code += code[1];        code += code[1];
1847        break;        break;
# Line 2120  for (;;) Line 1855  for (;;)
1855    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
1856    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
1857    
1858  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
1859      if (utf) switch(c)      if (utf) switch(c)
1860        {        {
1861        case OP_CHAR:        case OP_CHAR:
# Line 2172  instance of OP_RECURSE. Line 1907  instance of OP_RECURSE.
1907    
1908  Arguments:  Arguments:
1909    code        points to start of expression    code        points to start of expression
1910    utf         TRUE in UTF-8 / UTF-16 mode    utf         TRUE in UTF-8 / UTF-16 / UTF-32 mode
1911    
1912  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
1913  */  */
# Line 2182  find_recurse(const pcre_uchar *code, BOO Line 1917  find_recurse(const pcre_uchar *code, BOO
1917  {  {
1918  for (;;)  for (;;)
1919    {    {
1920    register int c = *code;    register pcre_uchar c = *code;
1921    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
1922    if (c == OP_RECURSE) return code;    if (c == OP_RECURSE) return code;
1923    
# Line 2217  for (;;) Line 1952  for (;;)
1952        case OP_TYPEUPTO:        case OP_TYPEUPTO:
1953        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
1954        case OP_TYPEEXACT:        case OP_TYPEEXACT:
1955        if (code[1 + IMM2_SIZE] == OP_PROP        if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
1956          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;          code += 2;
1957        break;        break;
1958    
1959        case OP_MARK:        case OP_MARK:
1960        case OP_PRUNE_ARG:        case OP_PRUNE_ARG:
1961        case OP_SKIP_ARG:        case OP_SKIP_ARG:
       code += code[1];  
       break;  
   
1962        case OP_THEN_ARG:        case OP_THEN_ARG:
1963        code += code[1];        code += code[1];
1964        break;        break;
# Line 2240  for (;;) Line 1972  for (;;)
1972      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
1973      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
1974    
1975  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
1976      if (utf) switch(c)      if (utf) switch(c)
1977        {        {
1978        case OP_CHAR:        case OP_CHAR:
# Line 2326  bracket whose current branch will alread Line 2058  bracket whose current branch will alread
2058  Arguments:  Arguments:
2059    code        points to start of search    code        points to start of search
2060    endcode     points to where to stop    endcode     points to where to stop
2061    utf         TRUE if in UTF-8 / UTF-16 mode    utf         TRUE if in UTF-8 / UTF-16 / UTF-32 mode
2062    cd          contains pointers to tables etc.    cd          contains pointers to tables etc.
2063      recurses    chain of recurse_check to catch mutual recursion
2064    
2065  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2066  */  */
2067    
2068    typedef struct recurse_check {
2069      struct recurse_check *prev;
2070      const pcre_uchar *group;
2071    } recurse_check;
2072    
2073  static BOOL  static BOOL
2074  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2075    BOOL utf, compile_data *cd)    BOOL utf, compile_data *cd, recurse_check *recurses)
2076  {  {
2077  register int c;  register pcre_uchar c;
2078    recurse_check this_recurse;
2079    
2080  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
2081       code < endcode;       code < endcode;
2082       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))
# Line 2364  for (code = first_significant_code(code Line 2104  for (code = first_significant_code(code
2104    
2105    if (c == OP_RECURSE)    if (c == OP_RECURSE)
2106      {      {
2107      const pcre_uchar *scode;      const pcre_uchar *scode = cd->start_code + GET(code, 1);
2108      BOOL empty_branch;      BOOL empty_branch;
2109    
2110      /* Test for forward reference */      /* Test for forward reference or uncompleted reference. This is disabled
2111        when called to scan a completed pattern by setting cd->start_workspace to
2112        NULL. */
2113    
2114        if (cd->start_workspace != NULL)
2115          {
2116          const pcre_uchar *tcode;
2117          for (tcode = cd->start_workspace; tcode < cd->hwm; tcode += LINK_SIZE)
2118            if ((int)GET(tcode, 0) == (int)(code + 1 - cd->start_code)) return TRUE;
2119          if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */
2120          }
2121    
2122        /* If we are scanning a completed pattern, there are no forward references
2123        and all groups are complete. We need to detect whether this is a recursive
2124        call, as otherwise there will be an infinite loop. If it is a recursion,
2125        just skip over it. Simple recursions are easily detected. For mutual
2126        recursions we keep a chain on the stack. */
2127    
2128        else
2129          {
2130          recurse_check *r = recurses;
2131          const pcre_uchar *endgroup = scode;
2132    
2133      for (scode = cd->start_workspace; scode < cd->hwm; scode += LINK_SIZE)        do endgroup += GET(endgroup, 1); while (*endgroup == OP_ALT);
2134        if (GET(scode, 0) == code + 1 - cd->start_code) return TRUE;        if (code >= scode && code <= endgroup) continue;  /* Simple recursion */
2135    
2136      /* Not a forward reference, test for completed backward reference */        for (r = recurses; r != NULL; r = r->prev)
2137            if (r->group == scode) break;
2138          if (r != NULL) continue;   /* Mutual recursion */
2139          }
2140    
2141      empty_branch = FALSE;      /* Completed reference; scan the referenced group, remembering it on the
2142      scode = cd->start_code + GET(code, 1);      stack chain to detect mutual recursions. */
     if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */  
2143    
2144      /* Completed backwards reference */      empty_branch = FALSE;
2145        this_recurse.prev = recurses;
2146        this_recurse.group = scode;
2147    
2148      do      do
2149        {        {
2150        if (could_be_empty_branch(scode, endcode, utf, cd))        if (could_be_empty_branch(scode, endcode, utf, cd, &this_recurse))
2151          {          {
2152          empty_branch = TRUE;          empty_branch = TRUE;
2153          break;          break;
# Line 2438  for (code = first_significant_code(code Line 2203  for (code = first_significant_code(code
2203        empty_branch = FALSE;        empty_branch = FALSE;
2204        do        do
2205          {          {
2206          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd))          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd, NULL))
2207            empty_branch = TRUE;            empty_branch = TRUE;
2208          code += GET(code, 1);          code += GET(code, 1);
2209          }          }
# Line 2496  for (code = first_significant_code(code Line 2261  for (code = first_significant_code(code
2261    
2262      /* Opcodes that must match a character */      /* Opcodes that must match a character */
2263    
2264        case OP_ANY:
2265        case OP_ALLANY:
2266        case OP_ANYBYTE:
2267    
2268      case OP_PROP:      case OP_PROP:
2269      case OP_NOTPROP:      case OP_NOTPROP:
2270        case OP_ANYNL:
2271    
2272        case OP_NOT_HSPACE:
2273        case OP_HSPACE:
2274        case OP_NOT_VSPACE:
2275        case OP_VSPACE:
2276      case OP_EXTUNI:      case OP_EXTUNI:
2277    
2278      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
2279      case OP_DIGIT:      case OP_DIGIT:
2280      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
2281      case OP_WHITESPACE:      case OP_WHITESPACE:
2282      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
2283      case OP_WORDCHAR:      case OP_WORDCHAR:
2284      case OP_ANY:  
     case OP_ALLANY:  
     case OP_ANYBYTE:  
2285      case OP_CHAR:      case OP_CHAR:
2286      case OP_CHARI:      case OP_CHARI:
2287      case OP_NOT:      case OP_NOT:
2288      case OP_NOTI:      case OP_NOTI:
2289    
2290      case OP_PLUS:      case OP_PLUS:
2291        case OP_PLUSI:
2292      case OP_MINPLUS:      case OP_MINPLUS:
2293      case OP_POSPLUS:      case OP_MINPLUSI:
2294      case OP_EXACT:  
2295      case OP_NOTPLUS:      case OP_NOTPLUS:
2296        case OP_NOTPLUSI:
2297      case OP_NOTMINPLUS:      case OP_NOTMINPLUS:
2298        case OP_NOTMINPLUSI:
2299    
2300        case OP_POSPLUS:
2301        case OP_POSPLUSI:
2302      case OP_NOTPOSPLUS:      case OP_NOTPOSPLUS:
2303        case OP_NOTPOSPLUSI:
2304    
2305        case OP_EXACT:
2306        case OP_EXACTI:
2307      case OP_NOTEXACT:      case OP_NOTEXACT:
2308        case OP_NOTEXACTI:
2309    
2310      case OP_TYPEPLUS:      case OP_TYPEPLUS:
2311      case OP_TYPEMINPLUS:      case OP_TYPEMINPLUS:
2312      case OP_TYPEPOSPLUS:      case OP_TYPEPOSPLUS:
2313      case OP_TYPEEXACT:      case OP_TYPEEXACT:
2314    
2315      return FALSE;      return FALSE;
2316    
2317      /* These are going to continue, as they may be empty, but we have to      /* These are going to continue, as they may be empty, but we have to
# Line 2543  for (code = first_significant_code(code Line 2331  for (code = first_significant_code(code
2331      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2332      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2333      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2334      if (code[1 + IMM2_SIZE] == OP_PROP      if (code[1 + IMM2_SIZE] == OP_PROP || code[1 + IMM2_SIZE] == OP_NOTPROP)
2335        || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;        code += 2;
2336      break;      break;
2337    
2338      /* End of branch */      /* End of branch */
# Line 2557  for (code = first_significant_code(code Line 2345  for (code = first_significant_code(code
2345      return TRUE;      return TRUE;
2346    
2347      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,
2348      MINUPTO, and POSUPTO may be followed by a multibyte character */      MINUPTO, and POSUPTO and their caseless and negative versions may be
2349        followed by a multibyte character. */
2350    
2351  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
2352      case OP_STAR:      case OP_STAR:
2353      case OP_STARI:      case OP_STARI:
2354        case OP_NOTSTAR:
2355        case OP_NOTSTARI:
2356    
2357      case OP_MINSTAR:      case OP_MINSTAR:
2358      case OP_MINSTARI:      case OP_MINSTARI:
2359        case OP_NOTMINSTAR:
2360        case OP_NOTMINSTARI:
2361    
2362      case OP_POSSTAR:      case OP_POSSTAR:
2363      case OP_POSSTARI:      case OP_POSSTARI:
2364        case OP_NOTPOSSTAR:
2365        case OP_NOTPOSSTARI:
2366    
2367      case OP_QUERY:      case OP_QUERY:
2368      case OP_QUERYI:      case OP_QUERYI:
2369        case OP_NOTQUERY:
2370        case OP_NOTQUERYI:
2371    
2372      case OP_MINQUERY:      case OP_MINQUERY:
2373      case OP_MINQUERYI:      case OP_MINQUERYI:
2374        case OP_NOTMINQUERY:
2375        case OP_NOTMINQUERYI:
2376    
2377      case OP_POSQUERY:      case OP_POSQUERY:
2378      case OP_POSQUERYI:      case OP_POSQUERYI:
2379        case OP_NOTPOSQUERY:
2380        case OP_NOTPOSQUERYI:
2381    
2382      if (utf && HAS_EXTRALEN(code[1])) code += GET_EXTRALEN(code[1]);      if (utf && HAS_EXTRALEN(code[1])) code += GET_EXTRALEN(code[1]);
2383      break;      break;
2384    
2385      case OP_UPTO:      case OP_UPTO:
2386      case OP_UPTOI:      case OP_UPTOI:
2387        case OP_NOTUPTO:
2388        case OP_NOTUPTOI:
2389    
2390      case OP_MINUPTO:      case OP_MINUPTO:
2391      case OP_MINUPTOI:      case OP_MINUPTOI:
2392        case OP_NOTMINUPTO:
2393        case OP_NOTMINUPTOI:
2394    
2395      case OP_POSUPTO:      case OP_POSUPTO:
2396      case OP_POSUPTOI:      case OP_POSUPTOI:
2397        case OP_NOTPOSUPTO:
2398        case OP_NOTPOSUPTOI:
2399    
2400      if (utf && HAS_EXTRALEN(code[1 + IMM2_SIZE])) code += GET_EXTRALEN(code[1 + IMM2_SIZE]);      if (utf && HAS_EXTRALEN(code[1 + IMM2_SIZE])) code += GET_EXTRALEN(code[1 + IMM2_SIZE]);
2401      break;      break;
2402  #endif  #endif
# Line 2591  for (code = first_significant_code(code Line 2407  for (code = first_significant_code(code
2407      case OP_MARK:      case OP_MARK:
2408      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
2409      case OP_SKIP_ARG:      case OP_SKIP_ARG:
     code += code[1];  
     break;  
   
2410      case OP_THEN_ARG:      case OP_THEN_ARG:
2411      code += code[1];      code += code[1];
2412      break;      break;
# Line 2625  Arguments: Line 2438  Arguments:
2438    code        points to start of the recursion    code        points to start of the recursion
2439    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2440    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2441    utf         TRUE if in UTF-8 / UTF-16 mode    utf         TRUE if in UTF-8 / UTF-16 / UTF-32 mode
2442    cd          pointers to tables etc    cd          pointers to tables etc
2443    
2444  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
# Line 2637  could_be_empty(const pcre_uchar *code, c Line 2450  could_be_empty(const pcre_uchar *code, c
2450  {  {
2451  while (bcptr != NULL && bcptr->current_branch >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2452    {    {
2453    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf, cd))    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf, cd, NULL))
2454      return FALSE;      return FALSE;
2455    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2456    }    }
# Line 2691  Returns:   TRUE or FALSE Line 2504  Returns:   TRUE or FALSE
2504  static BOOL  static BOOL
2505  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)
2506  {  {
2507  int terminator;          /* Don't combine these lines; the Solaris cc */  pcre_uchar terminator;          /* Don't combine these lines; the Solaris cc */
2508  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */
2509  for (++ptr; *ptr != 0; ptr++)  for (++ptr; *ptr != CHAR_NULL; ptr++)
2510    {    {
2511    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2512      ptr++;      ptr++;
# Line 2740  register int yield = 0; Line 2553  register int yield = 0;
2553  while (posix_name_lengths[yield] != 0)  while (posix_name_lengths[yield] != 0)
2554    {    {
2555    if (len == posix_name_lengths[yield] &&    if (len == posix_name_lengths[yield] &&
2556      STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;      STRNCMP_UC_C8(ptr, pn, (unsigned int)len) == 0) return yield;
2557    pn += posix_name_lengths[yield] + 1;    pn += posix_name_lengths[yield] + 1;
2558    yield++;    yield++;
2559    }    }
# Line 2772  value in the reference (which is a group Line 2585  value in the reference (which is a group
2585  Arguments:  Arguments:
2586    group      points to the start of the group    group      points to the start of the group
2587    adjust     the amount by which the group is to be moved    adjust     the amount by which the group is to be moved
2588    utf        TRUE in UTF-8 / UTF-16 mode    utf        TRUE in UTF-8 / UTF-16 / UTF-32 mode
2589    cd         contains pointers to tables etc.    cd         contains pointers to tables etc.
2590    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
2591    
# Line 2795  while ((ptr = (pcre_uchar *)find_recurse Line 2608  while ((ptr = (pcre_uchar *)find_recurse
2608    
2609    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)
2610      {      {
2611      offset = GET(hc, 0);      offset = (int)GET(hc, 0);
2612      if (cd->start_code + offset == ptr + 1)      if (cd->start_code + offset == ptr + 1)
2613        {        {
2614        PUT(hc, 0, offset + adjust);        PUT(hc, 0, offset + adjust);
# Line 2808  while ((ptr = (pcre_uchar *)find_recurse Line 2621  while ((ptr = (pcre_uchar *)find_recurse
2621    
2622    if (hc >= cd->hwm)    if (hc >= cd->hwm)
2623      {      {
2624      offset = GET(ptr, 1);      offset = (int)GET(ptr, 1);
2625      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);      if (cd->start_code + offset >= group) PUT(ptr, 1, offset + adjust);
2626      }      }
2627    
# Line 2878  PUT(previous_callout, 2 + LINK_SIZE, len Line 2691  PUT(previous_callout, 2 + LINK_SIZE, len
2691  /* 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
2692  with UCP support. It searches up the characters, looking for ranges of  with UCP support. It searches up the characters, looking for ranges of
2693  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
2694  start address. A character with multiple other cases is returned on its own  start address. A character with multiple other cases is returned on its own
2695  with a special return value.  with a special return value.
2696    
2697  Arguments:  Arguments:
# Line 2890  Arguments: Line 2703  Arguments:
2703  Yield:        -1 when no more  Yield:        -1 when no more
2704                 0 when a range is returned                 0 when a range is returned
2705                >0 the CASESET offset for char with multiple other cases                >0 the CASESET offset for char with multiple other cases
2706                  in this case, ocptr contains the original                  in this case, ocptr contains the original
2707  */  */
2708    
2709  static int  static int
2710  get_othercase_range(unsigned int *cptr, unsigned int d, unsigned int *ocptr,  get_othercase_range(pcre_uint32 *cptr, pcre_uint32 d, pcre_uint32 *ocptr,
2711    unsigned int *odptr)    pcre_uint32 *odptr)
2712  {  {
2713  unsigned int c, othercase, next;  pcre_uint32 c, othercase, next;
2714  int co;  unsigned int co;
2715    
2716  /* Find the first character that has an other case. If it has multiple other  /* Find the first character that has an other case. If it has multiple other
2717  cases, return its case offset value. */  cases, return its case offset value. */
2718    
2719  for (c = *cptr; c <= d; c++)  for (c = *cptr; c <= d; c++)
2720    {    {
2721    if ((co = UCD_CASESET(c)) != 0)    if ((co = UCD_CASESET(c)) != 0)
2722      {      {
2723      *ocptr = c++;   /* Character that has the set */      *ocptr = c++;   /* Character that has the set */
2724      *cptr = c;      /* Rest of input range */      *cptr = c;      /* Rest of input range */
2725      return co;      return (int)co;
2726      }      }
2727    if ((othercase = UCD_OTHERCASE(c)) != c) break;    if ((othercase = UCD_OTHERCASE(c)) != c) break;
2728    }    }
2729    
2730  if (c > d) return -1;  /* Reached end of range */  if (c > d) return -1;  /* Reached end of range */
# Line 2949  Returns:       TRUE if auto-possessifyin Line 2762  Returns:       TRUE if auto-possessifyin
2762  */  */
2763    
2764  static BOOL  static BOOL
2765  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)
2766  {  {
2767    #ifdef SUPPORT_UCP
2768    const pcre_uint32 *p;
2769    #endif
2770    
2771  const ucd_record *prop = GET_UCD(c);  const ucd_record *prop = GET_UCD(c);
2772    
2773  switch(ptype)  switch(ptype)
2774    {    {
2775    case PT_LAMP:    case PT_LAMP:
# Line 2989  switch(ptype) Line 2807  switch(ptype)
2807    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2808            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2809            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
2810    
2811    #ifdef SUPPORT_UCP
2812      case PT_CLIST:
2813      p = PRIV(ucd_caseless_sets) + prop->caseset;
2814      for (;;)
2815        {
2816        if (c < *p) return !negated;
2817        if (c == *p++) return negated;
2818        }
2819      break;  /* Control never reaches here */
2820    #endif
2821    }    }
2822    
2823  return FALSE;  return FALSE;
2824  }  }
2825  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 3006  sense to automatically possessify the re Line 2836  sense to automatically possessify the re
2836    
2837  Arguments:  Arguments:
2838    previous      pointer to the repeated opcode    previous      pointer to the repeated opcode
2839    utf           TRUE in UTF-8 / UTF-16 mode    utf           TRUE in UTF-8 / UTF-16 / UTF-32 mode
2840    ptr           next character in pattern    ptr           next character in pattern
2841    options       options bits    options       options bits
2842    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
# Line 3018  static BOOL Line 2848  static BOOL
2848  check_auto_possessive(const pcre_uchar *previous, BOOL utf,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
2849    const pcre_uchar *ptr, int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
2850  {  {
2851  pcre_int32 c, next;  pcre_uint32 c = NOTACHAR;
2852  int op_code = *previous++;  pcre_uint32 next;
2853    int escape;
2854    pcre_uchar op_code = *previous++;
2855    
2856  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
2857    
# Line 3031  if ((options & PCRE_EXTENDED) != 0) Line 2863  if ((options & PCRE_EXTENDED) != 0)
2863      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
2864        {        {
2865        ptr++;        ptr++;
2866        while (*ptr != 0)        while (*ptr != CHAR_NULL)
2867          {          {
2868          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2869          ptr++;          ptr++;
# Line 3050  value is a character, a negative value i Line 2882  value is a character, a negative value i
2882  if (*ptr == CHAR_BACKSLASH)  if (*ptr == CHAR_BACKSLASH)
2883    {    {
2884    int temperrorcode = 0;    int temperrorcode = 0;
2885    next = check_escape(&ptr, &temperrorcode, cd->bracount, options, FALSE);    escape = check_escape(&ptr, &next, &temperrorcode, cd->bracount, options,
2886        FALSE);
2887    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
2888    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
2889    }    }
2890  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)  else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
2891    {    {
2892      escape = 0;
2893  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2894    if (utf) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
2895  #endif  #endif
# Line 3073  if ((options & PCRE_EXTENDED) != 0) Line 2907  if ((options & PCRE_EXTENDED) != 0)
2907      if (*ptr == CHAR_NUMBER_SIGN)      if (*ptr == CHAR_NUMBER_SIGN)
2908        {        {
2909        ptr++;        ptr++;
2910        while (*ptr != 0)        while (*ptr != CHAR_NULL)
2911          {          {
2912          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2913          ptr++;          ptr++;
# Line 3092  if (*ptr == CHAR_ASTERISK || *ptr == CHA Line 2926  if (*ptr == CHAR_ASTERISK || *ptr == CHA
2926    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)
2927      return FALSE;      return FALSE;
2928    
2929  /* 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. */  
2930    
2931  if (next >= 0) switch(op_code)  if (op_code == OP_CHAR || op_code == OP_CHARI ||
2932        op_code == OP_NOT || op_code == OP_NOTI)
2933    {    {
   case OP_CHAR:  
2934  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2935    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
2936  #else  #else
2937    c = *previous;    c = *previous;
2938  #endif  #endif
2939    return c != next;    }
2940    
2941    /* 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
2942    Unicode property support, we can use it to test the other case of  the next item is a character. */
   high-valued characters. */  
2943    
2944    case OP_CHARI:  if (escape == 0)
2945  #ifdef SUPPORT_UTF    {
2946    GETCHARTEST(c, previous);    /* For a caseless UTF match, the next character may have more than one other
2947  #else    case, which maps to the special PT_CLIST property. Check this first. */
2948    c = *previous;  
2949    #ifdef SUPPORT_UCP
2950      if (utf && c != NOTACHAR && (options & PCRE_CASELESS) != 0)
2951        {
2952        unsigned int ocs = UCD_CASESET(next);
2953        if (ocs > 0) return check_char_prop(c, PT_CLIST, ocs, op_code >= OP_NOT);
2954        }
2955  #endif  #endif
2956    if (c == next) return FALSE;  
2957  #ifdef SUPPORT_UTF    switch(op_code)
   if (utf)  
2958      {      {
2959      unsigned int othercase;      case OP_CHAR:
2960      if (next < 128) othercase = cd->fcc[next]; else      return c != next;
2961    
2962        /* For CHARI (caseless character) we must check the other case. If we have
2963        Unicode property support, we can use it to test the other case of
2964        high-valued characters. We know that next can have only one other case,
2965        because multi-other-case characters are dealt with above. */
2966    
2967        case OP_CHARI:
2968        if (c == next) return FALSE;
2969    #ifdef SUPPORT_UTF
2970        if (utf)
2971          {
2972          pcre_uint32 othercase;
2973          if (next < 128) othercase = cd->fcc[next]; else
2974  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2975      othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
2976  #else  #else
2977      othercase = NOTACHAR;        othercase = NOTACHAR;
2978  #endif  #endif
2979      return (unsigned int)c != othercase;        return c != othercase;
2980      }        }
2981    else      else
2982  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
2983    return (c != TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */      return (c != TABLE_GET(next, cd->fcc, next));  /* Not UTF */
2984    
2985    case OP_NOT:      case OP_NOT:
2986  #ifdef SUPPORT_UTF      return c == next;
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   return c == next;  
2987    
2988    case OP_NOTI:      case OP_NOTI:
2989  #ifdef SUPPORT_UTF      if (c == next) return TRUE;
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   if (c == next) return TRUE;  
2990  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
2991    if (utf)      if (utf)
2992      {        {
2993      unsigned int othercase;        pcre_uint32 othercase;
2994      if (next < 128) othercase = cd->fcc[next]; else        if (next < 128) othercase = cd->fcc[next]; else
2995  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2996      othercase = UCD_OTHERCASE((unsigned int)next);        othercase = UCD_OTHERCASE(next);
2997  #else  #else
2998      othercase = NOTACHAR;        othercase = NOTACHAR;
2999  #endif  #endif
3000      return (unsigned int)c == othercase;        return c == othercase;
3001      }        }
3002    else      else
3003  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3004    return (c == TABLE_GET((unsigned int)next, cd->fcc, next));  /* Non-UTF-8 mode */      return (c == TABLE_GET(next, cd->fcc, next));  /* Not UTF */
3005    
3006    /* 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.
3007    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. */
3008    
3009    case OP_DIGIT:      case OP_DIGIT:
3010    return next > 255 || (cd->ctypes[next] & ctype_digit) == 0;      return next > 255 || (cd->ctypes[next] & ctype_digit) == 0;
3011    
3012    case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
3013    return next <= 255 && (cd->ctypes[next] & ctype_digit) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_digit) != 0;
3014    
3015    case OP_WHITESPACE:      case OP_WHITESPACE:
3016    return next > 255 || (cd->ctypes[next] & ctype_space) == 0;      return next > 255 || (cd->ctypes[next] & ctype_space) == 0;
3017    
3018    case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
3019    return next <= 255 && (cd->ctypes[next] & ctype_space) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_space) != 0;
3020    
3021    case OP_WORDCHAR:      case OP_WORDCHAR:
3022    return next > 255 || (cd->ctypes[next] & ctype_word) == 0;      return next > 255 || (cd->ctypes[next] & ctype_word) == 0;
3023    
3024    case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
3025    return next <= 255 && (cd->ctypes[next] & ctype_word) != 0;      return next <= 255 && (cd->ctypes[next] & ctype_word) != 0;
3026    
3027    case OP_HSPACE:      case OP_HSPACE:
3028    case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
3029    switch(next)      switch(next)
3030      {        {
3031      HSPACE_CASES:        HSPACE_CASES:
3032      return op_code == OP_NOT_HSPACE;        return op_code == OP_NOT_HSPACE;
   
     default:  
     return op_code != OP_NOT_HSPACE;  
     }  
3033    
3034    case OP_ANYNL:        default:
3035    case OP_VSPACE:        return op_code != OP_NOT_HSPACE;
3036    case OP_NOT_VSPACE:        }
3037    switch(next)  
3038      {      case OP_ANYNL:
3039      VSPACE_CASES:      case OP_VSPACE:
3040      return op_code == OP_NOT_VSPACE;      case OP_NOT_VSPACE:
3041        switch(next)
3042      default:        {
3043      return op_code != OP_NOT_VSPACE;        VSPACE_CASES:
3044      }        return op_code == OP_NOT_VSPACE;
3045    
3046          default:
3047          return op_code != OP_NOT_VSPACE;
3048          }
3049    
3050  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3051    case OP_PROP:      case OP_PROP:
3052    return check_char_prop(next, previous[0], previous[1], FALSE);      return check_char_prop(next, previous[0], previous[1], FALSE);
3053    
3054    case OP_NOTPROP:      case OP_NOTPROP:
3055    return check_char_prop(next, previous[0], previous[1], TRUE);      return check_char_prop(next, previous[0], previous[1], TRUE);
3056  #endif  #endif
3057    
3058    default:      default:
3059    return FALSE;      return FALSE;
3060        }
3061    }    }
3062    
   
3063  /* 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
3064  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
3065  generated only when PCRE_UCP is *not* set, that is, when only ASCII  generated only when PCRE_UCP is *not* set, that is, when only ASCII
# Line 3230  switch(op_code) Line 3070  switch(op_code)
3070    {    {
3071    case OP_CHAR:    case OP_CHAR:
3072    case OP_CHARI:    case OP_CHARI:
3073  #ifdef SUPPORT_UTF    switch(escape)
   GETCHARTEST(c, previous);  
 #else  
   c = *previous;  
 #endif  
   switch(-next)  
3074      {      {
3075      case ESC_d:      case ESC_d:
3076      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;      return c > 255 || (cd->ctypes[c] & ctype_digit) == 0;
# Line 3259  switch(op_code) Line 3094  switch(op_code)
3094      case ESC_H:      case ESC_H:
3095      switch(c)      switch(c)
3096        {        {
3097        HSPACE_CASES:        HSPACE_CASES:
3098        return -next != ESC_h;        return escape != ESC_h;
3099    
3100        default:        default:
3101        return -next == ESC_h;        return escape == ESC_h;
3102        }        }
3103    
3104      case ESC_v:      case ESC_v:
3105      case ESC_V:      case ESC_V:
3106      switch(c)      switch(c)
3107        {        {
3108        VSPACE_CASES:        VSPACE_CASES:
3109        return -next != ESC_v;        return escape != ESC_v;
3110    
3111        default:        default:
3112        return -next == ESC_v;        return escape == ESC_v;
3113        }        }
3114    
3115      /* 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
3116      their substitutions and process them. The result will always be either      their substitutions and process them. The result will always be either
3117      -ESC_p or -ESC_P. Then fall through to process those values. */      ESC_p or ESC_P. Then fall through to process those values. */
3118    
3119  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3120      case ESC_du:      case ESC_du:
# Line 3290  switch(op_code) Line 3125  switch(op_code)
3125      case ESC_SU:      case ESC_SU:
3126        {        {
3127        int temperrorcode = 0;        int temperrorcode = 0;
3128        ptr = substitutes[-next - ESC_DU];        ptr = substitutes[escape - ESC_DU];
3129        next = check_escape(&ptr, &temperrorcode, 0, options, FALSE);        escape = check_escape(&ptr, &next, &temperrorcode, 0, options, FALSE);
3130        if (temperrorcode != 0) return FALSE;        if (temperrorcode != 0) return FALSE;
3131        ptr++;    /* For compatibility */        ptr++;    /* For compatibility */
3132        }        }
# Line 3300  switch(op_code) Line 3135  switch(op_code)
3135      case ESC_p:      case ESC_p:
3136      case ESC_P:      case ESC_P:
3137        {        {
3138        int ptype, pdata, errorcodeptr;        unsigned int ptype = 0, pdata = 0;
3139          int errorcodeptr;
3140        BOOL negated;        BOOL negated;
3141    
3142        ptr--;      /* Make ptr point at the p or P */        ptr--;      /* Make ptr point at the p or P */
3143        ptype = get_ucp(&ptr, &negated, &pdata, &errorcodeptr);        if (!get_ucp(&ptr, &negated, &ptype, &pdata, &errorcodeptr))
3144        if (ptype < 0) return FALSE;          return FALSE;
3145        ptr++;      /* Point past the final curly ket */        ptr++;      /* Point past the final curly ket */
3146    
3147        /* If the property item is optional, we have to give up. (When generated        /* If the property item is optional, we have to give up. (When generated
# Line 3318  switch(op_code) Line 3154  switch(op_code)
3154    
3155        /* Do the property check. */        /* Do the property check. */
3156    
3157        return check_char_prop(c, ptype, pdata, (next == -ESC_P) != negated);        return check_char_prop(c, ptype, pdata, (escape == ESC_P) != negated);
3158        }        }
3159  #endif  #endif
3160    
# Line 3333  switch(op_code) Line 3169  switch(op_code)
3169    these op-codes are never generated.) */    these op-codes are never generated.) */
3170    
3171    case OP_DIGIT:    case OP_DIGIT:
3172    return next == -ESC_D || next == -ESC_s || next == -ESC_W ||    return escape == ESC_D || escape == ESC_s || escape == ESC_W ||
3173           next == -ESC_h || next == -ESC_v || next == -ESC_R;           escape == ESC_h || escape == ESC_v || escape == ESC_R;
3174    
3175    case OP_NOT_DIGIT:    case OP_NOT_DIGIT:
3176    return next == -ESC_d;    return escape == ESC_d;
3177    
3178    case OP_WHITESPACE:    case OP_WHITESPACE:
3179    return next == -ESC_S || next == -ESC_d || next == -ESC_w;    return escape == ESC_S || escape == ESC_d || escape == ESC_w;
3180    
3181    case OP_NOT_WHITESPACE:    case OP_NOT_WHITESPACE:
3182    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;
3183    
3184    case OP_HSPACE:    case OP_HSPACE:
3185    return next == -ESC_S || next == -ESC_H || next == -ESC_d ||    return escape == ESC_S || escape == ESC_H || escape == ESC_d ||
3186           next == -ESC_w || next == -ESC_v || next == -ESC_R;           escape == ESC_w || escape == ESC_v || escape == ESC_R;
3187    
3188    case OP_NOT_HSPACE:    case OP_NOT_HSPACE:
3189    return next == -ESC_h;    return escape == ESC_h;
3190    
3191    /* Can't have \S in here because VT matches \S (Perl anomaly) */    /* Can't have \S in here because VT matches \S (Perl anomaly) */
3192    case OP_ANYNL:    case OP_ANYNL:
3193    case OP_VSPACE:    case OP_VSPACE:
3194    return next == -ESC_V || next == -ESC_d || next == -ESC_w;    return escape == ESC_V || escape == ESC_d || escape == ESC_w;
3195    
3196    case OP_NOT_VSPACE:    case OP_NOT_VSPACE:
3197    return next == -ESC_v || next == -ESC_R;    return escape == ESC_v || escape == ESC_R;
3198    
3199    case OP_WORDCHAR:    case OP_WORDCHAR:
3200    return next == -ESC_W || next == -ESC_s || next == -ESC_h ||    return escape == ESC_W || escape == ESC_s || escape == ESC_h ||
3201           next == -ESC_v || next == -ESC_R;           escape == ESC_v || escape == ESC_R;
3202    
3203    case OP_NOT_WORDCHAR:    case OP_NOT_WORDCHAR:
3204    return next == -ESC_w || next == -ESC_d;    return escape == ESC_w || escape == ESC_d;
3205    
3206    default:    default:
3207    return FALSE;    return FALSE;
# Line 3381  switch(op_code) Line 3217  switch(op_code)
3217  *************************************************/  *************************************************/
3218    
3219  /* This function packages up the logic of adding a character or range of  /* This function packages up the logic of adding a character or range of
3220  characters to a class. The character values in the arguments will be within the  characters to a class. The character values in the arguments will be within the
3221  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is  valid values for the current mode (8-bit, 16-bit, UTF, etc). This function is
3222  mutually recursive with the function immediately below.  mutually recursive with the function immediately below.
3223    
3224  Arguments:  Arguments:
3225    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3226    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3227    options       the options word    options       the options word
3228    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3229    start         start of range character    start         start of range character
3230    end           end of range character    end           end of range character
3231    
3232  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3233                  the pointer to extra data is updated                  the pointer to extra data is updated
3234  */  */
3235    
3236  static int  static int
3237  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,  add_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr, int options,
3238    compile_data *cd, unsigned int start, unsigned int end)    compile_data *cd, pcre_uint32 start, pcre_uint32 end)
3239  {  {
3240  unsigned int c;  pcre_uint32 c;
3241  int n8 = 0;  int n8 = 0;
3242    
3243  /* If caseless matching is required, scan the range and process alternate  /* If caseless matching is required, scan the range and process alternate
3244  cases. In Unicode, there are 8-bit characters that have alternate cases that  cases. In Unicode, there are 8-bit characters that have alternate cases that
3245  are greater than 255 and vice-versa. Sometimes we can just extend the original  are greater than 255 and vice-versa. Sometimes we can just extend the original
3246  range. */  range. */
3247    
3248  if ((options & PCRE_CASELESS) != 0)  if ((options & PCRE_CASELESS) != 0)
3249    {    {
3250  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3251    if ((options & PCRE_UTF8) != 0)    if ((options & PCRE_UTF8) != 0)
3252      {      {
3253      int rc;      int rc;
3254      unsigned int oc, od;      pcre_uint32 oc, od;
3255    
3256      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */      options &= ~PCRE_CASELESS;   /* Remove for recursive calls */
3257      c = start;      c = start;
3258    
3259      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)      while ((rc = get_othercase_range(&c, end, &oc, &od)) >= 0)
3260        {        {
3261        /* Handle a single character that has more than one other case. */        /* Handle a single character that has more than one other case. */
3262    
3263        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,        if (rc > 0) n8 += add_list_to_class(classbits, uchardptr, options, cd,
3264          PRIV(ucd_caseless_sets) + rc, oc);          PRIV(ucd_caseless_sets) + rc, oc);
3265    
3266        /* Do nothing if the other case range is within the original range. */        /* Do nothing if the other case range is within the original range. */
3267    
3268        else if (oc >= start && od <= end) continue;        else if (oc >= start && od <= end) continue;
3269    
3270        /* Extend the original range if there is overlap, noting that if oc < c, we        /* Extend the original range if there is overlap, noting that if oc < c, we
3271        can't have od > end because a subrange is always shorter than the basic        can't have od > end because a subrange is always shorter than the basic
3272        range. Otherwise, use a recursive call to add the additional range. */        range. Otherwise, use a recursive call to add the additional range. */
3273    
3274        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */        else if (oc < start && od >= start - 1) start = oc; /* Extend downwards */
3275        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */        else if (od > end && oc <= end + 1) end = od;       /* Extend upwards */
3276        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);        else n8 += add_to_class(classbits, uchardptr, options, cd, oc, od);
# Line 3444  if ((options & PCRE_CASELESS) != 0) Line 3280  if ((options & PCRE_CASELESS) != 0)
3280  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3281    
3282    /* Not UTF-mode, or no UCP */    /* Not UTF-mode, or no UCP */
3283    
3284    for (c = start; c <= end && c < 256; c++)    for (c = start; c <= end && c < 256; c++)
3285      {      {
3286      SETBIT(classbits, cd->fcc[c]);      SETBIT(classbits, cd->fcc[c]);
3287      n8++;      n8++;
3288      }      }
3289    }    }
3290    
3291  /* Now handle the original range. Adjust the final value according to the bit  /* Now handle the original range. Adjust the final value according to the bit
3292  length - this means that the same lists of (e.g.) horizontal spaces can be used  length - this means that the same lists of (e.g.) horizontal spaces can be used
3293  in all cases. */  in all cases. */
3294    
3295  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
3296  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3297    if ((options & PCRE_UTF8) == 0)    if ((options & PCRE_UTF8) == 0)
3298  #endif  #endif
3299    if (end > 0xff) end = 0xff;    if (end > 0xff) end = 0xff;
 #endif  
3300    
3301  #ifdef COMPILE_PCRE16  #elif defined COMPILE_PCRE16
3302  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3303    if ((options & PCRE_UTF16) == 0)    if ((options & PCRE_UTF16) == 0)
3304  #endif  #endif
3305    if (end > 0xffff) end = 0xffff;    if (end > 0xffff) end = 0xffff;
3306  #endif  
3307    #endif /* COMPILE_PCRE[8|16] */
3308    
3309  /* If all characters are less than 256, use the bit map. Otherwise use extra  /* If all characters are less than 256, use the bit map. Otherwise use extra
3310  data. */  data. */
# Line 3477  if (end < 0x100) Line 3313  if (end < 0x100)
3313    {    {
3314    for (c = start; c <= end; c++)    for (c = start; c <= end; c++)
3315      {      {
3316      n8++;      n8++;
3317      SETBIT(classbits, c);      SETBIT(classbits, c);
3318      }      }
3319    }    }
3320    
3321  else  else
3322    {    {
3323    pcre_uchar *uchardata = *uchardptr;    pcre_uchar *uchardata = *uchardptr;
3324    
3325  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3326    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */    if ((options & PCRE_UTF8) != 0)  /* All UTFs use the same flag bit */
3327      {      {
3328      if (start < end)      if (start < end)
3329        {        {
3330        *uchardata++ = XCL_RANGE;        *uchardata++ = XCL_RANGE;
3331        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3332        uchardata += PRIV(ord2utf)(end, uchardata);        uchardata += PRIV(ord2utf)(end, uchardata);
3333        }        }
3334      else if (start == end)      else if (start == end)
3335        {        {
3336        *uchardata++ = XCL_SINGLE;        *uchardata++ = XCL_SINGLE;
3337        uchardata += PRIV(ord2utf)(start, uchardata);        uchardata += PRIV(ord2utf)(start, uchardata);
3338        }        }
3339      }      }
3340    else    else
3341  #endif  /* SUPPORT_UTF */  #endif  /* SUPPORT_UTF */
3342    
3343    /* Without UTF support, character values are constrained by the bit length,    /* Without UTF support, character values are constrained by the bit length,
3344    and can only be > 256 for 16-bit and 32-bit libraries. */    and can only be > 256 for 16-bit and 32-bit libraries. */
3345    
3346  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3347      {}      {}
3348  #else  #else
3349    if (start < end)    if (start < end)
3350      {      {
3351      *uchardata++ = XCL_RANGE;      *uchardata++ = XCL_RANGE;
# Line 3520  else Line 3356  else
3356      {      {
3357      *uchardata++ = XCL_SINGLE;      *uchardata++ = XCL_SINGLE;
3358      *uchardata++ = start;      *uchardata++ = start;
3359      }      }
3360  #endif  #endif
3361    
3362    *uchardptr = uchardata;   /* Updata extra data pointer */    *uchardptr = uchardata;   /* Updata extra data pointer */
3363    }    }
3364    
3365  return n8;    /* Number of 8-bit characters */  return n8;    /* Number of 8-bit characters */
3366  }  }
3367    
3368    
3369    
3370    
3371  /*************************************************  /*************************************************
3372  *        Add a list of characters to a class     *  *        Add a list of characters to a class     *
3373  *************************************************/  *************************************************/
3374    
3375  /* This function is used for adding a list of case-equivalent characters to a  /* This function is used for adding a list of case-equivalent characters to a
3376  class, and also for adding a list of horizontal or vertical whitespace. If the  class, and also for adding a list of horizontal or vertical whitespace. If the
3377  list is in order (which it should be), ranges of characters are detected and  list is in order (which it should be), ranges of characters are detected and
3378  handled appropriately. This function is mutually recursive with the function  handled appropriately. This function is mutually recursive with the function
# Line 3546  Arguments: Line 3382  Arguments:
3382    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3383    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3384    options       the options word    options       the options word
3385    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3386    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3387    except        character to omit; this is used when adding lists of    except        character to omit; this is used when adding lists of
3388                    case-equivalent characters to avoid including the one we                    case-equivalent characters to avoid including the one we
3389                    already know about                    already know about
3390    
3391  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3392                  the pointer to extra data is updated                  the pointer to extra data is updated
3393  */  */
# Line 3565  while (p[0] < NOTACHAR) Line 3401  while (p[0] < NOTACHAR)
3401    {    {
3402    int n = 0;    int n = 0;
3403    if (p[0] != except)    if (p[0] != except)
3404      {      {
3405      while(p[n+1] == p[0] + n + 1) n++;      while(p[n+1] == p[0] + n + 1) n++;
3406      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);      n8 += add_to_class(classbits, uchardptr, options, cd, p[0], p[n]);
3407      }      }
3408    p += n + 1;    p += n + 1;
3409    }    }
3410  return n8;  return n8;
3411  }  }
3412    
3413    
3414    
# Line 3587  Arguments: Line 3423  Arguments:
3423    classbits     the bit map for characters < 256    classbits     the bit map for characters < 256
3424    uchardptr     points to the pointer for extra data    uchardptr     points to the pointer for extra data
3425    options       the options word    options       the options word
3426    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
3427    p             points to row of 32-bit values, terminated by NOTACHAR    p             points to row of 32-bit values, terminated by NOTACHAR
3428    
3429  Returns:        the number of < 256 characters added  Returns:        the number of < 256 characters added
3430                  the pointer to extra data is updated                  the pointer to extra data is updated
3431  */  */
3432    
3433  static int  static int
3434  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,  add_not_list_to_class(pcre_uint8 *classbits, pcre_uchar **uchardptr,
3435    int options, compile_data *cd, const pcre_uint32 *p)    int options, compile_data *cd, const pcre_uint32 *p)
3436  {  {
3437    BOOL utf = (options & PCRE_UTF8) != 0;
3438  int n8 = 0;  int n8 = 0;
3439  if (p[0] > 0)  if (p[0] > 0)
3440    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);    n8 += add_to_class(classbits, uchardptr, options, cd, 0, p[0] - 1);
3441  while (p[0] < NOTACHAR)  while (p[0] < NOTACHAR)
3442    {    {
3443    while (p[1] == p[0] + 1) p++;    while (p[1] == p[0] + 1) p++;
3444    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,    n8 += add_to_class(classbits, uchardptr, options, cd, p[0] + 1,
3445      (p[1] == NOTACHAR)? 0x10ffff : p[1] - 1);      (p[1] == NOTACHAR) ? (utf ? 0x10ffffu : 0xffffffffu) : p[1] - 1);
3446    p++;    p++;
3447    }    }
3448  return n8;  return n8;
3449  }  }
3450    
3451    
3452    
# Line 3624  to find out the amount of memory needed, Line 3461  to find out the amount of memory needed,
3461  phase. The value of lengthptr distinguishes the two phases.  phase. The value of lengthptr distinguishes the two phases.
3462    
3463  Arguments:  Arguments:
3464    optionsptr     pointer to the option bits    optionsptr        pointer to the option bits
3465    codeptr        points to the pointer to the current code point    codeptr           points to the pointer to the current code point
3466    ptrptr         points to the current pattern pointer    ptrptr            points to the current pattern pointer
3467    errorcodeptr   points to error code variable    errorcodeptr      points to error code variable
3468    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr      place to put the first required character
3469    reqcharptr     set to the last literal character required, else < 0    firstcharflagsptr place to put the first character flags, or a negative number
3470    bcptr          points to current branch chain    reqcharptr        place to put the last required character
3471    cond_depth     conditional nesting depth    reqcharflagsptr   place to put the last required character flags, or a negative number
3472    cd             contains pointers to tables etc.    bcptr             points to current branch chain
3473    lengthptr      NULL during the real compile phase    cond_depth        conditional nesting depth
3474                   points to length accumulator during pre-compile phase    cd                contains pointers to tables etc.
3475      lengthptr         NULL during the real compile phase
3476                        points to length accumulator during pre-compile phase
3477    
3478  Returns:         TRUE on success  Returns:            TRUE on success
3479                   FALSE, with *errorcodeptr set non-zero on error                      FALSE, with *errorcodeptr set non-zero on error
3480  */  */
3481    
3482  static BOOL  static BOOL
3483  compile_branch(int *optionsptr, pcre_uchar **codeptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3484    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,    const pcre_uchar **ptrptr, int *errorcodeptr,
3485    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,    pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
3486      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
3487      branch_chain *bcptr, int cond_depth,
3488    compile_data *cd, int *lengthptr)    compile_data *cd, int *lengthptr)
3489  {  {
3490  int repeat_type, op_type;  int repeat_type, op_type;
3491  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3492  int bravalue = 0;  int bravalue = 0;
3493  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3494  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
3495  pcre_int32 zeroreqchar, zerofirstchar;  pcre_int32 firstcharflags, reqcharflags;
3496    pcre_uint32 zeroreqchar, zerofirstchar;
3497    pcre_int32 zeroreqcharflags, zerofirstcharflags;
3498  pcre_int32 req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3499  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3500  int after_manual_callout = 0;  int after_manual_callout = 0;
3501  int length_prevgroup = 0;  int length_prevgroup = 0;
3502  register int c;  register pcre_uint32 c;
3503    int escape;
3504  register pcre_uchar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3505  pcre_uchar *last_code = code;  pcre_uchar *last_code = code;
3506  pcre_uchar *orig_code = code;  pcre_uchar *orig_code = code;
# Line 3676  must not do this for other options (e.g. Line 3520  must not do this for other options (e.g.
3520  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3521    
3522  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
3523  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */
3524  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3525    #ifndef COMPILE_PCRE32
3526  pcre_uchar utf_chars[6];  pcre_uchar utf_chars[6];
3527    #endif
3528  #else  #else
3529  BOOL utf = FALSE;  BOOL utf = FALSE;
3530  #endif  #endif
3531    
3532  /* Helper variables for OP_XCLASS opcode (for characters > 255). */  /* Helper variables for OP_XCLASS opcode (for characters > 255). We define
3533    class_uchardata always so that it can be passed to add_to_class() always,
3534    though it will not be used in non-UTF 8-bit cases. This avoids having to supply
3535    alternative calls for the different cases. */
3536    
3537    pcre_uchar *class_uchardata;
3538  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3539  BOOL xclass;  BOOL xclass;
 pcre_uchar *class_uchardata;  
3540  pcre_uchar *class_uchardata_base;  pcre_uchar *class_uchardata_base;
3541  #endif  #endif
3542    
# Line 3710  to take the zero repeat into account. Th Line 3559  to take the zero repeat into account. Th
3559  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3560  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3561    
3562  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = 0;
3563    firstcharflags = reqcharflags = zerofirstcharflags = zeroreqcharflags = REQ_UNSET;
3564    
3565  /* The variable req_caseopt contains either the REQ_CASELESS value  /* The variable req_caseopt contains either the REQ_CASELESS value
3566  or zero, according to the current setting of the caseless flag. The  or zero, according to the current setting of the caseless flag. The
# Line 3736  for (;; ptr++) Line 3586  for (;; ptr++)
3586    int recno;    int recno;
3587    int refsign;    int refsign;
3588    int skipbytes;    int skipbytes;
3589    int subreqchar;    pcre_uint32 subreqchar, subfirstchar;
3590    int subfirstchar;    pcre_int32 subreqcharflags, subfirstcharflags;
3591    int terminator;    int terminator;
3592    int mclength;    unsigned int mclength;
3593    int tempbracount;    unsigned int tempbracount;
3594      pcre_uint32 ec;
3595    pcre_uchar mcbuffer[8];    pcre_uchar mcbuffer[8];
3596    
3597    /* Get next character in the pattern */    /* Get next character in the pattern */
# Line 3750  for (;; ptr++) Line 3601  for (;; ptr++)
3601    /* 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
3602    string. Nesting only happens one level deep. */    string. Nesting only happens one level deep. */
3603    
3604    if (c == 0 && nestptr != NULL)    if (c == CHAR_NULL && nestptr != NULL)
3605      {      {
3606      ptr = nestptr;      ptr = nestptr;
3607      nestptr = NULL;      nestptr = NULL;
# Line 3825  for (;; ptr++) Line 3676  for (;; ptr++)
3676    
3677    /* 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 */
3678    
3679    if (inescq && c != 0)    if (inescq && c != CHAR_NULL)
3680      {      {
3681      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)      if (c == CHAR_BACKSLASH && ptr[1] == CHAR_E)
3682        {        {
# Line 3873  for (;; ptr++) Line 3724  for (;; ptr++)
3724      if (c == CHAR_NUMBER_SIGN)      if (c == CHAR_NUMBER_SIGN)
3725        {        {
3726        ptr++;        ptr++;
3727        while (*ptr != 0)        while (*ptr != CHAR_NULL)
3728          {          {
3729          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3730          ptr++;          ptr++;
# Line 3881  for (;; ptr++) Line 3732  for (;; ptr++)
3732          if (utf) FORWARDCHAR(ptr);          if (utf) FORWARDCHAR(ptr);
3733  #endif  #endif
3734          }          }
3735        if (*ptr != 0) continue;        if (*ptr != CHAR_NULL) continue;
3736    
3737        /* Else fall through to handle end of string */        /* Else fall through to handle end of string */
3738        c = 0;        c = 0;
# Line 3903  for (;; ptr++) Line 3754  for (;; ptr++)
3754      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3755      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3756      *firstcharptr = firstchar;      *firstcharptr = firstchar;
3757        *firstcharflagsptr = firstcharflags;
3758      *reqcharptr = reqchar;      *reqcharptr = reqchar;
3759        *reqcharflagsptr = reqcharflags;
3760      *codeptr = code;      *codeptr = code;
3761      *ptrptr = ptr;      *ptrptr = ptr;
3762      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3927  for (;; ptr++) Line 3780  for (;; ptr++)
3780      previous = NULL;      previous = NULL;
3781      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3782        {        {
3783        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
3784        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3785        }        }
3786      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3942  for (;; ptr++) Line 3795  for (;; ptr++)
3795      repeats. The value of reqchar doesn't change either. */      repeats. The value of reqchar doesn't change either. */
3796    
3797      case CHAR_DOT:      case CHAR_DOT:
3798      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
3799      zerofirstchar = firstchar;      zerofirstchar = firstchar;
3800        zerofirstcharflags = firstcharflags;
3801      zeroreqchar = reqchar;      zeroreqchar = reqchar;
3802        zeroreqcharflags = reqcharflags;
3803      previous = code;      previous = code;
3804      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
3805      break;      break;
# Line 4018  for (;; ptr++) Line 3873  for (;; ptr++)
3873          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
3874        {        {
3875        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
3876        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;        if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
3877        zerofirstchar = firstchar;        zerofirstchar = firstchar;
3878          zerofirstcharflags = firstcharflags;
3879        break;        break;
3880        }        }
3881    
# Line 4054  for (;; ptr++) Line 3910  for (;; ptr++)
3910      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
3911      loop, c contains the first byte of the character. */      loop, c contains the first byte of the character. */
3912    
3913      if (c != 0) do      if (c != CHAR_NULL) do
3914        {        {
3915        const pcre_uchar *oldptr;        const pcre_uchar *oldptr;
3916    
# Line 4069  for (;; ptr++) Line 3925  for (;; ptr++)
3925        /* In the pre-compile phase, accumulate the length of any extra        /* In the pre-compile phase, accumulate the length of any extra
3926        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
3927        contain a zillion > 255 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
3928        (which is on the stack). We have to remember that there was XCLASS data,        (which is on the stack). We have to remember that there was XCLASS data,
3929        however. */        however. */
3930    
3931        if (lengthptr != NULL && class_uchardata > class_uchardata_base)        if (lengthptr != NULL && class_uchardata > class_uchardata_base)
# Line 4210  for (;; ptr++) Line 4066  for (;; ptr++)
4066    
4067        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
4068          {          {
4069          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);          escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options,
4070              TRUE);
4071          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
4072            if (escape == 0) c = ec;
4073          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 */
4074          else if (-c == ESC_N)            /* \N is not supported in a class */          else if (escape == ESC_N)          /* \N is not supported in a class */
4075            {            {
4076            *errorcodeptr = ERR71;            *errorcodeptr = ERR71;
4077            goto FAILED;            goto FAILED;
4078            }            }
4079          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (escape == ESC_Q)            /* Handle start of quoted string */
4080            {            {
4081            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
4082              {              {
# Line 4228  for (;; ptr++) Line 4085  for (;; ptr++)
4085            else inescq = TRUE;            else inescq = TRUE;
4086            continue;            continue;
4087            }            }
4088          else if (-c == ESC_E) continue;  /* Ignore orphan \E */          else if (escape == ESC_E) continue;  /* Ignore orphan \E */
4089    
4090          if (c < 0)          else
4091            {            {
4092            register const pcre_uint8 *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
4093            /* Every class contains at least two < 256 characters. */            /* Every class contains at least two < 256 characters. */
# Line 4238  for (;; ptr++) Line 4095  for (;; ptr++)
4095            /* Every class contains at least two characters. */            /* Every class contains at least two characters. */
4096            class_one_char += 2;            class_one_char += 2;
4097    
4098            switch (-c)            switch (escape)
4099              {              {
4100  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4101              case ESC_du:     /* These are the values given for \d etc */              case ESC_du:     /* These are the values given for \d etc */
# Line 4248  for (;; ptr++) Line 4105  for (;; ptr++)
4105              case ESC_su:     /* of the default ASCII testing. */              case ESC_su:     /* of the default ASCII testing. */
4106              case ESC_SU:              case ESC_SU:
4107              nestptr = ptr;              nestptr = ptr;
4108              ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */              ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
4109              class_has_8bitchar--;                /* Undo! */              class_has_8bitchar--;                /* Undo! */
4110              continue;              continue;
4111  #endif  #endif
# Line 4286  for (;; ptr++) Line 4143  for (;; ptr++)
4143              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];              for (c = 0; c < 32; c++) classbits[c] |= ~cbits[c+cbit_space];
4144              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */              classbits[1] |= 0x08;    /* Perl 5.004 onwards omits VT from \s */
4145              continue;              continue;
4146    
4147              /* The rest apply in both UCP and non-UCP cases. */              /* The rest apply in both UCP and non-UCP cases. */
4148    
4149              case ESC_h:              case ESC_h:
4150              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4151                PRIV(hspace_list), NOTACHAR);                PRIV(hspace_list), NOTACHAR);
4152              continue;              continue;
4153    
4154              case ESC_H:              case ESC_H:
4155              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4156                cd, PRIV(hspace_list));                cd, PRIV(hspace_list));
4157              continue;              continue;
4158    
4159              case ESC_v:              case ESC_v:
4160              (void)add_list_to_class(classbits, &class_uchardata, options, cd,              (void)add_list_to_class(classbits, &class_uchardata, options, cd,
4161                PRIV(vspace_list), NOTACHAR);                PRIV(vspace_list), NOTACHAR);
4162              continue;              continue;
4163    
4164              case ESC_V:              case ESC_V:
4165              (void)add_not_list_to_class(classbits, &class_uchardata, options,              (void)add_not_list_to_class(classbits, &class_uchardata, options,
4166                cd, PRIV(vspace_list));                cd, PRIV(vspace_list));
4167              continue;              continue;
4168    
4169  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 4314  for (;; ptr++) Line 4171  for (;; ptr++)
4171              case ESC_P:              case ESC_P:
4172                {                {
4173                BOOL negated;                BOOL negated;
4174                int pdata;                unsigned int ptype = 0, pdata = 0;
4175                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
4176                if (ptype < 0) goto FAILED;                  goto FAILED;
4177                *class_uchardata++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((escape == ESC_p) != negated)?
4178                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4179                *class_uchardata++ = ptype;                *class_uchardata++ = ptype;
4180                *class_uchardata++ = pdata;                *class_uchardata++ = pdata;
# Line 4344  for (;; ptr++) Line 4201  for (;; ptr++)
4201    
4202          /* Fall through if the escape just defined a single character (c >= 0).          /* Fall through if the escape just defined a single character (c >= 0).
4203          This may be greater than 256. */          This may be greater than 256. */
4204    
4205            escape = 0;
4206    
4207          }   /* End of backslash handling */          }   /* End of backslash handling */
4208    
4209        /* A character may be followed by '-' to form a range. However, Perl does        /* A character may be followed by '-' to form a range. However, Perl does
# Line 4368  for (;; ptr++) Line 4227  for (;; ptr++)
4227    
4228        if (!inescq && ptr[1] == CHAR_MINUS)        if (!inescq && ptr[1] == CHAR_MINUS)
4229          {          {
4230          int d;          pcre_uint32 d;
4231          ptr += 2;          ptr += 2;
4232          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;          while (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_E) ptr += 2;
4233    
# Line 4383  for (;; ptr++) Line 4242  for (;; ptr++)
4242            inescq = TRUE;            inescq = TRUE;
4243            break;            break;
4244            }            }
4245    
4246          /* Minus (hyphen) at the end of a class is treated as a literal, so put          /* Minus (hyphen) at the end of a class is treated as a literal, so put
4247          back the pointer and jump to handle the character that preceded it. */          back the pointer and jump to handle the character that preceded it. */
4248    
4249          if (*ptr == 0 || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))          if (*ptr == CHAR_NULL || (!inescq && *ptr == CHAR_RIGHT_SQUARE_BRACKET))
4250            {            {
4251            ptr = oldptr;            ptr = oldptr;
4252            goto CLASS_SINGLE_CHARACTER;            goto CLASS_SINGLE_CHARACTER;
4253            }            }
4254    
4255          /* Otherwise, we have a potential range; pick up the next character */          /* Otherwise, we have a potential range; pick up the next character */
4256    
4257  #ifdef SUPPORT_UTF  #ifdef SUPPORT_UTF
# Line 4410  for (;; ptr++) Line 4269  for (;; ptr++)
4269    
4270          if (!inescq && d == CHAR_BACKSLASH)          if (!inescq && d == CHAR_BACKSLASH)
4271            {            {
4272            d = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);            int descape;
4273              descape = check_escape(&ptr, &d, errorcodeptr, cd->bracount, options, TRUE);
4274            if (*errorcodeptr != 0) goto FAILED;            if (*errorcodeptr != 0) goto FAILED;
4275    
4276            /* \b is backspace; any other special means the '-' was literal. */            /* \b is backspace; any other special means the '-' was literal. */
4277    
4278            if (d < 0)            if (descape != 0)
4279              {              {
4280              if (d == -ESC_b) d = CHAR_BS; else              if (descape == ESC_b) d = CHAR_BS; else
4281                {                {
4282                ptr = oldptr;                ptr = oldptr;
4283                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */                goto CLASS_SINGLE_CHARACTER;  /* A few lines below */
# Line 4438  for (;; ptr++) Line 4298  for (;; ptr++)
4298          /* We have found a character range, so single character optimizations          /* We have found a character range, so single character optimizations
4299          cannot be done anymore. Any value greater than 1 indicates that there          cannot be done anymore. Any value greater than 1 indicates that there
4300          is more than one character. */          is more than one character. */
4301    
4302          class_one_char = 2;          class_one_char = 2;
4303    
4304          /* Remember an explicit \r or \n, and add the range to the class. */          /* Remember an explicit \r or \n, and add the range to the class. */
4305    
4306          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;          if (d == CHAR_CR || d == CHAR_NL) cd->external_flags |= PCRE_HASCRORLF;
4307    
4308          class_has_8bitchar +=          class_has_8bitchar +=
4309            add_to_class(classbits, &class_uchardata, options, cd, c, d);            add_to_class(classbits, &class_uchardata, options, cd, c, d);
4310    
4311          continue;   /* Go get the next char in the class */          continue;   /* Go get the next char in the class */
4312          }          }
4313    
4314        /* Handle a single character - we can get here for a normal non-escape        /* Handle a single character - we can get here for a normal non-escape
4315        char, or after \ that introduces a single character or for an apparent        char, or after \ that introduces a single character or for an apparent
4316        range that isn't. Only the value 1 matters for class_one_char, so don't        range that isn't. Only the value 1 matters for class_one_char, so don't
4317        increase it if it is already 2 or more ... just in case there's a class        increase it if it is already 2 or more ... just in case there's a class
4318        with a zillion characters in it. */        with a zillion characters in it. */
4319    
4320        CLASS_SINGLE_CHARACTER:        CLASS_SINGLE_CHARACTER:
# Line 4473  for (;; ptr++) Line 4333  for (;; ptr++)
4333          {          {
4334          ptr++;          ptr++;
4335          zeroreqchar = reqchar;          zeroreqchar = reqchar;
4336            zeroreqcharflags = reqcharflags;
4337    
4338          if (negate_class)          if (negate_class)
4339            {            {
4340            if (firstchar == REQ_UNSET) firstchar = REQ_NONE;  #ifdef SUPPORT_UCP
4341              int d;
4342    #endif
4343              if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4344            zerofirstchar = firstchar;            zerofirstchar = firstchar;
4345            *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;            zerofirstcharflags = firstcharflags;
4346  #ifdef SUPPORT_UTF  
4347            if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)            /* For caseless UTF-8 mode when UCP support is available, check
4348              code += PRIV(ord2utf)(c, code);            whether this character has more than one other case. If so, generate
4349              a special OP_NOTPROP item instead of OP_NOTI. */
4350    
4351    #ifdef SUPPORT_UCP
4352              if (utf && (options & PCRE_CASELESS) != 0 &&
4353                  (d = UCD_CASESET(c)) != 0)
4354                {
4355                *code++ = OP_NOTPROP;
4356                *code++ = PT_CLIST;
4357                *code++ = d;
4358                }
4359            else            else
4360  #endif  #endif
4361              *code++ = c;            /* Char has only one other case, or UCP not available */
4362            goto NOT_CHAR;  
4363                {
4364                *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4365    #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4366                if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4367                  code += PRIV(ord2utf)(c, code);
4368                else
4369    #endif
4370                  *code++ = c;
4371                }
4372    
4373              /* We are finished with this character class */
4374    
4375              goto END_CLASS;
4376            }            }
4377    
4378          /* For a single, positive character, get the value into mcbuffer, and          /* For a single, positive character, get the value into mcbuffer, and
4379          then we can handle this with the normal one-character code. */          then we can handle this with the normal one-character code. */
4380    
4381  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4382          if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)          if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
4383            mclength = PRIV(ord2utf)(c, mcbuffer);            mclength = PRIV(ord2utf)(c, mcbuffer);
4384          else          else
# Line 4502  for (;; ptr++) Line 4389  for (;; ptr++)
4389            }            }
4390          goto ONE_CHAR;          goto ONE_CHAR;
4391          }       /* End of 1-char optimization */          }       /* End of 1-char optimization */
4392    
4393        /* There is more than one character in the class, or an XCLASS item        /* There is more than one character in the class, or an XCLASS item
4394        has been generated. Add this character to the class. */        has been generated. Add this character to the class. */
4395    
4396        class_has_8bitchar +=        class_has_8bitchar +=
4397          add_to_class(classbits, &class_uchardata, options, cd, c, c);          add_to_class(classbits, &class_uchardata, options, cd, c, c);
4398        }        }
4399    
# Line 4514  for (;; ptr++) Line 4401  for (;; ptr++)
4401      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
4402      string. */      string. */
4403    
4404      while (((c = *(++ptr)) != 0 ||      while (((c = *(++ptr)) != CHAR_NULL ||
4405             (nestptr != NULL &&             (nestptr != NULL &&
4406               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != 0)) &&               (ptr = nestptr, nestptr = NULL, c = *(++ptr)) != CHAR_NULL)) &&
4407             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));             (c != CHAR_RIGHT_SQUARE_BRACKET || inescq));
4408    
4409      /* Check for missing terminating ']' */      /* Check for missing terminating ']' */
4410    
4411      if (c == 0)      if (c == CHAR_NULL)
4412        {        {
4413        *errorcodeptr = ERR6;        *errorcodeptr = ERR6;
4414        goto FAILED;        goto FAILED;
4415        }        }
4416    
4417      /* We will need an XCLASS if data has been placed in class_uchardata. In      /* We will need an XCLASS if data has been placed in class_uchardata. In
4418      the second phase this is a sufficient test. However, in the pre-compile      the second phase this is a sufficient test. However, in the pre-compile
4419      phase, class_uchardata gets emptied to prevent workspace overflow, so it      phase, class_uchardata gets emptied to prevent workspace overflow, so it
4420      only if the very last character in the class needs XCLASS will it contain      only if the very last character in the class needs XCLASS will it contain
4421      anything at this point. For this reason, xclass gets set TRUE above when      anything at this point. For this reason, xclass gets set TRUE above when
4422      uchar_classdata is emptied, and that's why this code is the way it is here      uchar_classdata is emptied, and that's why this code is the way it is here
4423      instead of just doing a test on class_uchardata below. */      instead of just doing a test on class_uchardata below. */
4424    
4425  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4426      if (class_uchardata > class_uchardata_base) xclass = TRUE;      if (class_uchardata > class_uchardata_base) xclass = TRUE;
4427  #endif  #endif
# Line 4543  for (;; ptr++) Line 4430  for (;; ptr++)
4430      setting, whatever the repeat count. Any reqchar setting must remain      setting, whatever the repeat count. Any reqchar setting must remain
4431      unchanged after any kind of repeat. */      unchanged after any kind of repeat. */
4432    
4433      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;      if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
4434      zerofirstchar = firstchar;      zerofirstchar = firstchar;
4435        zerofirstcharflags = firstcharflags;
4436      zeroreqchar = reqchar;      zeroreqchar = reqchar;
4437        zeroreqcharflags = reqcharflags;
4438    
4439      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4440      extended class, with its own opcode, unless there was a negated special      extended class, with its own opcode, unless there was a negated special
# Line 4601  for (;; ptr++) Line 4490  for (;; ptr++)
4490        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4491        }        }
4492      code += 32 / sizeof(pcre_uchar);      code += 32 / sizeof(pcre_uchar);
4493      NOT_CHAR:  
4494        END_CLASS:
4495      break;      break;
4496    
4497    
# Line 4639  for (;; ptr++) Line 4529  for (;; ptr++)
4529      if (repeat_min == 0)      if (repeat_min == 0)
4530        {        {
4531        firstchar = zerofirstchar;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4532          firstcharflags = zerofirstcharflags;
4533        reqchar = zeroreqchar;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4534          reqcharflags = zeroreqcharflags;
4535        }        }
4536    
4537      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4725  for (;; ptr++) Line 4617  for (;; ptr++)
4617        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
4618        it's a length rather than a small character. */        it's a length rather than a small character. */
4619    
4620  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4621        if (utf && NOT_FIRSTCHAR(code[-1]))        if (utf && NOT_FIRSTCHAR(code[-1]))
4622          {          {
4623          pcre_uchar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
# Line 4742  for (;; ptr++) Line 4634  for (;; ptr++)
4634          {          {
4635          c = code[-1];          c = code[-1];
4636          if (*previous <= OP_CHARI && repeat_min > 1)          if (*previous <= OP_CHARI && repeat_min > 1)
4637            reqchar = c | req_caseopt | cd->req_varyopt;            {
4638              reqchar = c;
4639              reqcharflags = req_caseopt | cd->req_varyopt;
4640              }
4641          }          }
4642    
4643        /* If the repetition is unlimited, it pays to see if the next thing on        /* If the repetition is unlimited, it pays to see if the next thing on
# Line 4799  for (;; ptr++) Line 4694  for (;; ptr++)
4694    
4695        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
4696    
       /*--------------------------------------------------------------------*/  
       /* 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; */  
       /*--------------------------------------------------------------------*/  
   
4697        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
4698    
4699        repeat_type += op_type;        repeat_type += op_type;
# Line 4861  for (;; ptr++) Line 4746  for (;; ptr++)
4746    
4747          if (repeat_max < 0)          if (repeat_max < 0)
4748            {            {
4749  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4750            if (utf && (c & UTF_LENGTH) != 0)            if (utf && (c & UTF_LENGTH) != 0)
4751              {              {
4752              memcpy(code, utf_chars, IN_UCHARS(c & 7));              memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4886  for (;; ptr++) Line 4771  for (;; ptr++)
4771    
4772          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4773            {            {
4774  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4775            if (utf && (c & UTF_LENGTH) != 0)            if (utf && (c & UTF_LENGTH) != 0)
4776              {              {
4777              memcpy(code, utf_chars, IN_UCHARS(c & 7));              memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4916  for (;; ptr++) Line 4801  for (;; ptr++)
4801    
4802        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
4803    
4804  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
4805        if (utf && (c & UTF_LENGTH) != 0)        if (utf && (c & UTF_LENGTH) != 0)
4806          {          {
4807          memcpy(code, utf_chars, IN_UCHARS(c & 7));          memcpy(code, utf_chars, IN_UCHARS(c & 7));
# Line 4955  for (;; ptr++) Line 4840  for (;; ptr++)
4840          goto END_REPEAT;          goto END_REPEAT;
4841          }          }
4842    
       /*--------------------------------------------------------------------*/  
       /* 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; */  
       /*--------------------------------------------------------------------*/  
   
4843        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
4844          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
4845        else if (repeat_min == 1 && repeat_max == -1)        else if (repeat_min == 1 && repeat_max == -1)
# Line 5124  for (;; ptr++) Line 4999  for (;; ptr++)
4999    
5000            else            else
5001              {              {
5002              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;              if (groupsetfirstchar && reqcharflags < 0)
5003                  {
5004                  reqchar = firstchar;
5005                  reqcharflags = firstcharflags;
5006                  }
5007    
5008              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5009                {                {
# Line 5303  for (;; ptr++) Line 5182  for (;; ptr++)
5182              pcre_uchar *scode = bracode;              pcre_uchar *scode = bracode;
5183              do              do
5184                {                {
5185                if (could_be_empty_branch(scode, ketcode, utf, cd))                if (could_be_empty_branch(scode, ketcode, utf, cd, NULL))
5186                  {                  {
5187                  *bracode += OP_SBRA - OP_BRA;                  *bracode += OP_SBRA - OP_BRA;
5188                  break;                  break;
# Line 5499  for (;; ptr++) Line 5378  for (;; ptr++)
5378        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
5379          {          {
5380          arg = ++ptr;          arg = ++ptr;
5381          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5382          arglen = (int)(ptr - arg);          arglen = (int)(ptr - arg);
5383          if (arglen > (int)MAX_MARK)          if ((unsigned int)arglen > MAX_MARK)
5384            {            {
5385            *errorcodeptr = ERR75;            *errorcodeptr = ERR75;
5386            goto FAILED;            goto FAILED;
# Line 5544  for (;; ptr++) Line 5423  for (;; ptr++)
5423                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;                (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5424    
5425              /* Do not set firstchar after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5426              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;              if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
5427              }              }
5428    
5429            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5613  for (;; ptr++) Line 5492  for (;; ptr++)
5492          {          {
5493          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */          case CHAR_NUMBER_SIGN:                 /* Comment; skip to ket */
5494          ptr++;          ptr++;
5495          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;          while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
5496          if (*ptr == 0)          if (*ptr == CHAR_NULL)
5497            {            {
5498            *errorcodeptr = ERR18;            *errorcodeptr = ERR18;
5499            goto FAILED;            goto FAILED;
# Line 5637  for (;; ptr++) Line 5516  for (;; ptr++)
5516          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5517          case CHAR_LEFT_PARENTHESIS:          case CHAR_LEFT_PARENTHESIS:
5518          bravalue = OP_COND;       /* Conditional group */          bravalue = OP_COND;       /* Conditional group */
5519            tempptr = ptr;
5520    
5521          /* A condition can be an assertion, a number (referring to a numbered          /* A condition can be an assertion, a number (referring to a numbered
5522          group), a name (referring to a named group), or 'R', referring to          group), a name (referring to a named group), or 'R', referring to
# Line 5649  for (;; ptr++) Line 5529  for (;; ptr++)
5529          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
5530          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.
5531          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
5532          cases. */          cases.
5533    
5534            For compatibility with auto-callouts, we allow a callout to be
5535            specified before a condition that is an assertion. First, check for the
5536            syntax of a callout; if found, adjust the temporary pointer that is
5537            used to check for an assertion condition. That's all that is needed! */
5538    
5539            if (ptr[1] == CHAR_QUESTION_MARK && ptr[2] == CHAR_C)
5540              {
5541              for (i = 3;; i++) if (!IS_DIGIT(ptr[i])) break;
5542              if (ptr[i] == CHAR_RIGHT_PARENTHESIS)
5543                tempptr += i + 1;
5544              }
5545    
5546          /* For conditions that are assertions, check the syntax, and then exit          /* For conditions that are assertions, check the syntax, and then exit
5547          the switch. This will take control down to where bracketed groups,          the switch. This will take control down to where bracketed groups,
5548          including assertions, are processed. */          including assertions, are processed. */
5549    
5550          if (ptr[1] == CHAR_QUESTION_MARK && (ptr[2] == CHAR_EQUALS_SIGN ||          if (tempptr[1] == CHAR_QUESTION_MARK &&
5551              ptr[2] == CHAR_EXCLAMATION_MARK || ptr[2] == CHAR_LESS_THAN_SIGN))                (tempptr[2] == CHAR_EQUALS_SIGN ||
5552                   tempptr[2] == CHAR_EXCLAMATION_MARK ||
5553                   tempptr[2] == CHAR_LESS_THAN_SIGN))
5554            break;            break;
5555    
5556          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
# Line 5690  for (;; ptr++) Line 5584  for (;; ptr++)
5584            }            }
5585          else          else
5586            {            {
5587            terminator = 0;            terminator = CHAR_NULL;
5588            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);            if (ptr[1] == CHAR_MINUS || ptr[1] == CHAR_PLUS) refsign = *(++ptr);
5589            }            }
5590    
# Line 5710  for (;; ptr++) Line 5604  for (;; ptr++)
5604          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0)
5605            {            {
5606            if (recno >= 0)            if (recno >= 0)
5607              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;              recno = (IS_DIGIT(*ptr))? recno * 10 + (int)(*ptr - CHAR_0) : -1;
5608            ptr++;            ptr++;
5609            }            }
5610          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
5611    
5612          if ((terminator > 0 && *ptr++ != terminator) ||          if ((terminator > 0 && *ptr++ != (pcre_uchar)terminator) ||
5613              *ptr++ != CHAR_RIGHT_PARENTHESIS)              *ptr++ != CHAR_RIGHT_PARENTHESIS)
5614            {            {
5615            ptr--;      /* Error offset */            ptr--;      /* Error offset */
# Line 5762  for (;; ptr++) Line 5656  for (;; ptr++)
5656            slot += cd->name_entry_size;            slot += cd->name_entry_size;
5657            }            }
5658    
5659          /* Found a previous named subpattern */          /* Found the named subpattern */
5660    
5661          if (i < cd->names_found)          if (i < cd->names_found)
5662            {            {
# Line 5771  for (;; ptr++) Line 5665  for (;; ptr++)
5665            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
5666            }            }
5667    
5668          /* Search the pattern for a forward reference */          /* If terminator == CHAR_NULL it means that the name followed directly
5669            after the opening parenthesis [e.g. (?(abc)...] and in this case there
5670          else if ((i = find_parens(cd, name, namelen,          are some further alternatives to try. For the cases where terminator !=
5671                          (options & PCRE_EXTENDED) != 0, utf)) > 0)          0 [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have
           {  
           PUT2(code, 2+LINK_SIZE, i);  
           code[1+LINK_SIZE]++;  
           }  
   
         /* If terminator == 0 it means that the name followed directly after  
         the opening parenthesis [e.g. (?(abc)...] and in this case there are  
         some further alternatives to try. For the cases where terminator != 0  
         [things like (?(<name>... or (?('name')... or (?(R&name)... ] we have  
5672          now checked all the possibilities, so give an error. */          now checked all the possibilities, so give an error. */
5673    
5674          else if (terminator != 0)          else if (terminator != CHAR_NULL)
5675            {            {
5676            *errorcodeptr = ERR15;            *errorcodeptr = ERR15;
5677            goto FAILED;            goto FAILED;
# Line 5943  for (;; ptr++) Line 5828  for (;; ptr++)
5828          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5829          DEFINE_NAME:    /* Come here from (?< handling */          DEFINE_NAME:    /* Come here from (?< handling */
5830          case CHAR_APOSTROPHE:          case CHAR_APOSTROPHE:
5831            {          terminator = (*ptr == CHAR_LESS_THAN_SIGN)?
5832            terminator = (*ptr == CHAR_LESS_THAN_SIGN)?            CHAR_GREATER_THAN_SIGN : CHAR_APOSTROPHE;
5833              CHAR_GREATER_THAN_SIGN : CHAR_APOSTROPHE;          name = ++ptr;
           name = ++ptr;  
5834    
5835            while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0) ptr++;          while (MAX_255(*ptr) && (cd->ctypes[*ptr] & ctype_word) != 0) ptr++;
5836            namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
5837    
5838            /* In the pre-compile phase, just do a syntax check. */          /* In the pre-compile phase, do a syntax check, remember the longest
5839            name, and then remember the group in a vector, expanding it if
5840            necessary. Duplicates for the same number are skipped; other duplicates
5841            are checked for validity. In the actual compile, there is nothing to
5842            do. */
5843    
5844            if (lengthptr != NULL)          if (lengthptr != NULL)
5845              {
5846              named_group *ng;
5847              pcre_uint32 number = cd->bracount + 1;
5848    
5849              if (*ptr != (pcre_uchar)terminator)
5850              {              {
5851              if (*ptr != terminator)              *errorcodeptr = ERR42;
5852                {              goto FAILED;
5853                *errorcodeptr = ERR42;              }
5854                goto FAILED;  
5855                }            if (cd->names_found >= MAX_NAME_COUNT)
5856              if (cd->names_found >= MAX_NAME_COUNT)              {
5857                *errorcodeptr = ERR49;
5858                goto FAILED;
5859                }
5860    
5861              if (namelen + IMM2_SIZE + 1 > cd->name_entry_size)
5862                {
5863                cd->name_entry_size = namelen + IMM2_SIZE + 1;
5864                if (namelen > MAX_NAME_SIZE)
5865                {                {
5866                *errorcodeptr = ERR49;                *errorcodeptr = ERR48;
5867                goto FAILED;                goto FAILED;
5868                }                }
             if (namelen + IMM2_SIZE + 1 > cd->name_entry_size)  
               {  
               cd->name_entry_size = namelen + IMM2_SIZE + 1;  
               if (namelen > MAX_NAME_SIZE)  
                 {  
                 *errorcodeptr = ERR48;  
                 goto FAILED;  
                 }  
               }  
5869              }              }
5870    
5871            /* In the real compile, create the entry in the table, maintaining            /* Scan the list to check for duplicates. For duplicate names, if the
5872            alphabetical order. Duplicate names for different numbers are            number is the same, break the loop, which causes the name to be
5873            permitted only if PCRE_DUPNAMES is set. Duplicate names for the same            discarded; otherwise, if DUPNAMES is not set, give an error.
5874            number are always OK. (An existing number can be re-used if (?|            If it is set, allow the name with a different number, but continue
5875            appears in the pattern.) In either event, a duplicate name results in            scanning in case this is a duplicate with the same number. For
5876            a duplicate entry in the table, even if the number is the same. This            non-duplicate names, give an error if the number is duplicated. */
5877            is because the number of names, and hence the table size, is computed  
5878            in the pre-compile, and it affects various numbers and pointers which            ng = cd->named_groups;
5879            would all have to be modified, and the compiled code moved down, if            for (i = 0; i < cd->names_found; i++, ng++)
           duplicates with the same number were omitted from the table. This  
           doesn't seem worth the hassle. However, *different* names for the  
           same number are not permitted. */  
   
           else  
5880              {              {
5881              BOOL dupname = FALSE;              if (namelen == ng->length &&
5882              slot = cd->name_table;                  STRNCMP_UC_UC(name, ng->name, namelen) == 0)
5883                  {
5884              for (i = 0; i < cd->names_found; i++)                if (ng->number == number) break;
5885                {                if ((options & PCRE_DUPNAMES) == 0)
               int crc = memcmp(name, slot+IMM2_SIZE, IN_UCHARS(namelen));  
               if (crc == 0)  
                 {  
                 if (slot[IMM2_SIZE+namelen] == 0)  
                   {  
                   if (GET2(slot, 0) != cd->bracount + 1 &&  
                       (options & PCRE_DUPNAMES) == 0)  
                     {  
                     *errorcodeptr = ERR43;  
                     goto FAILED;  
                     }  
                   else dupname = TRUE;  
                   }  
                 else crc = -1;      /* Current name is a substring */  
                 }  
   
               /* Make space in the table and break the loop for an earlier  
               name. For a duplicate or later name, carry on. We do this for  
               duplicates so that in the simple case (when ?(| is not used) they  
               are in order of their numbers. */  
   
               if (crc < 0)  
5886                  {                  {
5887                  memmove(slot + cd->name_entry_size, slot,                  *errorcodeptr = ERR43;
5888                    IN_UCHARS((cd->names_found - i) * cd->name_entry_size));                  goto FAILED;
5889                  break;                  }
5890                  }                }
5891                else if (ng->number == number)
5892                /* Continue the loop for a later or duplicate name */                {
5893                  *errorcodeptr = ERR65;
5894                slot += cd->name_entry_size;                goto FAILED;
5895                }                }
5896                }
             /* For non-duplicate names, check for a duplicate number before  
             adding the new name. */  
5897    
5898              if (!dupname)            if (i >= cd->names_found)     /* Not a duplicate with same number */
5899                {
5900                /* Increase the list size if necessary */
5901    
5902                if (cd->names_found >= cd->named_group_list_size)
5903                {                {
5904                pcre_uchar *cslot = cd->name_table;                int newsize = cd->named_group_list_size * 2;
5905                for (i = 0; i < cd->names_found; i++)                named_group *newspace = (PUBL(malloc))
5906                    (newsize * sizeof(named_group));
5907    
5908                  if (newspace == NULL)
5909                  {                  {
5910                  if (cslot != slot)                  *errorcodeptr = ERR21;
5911                    {                  goto FAILED;
5912                    if (GET2(cslot, 0) == cd->bracount + 1)                  }
5913                      {  
5914                      *errorcodeptr = ERR65;                memcpy(newspace, cd->named_groups,
5915                      goto FAILED;                  cd->named_group_list_size * sizeof(named_group));
5916                      }                if (cd->named_group_list_size > NAMED_GROUP_LIST_SIZE)
5917                    }                  (PUBL(free))((void *)cd->named_groups);
5918                  else i--;                cd->named_groups = newspace;
5919                  cslot += cd->name_entry_size;                cd->named_group_list_size = newsize;
5920                  }                }
5921                }  
5922                cd->named_groups[cd->names_found].name = name;
5923              PUT2(slot, 0, cd->bracount + 1);              cd->named_groups[cd->names_found].length = namelen;
5924              memcpy(slot + IMM2_SIZE, name, IN_UCHARS(namelen));              cd->named_groups[cd->names_found].number = number;
5925              slot[IMM2_SIZE + namelen] = 0;              cd->names_found++;
5926              }              }
5927            }            }
5928    
5929          /* In both pre-compile and compile, count the number of names we've          ptr++;                    /* Move past > or ' in both passes. */
         encountered. */  
   
         cd->names_found++;  
         ptr++;                    /* Move past > or ' */  
5930          goto NUMBERED_GROUP;          goto NUMBERED_GROUP;
5931    
5932    
# Line 6090  for (;; ptr++) Line 5956  for (;; ptr++)
5956    
5957          if (lengthptr != NULL)          if (lengthptr != NULL)
5958            {            {
5959            const pcre_uchar *temp;            named_group *ng;
5960    
5961            if (namelen == 0)            if (namelen == 0)
5962              {              {
5963              *errorcodeptr = ERR62;              *errorcodeptr = ERR62;
5964              goto FAILED;              goto FAILED;
5965              }              }
5966            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
5967              {              {
5968              *errorcodeptr = ERR42;              *errorcodeptr = ERR42;
5969              goto FAILED;              goto FAILED;
# Line 6108  for (;; ptr++) Line 5974  for (;; ptr++)
5974              goto FAILED;              goto FAILED;
5975              }              }
5976    
5977            /* The name table does not exist in the first pass, so we cannot            /* The name table does not exist in the first pass; instead we must
5978            do a simple search as in the code below. Instead, we have to scan the            scan the list of names encountered so far in order to get the
5979            pattern to find the number. It is important that we scan it only as            number. If the name is not found, set the value to 0 for a forward
5980            far as we have got because the syntax of named subpatterns has not            reference. */
5981            been checked for the rest of the pattern, and find_parens() assumes  
5982            correct syntax. In any case, it's a waste of resources to scan            ng = cd->named_groups;
5983            further. We stop the scan at the current point by temporarily            for (i = 0; i < cd->names_found; i++, ng++)
5984            adjusting the value of cd->endpattern. */              {
5985                if (namelen == ng->length &&
5986            temp = cd->end_pattern;                  STRNCMP_UC_UC(name, ng->name, namelen) == 0)
5987            cd->end_pattern = ptr;                break;
5988            recno = find_parens(cd, name, namelen,              }
5989              (options & PCRE_EXTENDED) != 0, utf);            recno = (i < cd->names_found)? ng->number : 0;
           cd->end_pattern = temp;  
           if (recno < 0) recno = 0;    /* Forward ref; set dummy number */  
5990            }            }
5991    
5992          /* In the real compile, seek the name in the table. We check the name          /* In the real compile, search the name table. We check the name
5993          first, and then check that we have reached the end of the name in the          first, and then check that we have reached the end of the name in the
5994          table. That way, if the name that is longer than any in the table,          table. That way, if the name is longer than any in the table, the
5995          the comparison will fail without reading beyond the table entry. */          comparison will fail without reading beyond the table entry. */
5996    
5997          else          else
5998            {            {
# Line 6141  for (;; ptr++) Line 6005  for (;; ptr++)
6005              slot += cd->name_entry_size;              slot += cd->name_entry_size;
6006              }              }
6007    
6008            if (i < cd->names_found)         /* Back reference */            if (i < cd->names_found)
6009              {              {
6010              recno = GET2(slot, 0);              recno = GET2(slot, 0);
6011              }              }
6012            else if ((recno =                /* Forward back reference */            else
                     find_parens(cd, name, namelen,  
                       (options & PCRE_EXTENDED) != 0, utf)) <= 0)  
6013              {              {
6014              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
6015              goto FAILED;              goto FAILED;
# Line 6203  for (;; ptr++) Line 6065  for (;; ptr++)
6065            while(IS_DIGIT(*ptr))            while(IS_DIGIT(*ptr))
6066              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6067    
6068            if (*ptr != terminator)            if (*ptr != (pcre_uchar)terminator)
6069              {              {
6070              *errorcodeptr = ERR29;              *errorcodeptr = ERR29;
6071              goto FAILED;              goto FAILED;
# Line 6257  for (;; ptr++) Line 6119  for (;; ptr++)
6119    
6120              if (called == NULL)              if (called == NULL)
6121                {                {
6122                if (find_parens(cd, NULL, recno,                if (recno > cd->final_bracount)
                     (options & PCRE_EXTENDED) != 0, utf) < 0)  
6123                  {                  {
6124                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
6125                  goto FAILED;                  goto FAILED;
# Line 6307  for (;; ptr++) Line 6168  for (;; ptr++)
6168    
6169          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6170    
6171          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6172          continue;          continue;
6173    
6174    
# Line 6441  for (;; ptr++) Line 6302  for (;; ptr++)
6302           cond_depth +           cond_depth +
6303             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6304           &subfirstchar,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6305             &subfirstcharflags,
6306           &subreqchar,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6307             &subreqcharflags,
6308           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6309           cd,                              /* Tables block */           cd,                              /* Tables block */
6310           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 6502  for (;; ptr++) Line 6365  for (;; ptr++)
6365            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6366            goto FAILED;            goto FAILED;
6367            }            }
6368          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;          if (condcount == 1) subfirstcharflags = subreqcharflags = REQ_NONE;
6369          }          }
6370        }        }
6371    
# Line 6551  for (;; ptr++) Line 6414  for (;; ptr++)
6414      back off. */      back off. */
6415    
6416      zeroreqchar = reqchar;      zeroreqchar = reqchar;
6417        zeroreqcharflags = reqcharflags;
6418      zerofirstchar = firstchar;      zerofirstchar = firstchar;
6419        zerofirstcharflags = firstcharflags;
6420      groupsetfirstchar = FALSE;      groupsetfirstchar = FALSE;
6421    
6422      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
# Line 6562  for (;; ptr++) Line 6427  for (;; ptr++)
6427        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
6428        repeat forces firstchar to "none". */        repeat forces firstchar to "none". */
6429    
6430        if (firstchar == REQ_UNSET)        if (firstcharflags == REQ_UNSET)
6431          {          {
6432          if (subfirstchar >= 0)          if (subfirstcharflags >= 0)
6433            {            {
6434            firstchar = subfirstchar;            firstchar = subfirstchar;
6435              firstcharflags = subfirstcharflags;
6436            groupsetfirstchar = TRUE;            groupsetfirstchar = TRUE;
6437            }            }
6438          else firstchar = REQ_NONE;          else firstcharflags = REQ_NONE;
6439          zerofirstchar = REQ_NONE;          zerofirstcharflags = REQ_NONE;
6440          }          }
6441    
6442        /* If firstchar was previously set, convert the subpattern's firstchar        /* If firstchar was previously set, convert the subpattern's firstchar
6443        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
6444        existence beforehand. */        existence beforehand. */
6445    
6446        else if (subfirstchar >= 0 && subreqchar < 0)        else if (subfirstcharflags >= 0 && subreqcharflags < 0)
6447          subreqchar = subfirstchar | tempreqvary;          {
6448            subreqchar = subfirstchar;
6449            subreqcharflags = subfirstcharflags | tempreqvary;
6450            }
6451    
6452        /* 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
6453        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6454    
6455        if (subreqchar >= 0) reqchar = subreqchar;        if (subreqcharflags >= 0)
6456            {
6457            reqchar = subreqchar;
6458            reqcharflags = subreqcharflags;
6459            }
6460        }        }
6461    
6462      /* For a forward assertion, we take the reqchar, if set. This can be      /* For a forward assertion, we take the reqchar, if set. This can be
# Line 6594  for (;; ptr++) Line 6467  for (;; ptr++)
6467      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
6468      firstchar, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6469    
6470      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;      else if (bravalue == OP_ASSERT && subreqcharflags >= 0)
6471          {
6472          reqchar = subreqchar;
6473          reqcharflags = subreqcharflags;
6474          }
6475      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6476    
6477    
# Line 6602  for (;; ptr++) Line 6479  for (;; ptr++)
6479      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values      /* Handle metasequences introduced by \. For ones like \d, the ESC_ values
6480      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
6481      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
6482      are ESC_REF plus the reference number. Only back references and those types      are negative the reference number. Only back references and those types
6483      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
6484      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
6485      ever created. */      ever created. */
6486    
6487      case CHAR_BACKSLASH:      case CHAR_BACKSLASH:
6488      tempptr = ptr;      tempptr = ptr;
6489      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);      escape = check_escape(&ptr, &ec, errorcodeptr, cd->bracount, options, FALSE);
6490      if (*errorcodeptr != 0) goto FAILED;      if (*errorcodeptr != 0) goto FAILED;
6491    
6492      if (c < 0)      if (escape == 0)                  /* The escape coded a single character */
6493          c = ec;
6494        else
6495        {        {
6496        if (-c == ESC_Q)            /* Handle start of quoted string */        if (escape == ESC_Q)            /* Handle start of quoted string */
6497          {          {
6498          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)          if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
6499            ptr += 2;               /* avoid empty string */            ptr += 2;               /* avoid empty string */
# Line 6622  for (;; ptr++) Line 6501  for (;; ptr++)
6501          continue;          continue;
6502          }          }
6503    
6504        if (-c == ESC_E) continue;  /* Perl ignores an orphan \E */        if (escape == ESC_E) continue;  /* Perl ignores an orphan \E */
6505    
6506        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6507        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6508    
6509        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstcharflags == REQ_UNSET && escape > ESC_b && escape < ESC_Z)
6510          firstchar = REQ_NONE;          firstcharflags = REQ_NONE;
6511    
6512        /* 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. */
6513    
6514        zerofirstchar = firstchar;        zerofirstchar = firstchar;
6515          zerofirstcharflags = firstcharflags;
6516        zeroreqchar = reqchar;        zeroreqchar = reqchar;
6517          zeroreqcharflags = reqcharflags;
6518    
6519        /* \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'
6520        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
6521        -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 <
6522        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
6523        -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
6524        that is a synonym for a named back reference). */        that is a synonym for a named back reference). */
6525    
6526        if (-c == ESC_g)        if (escape == ESC_g)
6527          {          {
6528          const pcre_uchar *p;          const pcre_uchar *p;
6529          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
# Line 6662  for (;; ptr++) Line 6543  for (;; ptr++)
6543          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)          if (ptr[1] != CHAR_PLUS && ptr[1] != CHAR_MINUS)
6544            {            {
6545            BOOL is_a_number = TRUE;            BOOL is_a_number = TRUE;
6546            for (p = ptr + 1; *p != 0 && *p != terminator; p++)            for (p = ptr + 1; *p != CHAR_NULL && *p != (pcre_uchar)terminator; p++)
6547              {              {
6548              if (!MAX_255(*p)) { is_a_number = FALSE; break; }              if (!MAX_255(*p)) { is_a_number = FALSE; break; }
6549              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;              if ((cd->ctypes[*p] & ctype_digit) == 0) is_a_number = FALSE;
6550              if ((cd->ctypes[*p] & ctype_word) == 0) break;              if ((cd->ctypes[*p] & ctype_word) == 0) break;
6551              }              }
6552            if (*p != terminator)            if (*p != (pcre_uchar)terminator)
6553              {              {
6554              *errorcodeptr = ERR57;              *errorcodeptr = ERR57;
6555              break;              break;
# Line 6686  for (;; ptr++) Line 6567  for (;; ptr++)
6567    
6568          p = ptr + 2;          p = ptr + 2;
6569          while (IS_DIGIT(*p)) p++;          while (IS_DIGIT(*p)) p++;
6570          if (*p != terminator)          if (*p != (pcre_uchar)terminator)
6571            {            {
6572            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
6573            break;            break;
# Line 6698  for (;; ptr++) Line 6579  for (;; ptr++)
6579        /* \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).
6580        We also support \k{name} (.NET syntax).  */        We also support \k{name} (.NET syntax).  */
6581    
6582        if (-c == ESC_k)        if (escape == ESC_k)
6583          {          {
6584          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&          if ((ptr[1] != CHAR_LESS_THAN_SIGN &&
6585            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))            ptr[1] != CHAR_APOSTROPHE && ptr[1] != CHAR_LEFT_CURLY_BRACKET))
# Line 6717  for (;; ptr++) Line 6598  for (;; ptr++)
6598        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
6599        ':' later. */        ':' later. */
6600    
6601        if (-c >= ESC_REF)        if (escape < 0)
6602          {          {
6603          open_capitem *oc;          open_capitem *oc;
6604          recno = -c - ESC_REF;          recno = -escape;
6605    
6606          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6607          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6608          previous = code;          previous = code;
6609          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6610          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6747  for (;; ptr++) Line 6628  for (;; ptr++)
6628        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
6629    
6630  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6631        else if (-c == ESC_P || -c == ESC_p)        else if (escape == ESC_P || escape == ESC_p)
6632          {          {
6633          BOOL negated;          BOOL negated;
6634          int pdata;          unsigned int ptype = 0, pdata = 0;
6635          int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);          if (!get_ucp(&ptr, &negated, &ptype, &pdata, errorcodeptr))
6636          if (ptype < 0) goto FAILED;            goto FAILED;
6637          previous = code;          previous = code;
6638          *code++ = ((-c == ESC_p) != negated)? OP_PROP : OP_NOTPROP;          *code++ = ((escape == ESC_p) != negated)? OP_PROP : OP_NOTPROP;
6639          *code++ = ptype;          *code++ = ptype;
6640          *code++ = pdata;          *code++ = pdata;
6641          }          }
# Line 6763  for (;; ptr++) Line 6644  for (;; ptr++)
6644        /* If Unicode properties are not supported, \X, \P, and \p are not        /* If Unicode properties are not supported, \X, \P, and \p are not
6645        allowed. */        allowed. */
6646    
6647        else if (-c == ESC_X || -c == ESC_P || -c == ESC_p)        else if (escape == ESC_X || escape == ESC_P || escape == ESC_p)
6648          {          {
6649          *errorcodeptr = ERR45;          *errorcodeptr = ERR45;
6650          goto FAILED;          goto FAILED;
# Line 6774  for (;; ptr++) Line 6655  for (;; ptr++)
6655        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
6656        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
6657        Unicode property tests. Note that \b and \B do a one-character        Unicode property tests. Note that \b and \B do a one-character
6658        lookbehind. */        lookbehind, and \A also behaves as if it does. */
6659    
6660        else        else
6661          {          {
6662          if ((-c == ESC_b || -c == ESC_B) && cd->max_lookbehind == 0)          if ((escape == ESC_b || escape == ESC_B || escape == ESC_A) &&
6663                 cd->max_lookbehind == 0)
6664            cd->max_lookbehind = 1;            cd->max_lookbehind = 1;
6665  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
6666          if (-c >= ESC_DU && -c <= ESC_wu)          if (escape >= ESC_DU && escape <= ESC_wu)
6667            {            {
6668            nestptr = ptr + 1;                   /* Where to resume */            nestptr = ptr + 1;                   /* Where to resume */
6669            ptr = substitutes[-c - ESC_DU] - 1;  /* Just before substitute */            ptr = substitutes[escape - ESC_DU] - 1;  /* Just before substitute */
6670            }            }
6671          else          else
6672  #endif  #endif
# Line 6792  for (;; ptr++) Line 6674  for (;; ptr++)
6674          so that it works in DFA mode and in lookbehinds. */          so that it works in DFA mode and in lookbehinds. */
6675    
6676            {            {
6677            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (escape > ESC_b && escape < ESC_Z)? code : NULL;
6678            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;            *code++ = (!utf && escape == ESC_C)? OP_ALLANY : escape;
6679            }            }
6680          }          }
6681        continue;        continue;
# Line 6803  for (;; ptr++) Line 6685  for (;; ptr++)
6685      a value > 127. We set its representation in the length/buffer, and then      a value > 127. We set its representation in the length/buffer, and then
6686      handle it as a data character. */      handle it as a data character. */
6687    
6688  #ifdef SUPPORT_UTF  #if defined SUPPORT_UTF && !defined COMPILE_PCRE32
6689      if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)      if (utf && c > MAX_VALUE_FOR_SINGLE_CHAR)
6690        mclength = PRIV(ord2utf)(c, mcbuffer);        mclength = PRIV(ord2utf)(c, mcbuffer);
6691      else      else
# Line 6836  for (;; ptr++) Line 6718  for (;; ptr++)
6718    
6719      ONE_CHAR:      ONE_CHAR:
6720      previous = code;      previous = code;
6721    
6722        /* For caseless UTF-8 mode when UCP support is available, check whether
6723        this character has more than one other case. If so, generate a special
6724        OP_PROP item instead of OP_CHARI. */
6725    
6726    #ifdef SUPPORT_UCP
6727        if (utf && (options & PCRE_CASELESS) != 0)
6728          {
6729          GETCHAR(c, mcbuffer);
6730          if ((c = UCD_CASESET(c)) != 0)
6731            {
6732            *code++ = OP_PROP;
6733            *code++ = PT_CLIST;
6734            *code++ = c;
6735            if (firstcharflags == REQ_UNSET)
6736              firstcharflags = zerofirstcharflags = REQ_NONE;
6737            break;
6738            }
6739          }
6740    #endif
6741    
6742        /* Caseful matches, or not one of the multicase characters. */
6743    
6744      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;      *code++ = ((options & PCRE_CASELESS) != 0)? OP_CHARI : OP_CHAR;
6745      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];      for (c = 0; c < mclength; c++) *code++ = mcbuffer[c];
6746    
# Line 6849  for (;; ptr++) Line 6754  for (;; ptr++)
6754      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
6755      repeat. */      repeat. */
6756    
6757      if (firstchar == REQ_UNSET)      if (firstcharflags == REQ_UNSET)
6758        {        {
6759        zerofirstchar = REQ_NONE;        zerofirstcharflags = REQ_NONE;
6760        zeroreqchar = reqchar;        zeroreqchar = reqchar;
6761          zeroreqcharflags = reqcharflags;
6762    
6763        /* 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
6764        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
# Line 6860  for (;; ptr++) Line 6766  for (;; ptr++)
6766        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6767          {          {
6768          firstchar = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
6769          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;          firstchar = mcbuffer[0];
6770            firstcharflags = req_caseopt;
6771    
6772            if (mclength != 1)
6773              {
6774              reqchar = code[-1];
6775              reqcharflags = cd->req_varyopt;
6776              }
6777          }          }
6778        else firstchar = reqchar = REQ_NONE;        else firstcharflags = reqcharflags = REQ_NONE;
6779        }        }
6780    
6781      /* firstchar was previously set; we can set reqchar only if the length is      /* firstchar was previously set; we can set reqchar only if the length is
# Line 6871  for (;; ptr++) Line 6784  for (;; ptr++)
6784      else      else
6785        {        {
6786        zerofirstchar = firstchar;        zerofirstchar = firstchar;
6787          zerofirstcharflags = firstcharflags;
6788        zeroreqchar = reqchar;        zeroreqchar = reqchar;
6789          zeroreqcharflags = reqcharflags;
6790        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6791          reqchar = code[-1] | req_caseopt | cd->req_varyopt;          {
6792            reqchar = code[-1];
6793            reqcharflags = req_caseopt | cd->req_varyopt;
6794            }
6795        }        }
6796    
6797      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6892  return FALSE; Line 6810  return FALSE;
6810    
6811    
6812    
   
6813  /*************************************************  /*************************************************
6814  *     Compile sequence of alternatives           *  *     Compile sequence of alternatives           *
6815  *************************************************/  *************************************************/
# Line 6905  out the amount of memory needed, as well Line 6822  out the amount of memory needed, as well
6822  value of lengthptr distinguishes the two phases.  value of lengthptr distinguishes the two phases.
6823    
6824  Arguments:  Arguments:
6825    options        option bits, including any changes for this subpattern    options           option bits, including any changes for this subpattern
6826    codeptr        -> the address of the current code pointer    codeptr           -> the address of the current code pointer
6827    ptrptr         -> the address of the current pattern pointer    ptrptr            -> the address of the current pattern pointer
6828    errorcodeptr   -> pointer to error code variable    errorcodeptr      -> pointer to error code variable
6829    lookbehind     TRUE if this is a lookbehind assertion    lookbehind        TRUE if this is a lookbehind assertion
6830    reset_bracount TRUE to reset the count for each branch    reset_bracount    TRUE to reset the count for each branch
6831    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes         skip this many bytes at start (for brackets and OP_COND)
6832    cond_depth     depth of nesting for conditional subpatterns    cond_depth        depth of nesting for conditional subpatterns
6833    firstcharptr   place to put the first required character, or a negative number    firstcharptr      place to put the first required character
6834    reqcharptr     place to put the last required character, or a negative number    firstcharflagsptr place to put the first character flags, or a negative number
6835    bcptr          pointer to the chain of currently open branches    reqcharptr        place to put the last required character
6836    cd             points to the data block with tables pointers etc.    reqcharflagsptr   place to put the last required character flags, or a negative number
6837    lengthptr      NULL during the real compile phase    bcptr             pointer to the chain of currently open branches
6838                   points to length accumulator during pre-compile phase    cd                points to the data block with tables pointers etc.
6839      lengthptr         NULL during the real compile phase
6840                        points to length accumulator during pre-compile phase
6841    
6842  Returns:         TRUE on success  Returns:            TRUE on success
6843  */  */
6844    
6845  static BOOL  static BOOL
6846  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
6847    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
6848    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,    int cond_depth,
6849      pcre_uint32 *firstcharptr, pcre_int32 *firstcharflagsptr,
6850      pcre_uint32 *reqcharptr, pcre_int32 *reqcharflagsptr,
6851    branch_chain *bcptr, compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
6852  {  {
6853  const pcre_uchar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
# Line 6936  pcre_uchar *start_bracket = code; Line 6857  pcre_uchar *start_bracket = code;
6857  pcre_uchar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
6858  open_capitem capitem;  open_capitem capitem;
6859  int capnumber = 0;  int capnumber = 0;
6860  pcre_int32 firstchar, reqchar;  pcre_uint32 firstchar, reqchar;
6861  pcre_int32 branchfirstchar, branchreqchar;  pcre_int32 firstcharflags, reqcharflags;
6862    pcre_uint32 branchfirstchar, branchreqchar;
6863    pcre_int32 branchfirstcharflags, branchreqcharflags;
6864  int length;  int length;
6865  int orig_bracount;  unsigned int orig_bracount;
6866  int max_bracount;  unsigned int max_bracount;
6867  branch_chain bc;  branch_chain bc;
6868    
6869  bc.outer = bcptr;  bc.outer = bcptr;
6870  bc.current_branch = code;  bc.current_branch = code;
6871    
6872  firstchar = reqchar = REQ_UNSET;  firstchar = reqchar = 0;
6873    firstcharflags = reqcharflags = REQ_UNSET;
6874    
6875  /* 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
6876  length of the BRA and KET and any extra bytes that are required at the  length of the BRA and KET and any extra bytes that are required at the
# Line 7006  for (;;) Line 6930  for (;;)
6930    into the length. */    into the length. */
6931    
6932    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
6933          &branchreqchar, &bc, cond_depth, cd,          &branchfirstcharflags, &branchreqchar, &branchreqcharflags, &bc,
6934          (lengthptr == NULL)? NULL : &length))          cond_depth, cd, (lengthptr == NULL)? NULL : &length))
6935      {      {
6936      *ptrptr = ptr;      *ptrptr = ptr;
6937      return FALSE;      return FALSE;
# Line 7028  for (;;) Line 6952  for (;;)
6952      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
6953        {        {
6954        firstchar = branchfirstchar;        firstchar = branchfirstchar;
6955          firstcharflags = branchfirstcharflags;
6956        reqchar = branchreqchar;        reqchar = branchreqchar;
6957          reqcharflags = branchreqcharflags;
6958        }        }
6959    
6960      /* If this is not the first branch, the first char and reqchar have to      /* If this is not the first branch, the first char and reqchar have to
# Line 7042  for (;;) Line 6968  for (;;)
6968        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
6969        previously no reqchar, it takes on the value of the old firstchar. */        previously no reqchar, it takes on the value of the old firstchar. */
6970    
6971        if (firstchar >= 0 && firstchar != branchfirstchar)        if (firstcharflags >= 0 &&
6972              (firstcharflags != branchfirstcharflags || firstchar != branchfirstchar))
6973          {          {
6974          if (reqchar < 0) reqchar = firstchar;          if (reqcharflags < 0)
6975          firstchar = REQ_NONE;            {
6976              reqchar = firstchar;
6977              reqcharflags = firstcharflags;
6978              }
6979            firstcharflags = REQ_NONE;
6980          }          }
6981    
6982        /* 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
6983        branch becomes a reqchar if there isn't a branch reqchar. */        branch becomes a reqchar if there isn't a branch reqchar. */
6984    
6985        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)        if (firstcharflags < 0 && branchfirstcharflags >= 0 && branchreqcharflags < 0)
6986            branchreqchar = branchfirstchar;          {
6987            branchreqchar = branchfirstchar;
6988            branchreqcharflags = branchfirstcharflags;
6989            }
6990    
6991        /* Now ensure that the reqchars match */        /* Now ensure that the reqchars match */
6992    
6993        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))        if (((reqcharflags & ~REQ_VARY) != (branchreqcharflags & ~REQ_VARY)) ||
6994          reqchar = REQ_NONE;            reqchar != branchreqchar)
6995        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */          reqcharflags = REQ_NONE;
6996          else
6997            {
6998            reqchar = branchreqchar;
6999            reqcharflags |= branchreqcharflags; /* To "or" REQ_VARY */
7000            }
7001        }        }
7002    
7003      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
# Line 7154  for (;;) Line 7093  for (;;)
7093      *codeptr = code;      *codeptr = code;
7094      *ptrptr = ptr;      *ptrptr = ptr;
7095      *firstcharptr = firstchar;      *firstcharptr = firstchar;
7096        *firstcharflagsptr = firstcharflags;
7097      *reqcharptr = reqchar;      *reqcharptr = reqchar;
7098        *reqcharflagsptr = reqcharflags;
7099      if (lengthptr != NULL)      if (lengthptr != NULL)
7100        {        {
7101        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 7389  do { Line 7330  do {
7330       {       {
7331       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;       if (!is_startline(scode, bracket_map, cd, atomcount)) return FALSE;
7332       }       }
7333    
7334     /* Atomic brackets */     /* Atomic brackets */
7335    
7336     else if (op == OP_ONCE || op == OP_ONCE_NC)     else if (op == OP_ONCE || op == OP_ONCE_NC)
# Line 7435  return TRUE; Line 7376  return TRUE;
7376  discarded, because they can cause conflicts with actual literals that follow.  discarded, because they can cause conflicts with actual literals that follow.
7377  However, if we end up without a first char setting for an unanchored pattern,  However, if we end up without a first char setting for an unanchored pattern,
7378  it is worth scanning the regex to see if there is an initial asserted first  it is worth scanning the regex to see if there is an initial asserted first
7379  char. If all branches start with the same asserted char, or with a bracket all  char. If all branches start with the same asserted char, or with a
7380  of whose alternatives start with the same asserted char (recurse ad lib), then  non-conditional bracket all of whose alternatives start with the same asserted
7381  we return that char, otherwise -1.  char (recurse ad lib), then we return that char, with the flags set to zero or
7382    REQ_CASELESS; otherwise return zero with REQ_NONE in the flags.
7383    
7384  Arguments:  Arguments:
7385    code       points to start of expression (the bracket)    code       points to start of expression (the bracket)
7386      flags      points to the first char flags, or to REQ_NONE
7387    inassert   TRUE if in an assertion    inassert   TRUE if in an assertion
7388    
7389  Returns:     -1 or the fixed first char  Returns:     the fixed first char, or 0 with REQ_NONE in flags
7390  */  */
7391    
7392  static int  static pcre_uint32
7393  find_firstassertedchar(const pcre_uchar *code, BOOL inassert)  find_firstassertedchar(const pcre_uchar *code, pcre_int32 *flags,
7394      BOOL inassert)
7395  {  {
7396  register int c = -1;  register pcre_uint32 c = 0;
7397    int cflags = REQ_NONE;
7398    
7399    *flags = REQ_NONE;
7400  do {  do {
7401     int d;     pcre_uint32 d;
7402       int dflags;
7403     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||
7404               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;
7405     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,
7406       TRUE);       TRUE);
7407     register int op = *scode;     register pcre_uchar op = *scode;
7408    
7409     switch(op)     switch(op)
7410       {       {
7411       default:       default:
7412       return -1;       return 0;
7413    
7414       case OP_BRA:       case OP_BRA:
7415       case OP_BRAPOS:       case OP_BRAPOS:
# Line 7472  do { Line 7420  do {
7420       case OP_ASSERT:       case OP_ASSERT:
7421       case OP_ONCE:       case OP_ONCE:
7422       case OP_ONCE_NC:       case OP_ONCE_NC:
7423       case OP_COND:       d = find_firstassertedchar(scode, &dflags, op == OP_ASSERT);
7424       if ((d = find_firstassertedchar(scode, op == OP_ASSERT)) < 0)       if (dflags < 0)
7425         return -1;         return 0;
7426       if (c < 0) c = d; else if (c != d) return -1;       if (cflags < 0) { c = d; cflags = dflags; } else if (c != d || cflags != dflags) return 0;
7427       break;       break;
7428    
7429       case OP_EXACT:       case OP_EXACT:
# Line 7486  do { Line 7434  do {
7434       case OP_PLUS:       case OP_PLUS:
7435       case OP_MINPLUS:       case OP_MINPLUS:
7436       case OP_POSPLUS:       case OP_POSPLUS:
7437       if (!inassert) return -1;       if (!inassert) return 0;
7438       if (c < 0) c = scode[1];       if (cflags < 0) { c = scode[1]; cflags = 0; }
7439         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7440       break;       break;
7441    
7442       case OP_EXACTI:       case OP_EXACTI:
# Line 7499  do { Line 7447  do {
7447       case OP_PLUSI:       case OP_PLUSI:
7448       case OP_MINPLUSI:       case OP_MINPLUSI:
7449       case OP_POSPLUSI:       case OP_POSPLUSI:
7450       if (!inassert) return -1;       if (!inassert) return 0;
7451       if (c < 0) c = scode[1] | REQ_CASELESS;       if (cflags < 0) { c = scode[1]; cflags = REQ_CASELESS; }
7452         else if (c != scode[1]) return -1;         else if (c != scode[1]) return 0;
7453       break;       break;
7454       }       }
7455    
7456     code += GET(code, 1);     code += GET(code, 1);
7457     }     }
7458  while (*code == OP_ALT);  while (*code == OP_ALT);
7459    
7460    *flags = cflags;
7461  return c;  return c;
7462  }  }
7463    
7464    
7465    
7466  /*************************************************  /*************************************************
7467    *     Add an entry to the name/number table      *
7468    *************************************************/
7469    
7470    /* This function is called between compiling passes to add an entry to the
7471    name/number table, maintaining alphabetical order. Checking for permitted
7472    and forbidden duplicates has already been done.
7473    
7474    Arguments:
7475      cd           the compile data block
7476      name         the name to add
7477      length       the length of the name
7478      groupno      the group number
7479    
7480    Returns:       nothing
7481    */
7482    
7483    static void
7484    add_name(compile_data *cd, const pcre_uchar *name, int length,
7485      unsigned int groupno)
7486    {
7487    int i;
7488    pcre_uchar *slot = cd->name_table;
7489    
7490    for (i = 0; i < cd->names_found; i++)
7491      {
7492      int crc = memcmp(name, slot+IMM2_SIZE, IN_UCHARS(length));
7493      if (crc == 0 && slot[IMM2_SIZE+length] != 0)
7494        crc = -1; /* Current name is a substring */
7495    
7496      /* Make space in the table and break the loop for an earlier name. For a
7497      duplicate or later name, carry on. We do this for duplicates so that in the
7498      simple case (when ?(| is not used) they are in order of their numbers. In all
7499      cases they are in the order in which they appear in the pattern. */
7500    
7501      if (crc < 0)
7502        {
7503        memmove(slot + cd->name_entry_size, slot,
7504          IN_UCHARS((cd->names_found - i) * cd->name_entry_size));
7505        break;
7506        }
7507    
7508      /* Continue the loop for a later or duplicate name */
7509    
7510      slot += cd->name_entry_size;
7511      }
7512    
7513    PUT2(slot, 0, groupno);
7514    memcpy(slot + IMM2_SIZE, name, IN_UCHARS(length));
7515    slot[IMM2_SIZE + length] = 0;
7516    cd->names_found++;
7517    }
7518    
7519    
7520    
7521    /*************************************************
7522  *        Compile a Regular Expression            *  *        Compile a Regular Expression            *
7523  *************************************************/  *************************************************/
7524    
# Line 7535  Returns:        pointer to compiled data Line 7540  Returns:        pointer to compiled data
7540                  with errorptr and erroroffset set                  with errorptr and erroroffset set
7541  */  */
7542    
7543  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7544  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7545  pcre_compile(const char *pattern, int options, const char **errorptr,  pcre_compile(const char *pattern, int options, const char **errorptr,
7546    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7547  #else  #elif defined COMPILE_PCRE16
7548  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION
7549  pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,  pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,
7550    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7551    #elif defined COMPILE_PCRE32
7552    PCRE_EXP_DEFN pcre32 * PCRE_CALL_CONVENTION
7553    pcre32_compile(PCRE_SPTR32 pattern, int options, const char **errorptr,
7554      int *erroroffset, const unsigned char *tables)
7555  #endif  #endif
7556  {  {
7557  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7558  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7559  #else  #elif defined COMPILE_PCRE16
7560  return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7561    #elif defined COMPILE_PCRE32
7562    return pcre32_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7563  #endif  #endif
7564  }  }
7565    
7566    
7567  #ifdef COMPILE_PCRE8  #if defined COMPILE_PCRE8
7568  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7569  pcre_compile2(const char *pattern, int options, int *errorcodeptr,  pcre_compile2(const char *pattern, int options, int *errorcodeptr,
7570    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7571  #else  #elif defined COMPILE_PCRE16
7572  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre16 * PCRE_CALL_CONVENTION
7573  pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,  pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,
7574    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7575    #elif defined COMPILE_PCRE32
7576    PCRE_EXP_DEFN pcre32 * PCRE_CALL_CONVENTION
7577    pcre32_compile2(PCRE_SPTR32 pattern, int options, int *errorcodeptr,
7578      const char **errorptr, int *erroroffset, const unsigned char *tables)
7579  #endif  #endif
7580  {  {
7581  REAL_PCRE *re;  REAL_PCRE *re;
7582  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7583  pcre_int32 firstchar, reqchar;  pcre_int32 firstcharflags, reqcharflags;
7584    pcre_uint32 firstchar, reqchar;
7585    pcre_uint32 limit_match = PCRE_UINT32_MAX;
7586    pcre_uint32 limit_recursion = PCRE_UINT32_MAX;
7587  int newline;  int newline;
7588  int errorcode = 0;  int errorcode = 0;
7589  int skipatstart = 0;  int skipatstart = 0;
7590  BOOL utf;  BOOL utf;
7591    BOOL never_utf = FALSE;
7592  size_t size;  size_t size;
7593  pcre_uchar *code;  pcre_uchar *code;
7594  const pcre_uchar *codesta