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

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

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

code/trunk/pcre_compile.c revision 749 by ph10, Fri Nov 18 10:36:45 2011 UTC code/branches/pcre16/pcre_compile.c revision 785 by zherczeg, Mon Dec 5 20:12:24 2011 UTC
# Line 97  overrun before it actually does run off Line 97  overrun before it actually does run off
97    
98  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)
99    
100    /* Private flags added to firstchar and reqchar. */
101    
102    #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */
103    #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */
104    
105    /* Repeated character flags. */
106    
107    #define UTF_LENGTH     0x10000000l      /* The char contains its length. */
108    
109  /* Table for handling escaped characters in the range '0'-'z'. Positive returns  /* Table for handling escaped characters in the range '0'-'z'. Positive returns
110  are simple data values; negative values are for special things like \d and so  are simple data values; negative values are for special things like \d and so
# Line 231  static const char posix_names[] = Line 239  static const char posix_names[] =
239    STRING_graph0 STRING_print0 STRING_punct0 STRING_space0    STRING_graph0 STRING_print0 STRING_punct0 STRING_space0
240    STRING_word0  STRING_xdigit;    STRING_word0  STRING_xdigit;
241    
242  static const uschar posix_name_lengths[] = {  static const pcre_uint8 posix_name_lengths[] = {
243    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 };    5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 6, 0 };
244    
245  /* Table of class bit maps for each POSIX class. Each class is formed from a  /* Table of class bit maps for each POSIX class. Each class is formed from a
# Line 266  substitutes must be in the order of the Line 274  substitutes must be in the order of the
274  both positive and negative cases. NULL means no substitute. */  both positive and negative cases. NULL means no substitute. */
275    
276  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
277  static const uschar *substitutes[] = {  static const pcre_uchar string_PNd[]  = {
278    (uschar *)"\\P{Nd}",    /* \D */    CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
279    (uschar *)"\\p{Nd}",    /* \d */    CHAR_N, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
280    (uschar *)"\\P{Xsp}",   /* \S */       /* NOTE: Xsp is Perl space */  static const pcre_uchar string_pNd[]  = {
281    (uschar *)"\\p{Xsp}",   /* \s */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
282    (uschar *)"\\P{Xwd}",   /* \W */    CHAR_N, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
283    (uschar *)"\\p{Xwd}"    /* \w */  static const pcre_uchar string_PXsp[] = {
284      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
285      CHAR_X, CHAR_s, CHAR_p, CHAR_RIGHT_CURLY_BRACKET, '\0' };
286    static const pcre_uchar string_pXsp[] = {
287      CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
288      CHAR_X, CHAR_s, CHAR_p, CHAR_RIGHT_CURLY_BRACKET, '\0' };
289    static const pcre_uchar string_PXwd[] = {
290      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
291      CHAR_X, CHAR_w, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
292    static const pcre_uchar string_pXwd[] = {
293      CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
294      CHAR_X, CHAR_w, CHAR_d, CHAR_RIGHT_CURLY_BRACKET, '\0' };
295    
296    static const pcre_uchar *substitutes[] = {
297      string_PNd,           /* \D */
298      string_pNd,           /* \d */
299      string_PXsp,          /* \S */       /* NOTE: Xsp is Perl space */
300      string_pXsp,          /* \s */
301      string_PXwd,          /* \W */
302      string_pXwd           /* \w */
303  };  };
304    
305  static const uschar *posix_substitutes[] = {  static const pcre_uchar string_pL[] =   {
306    (uschar *)"\\p{L}",     /* alpha */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
307    (uschar *)"\\p{Ll}",    /* lower */    CHAR_L, CHAR_RIGHT_CURLY_BRACKET, '\0' };
308    (uschar *)"\\p{Lu}",    /* upper */  static const pcre_uchar string_pLl[] =  {
309    (uschar *)"\\p{Xan}",   /* alnum */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
310    NULL,                   /* ascii */    CHAR_L, CHAR_l, CHAR_RIGHT_CURLY_BRACKET, '\0' };
311    (uschar *)"\\h",        /* blank */  static const pcre_uchar string_pLu[] =  {
312    NULL,                   /* cntrl */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
313    (uschar *)"\\p{Nd}",    /* digit */    CHAR_L, CHAR_u, CHAR_RIGHT_CURLY_BRACKET, '\0' };
314    NULL,                   /* graph */  static const pcre_uchar string_pXan[] = {
315    NULL,                   /* print */    CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
316    NULL,                   /* punct */    CHAR_X, CHAR_a, CHAR_n, CHAR_RIGHT_CURLY_BRACKET, '\0' };
317    (uschar *)"\\p{Xps}",   /* space */    /* NOTE: Xps is POSIX space */  static const pcre_uchar string_h[] =    {
318    (uschar *)"\\p{Xwd}",   /* word */    CHAR_BACKSLASH, CHAR_h, '\0' };
319    NULL,                   /* xdigit */  static const pcre_uchar string_pXps[] = {
320      CHAR_BACKSLASH, CHAR_p, CHAR_LEFT_CURLY_BRACKET,
321      CHAR_X, CHAR_p, CHAR_s, CHAR_RIGHT_CURLY_BRACKET, '\0' };
322    static const pcre_uchar string_PL[] =   {
323      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
324      CHAR_L, CHAR_RIGHT_CURLY_BRACKET, '\0' };
325    static const pcre_uchar string_PLl[] =  {
326      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
327      CHAR_L, CHAR_l, CHAR_RIGHT_CURLY_BRACKET, '\0' };
328    static const pcre_uchar string_PLu[] =  {
329      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
330      CHAR_L, CHAR_u, CHAR_RIGHT_CURLY_BRACKET, '\0' };
331    static const pcre_uchar string_PXan[] = {
332      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
333      CHAR_X, CHAR_a, CHAR_n, CHAR_RIGHT_CURLY_BRACKET, '\0' };
334    static const pcre_uchar string_H[] =    {
335      CHAR_BACKSLASH, CHAR_H, '\0' };
336    static const pcre_uchar string_PXps[] = {
337      CHAR_BACKSLASH, CHAR_P, CHAR_LEFT_CURLY_BRACKET,
338      CHAR_X, CHAR_p, CHAR_s, CHAR_RIGHT_CURLY_BRACKET, '\0' };
339    
340    static const pcre_uchar *posix_substitutes[] = {
341      string_pL,            /* alpha */
342      string_pLl,           /* lower */
343      string_pLu,           /* upper */
344      string_pXan,          /* alnum */
345      NULL,                 /* ascii */
346      string_h,             /* blank */
347      NULL,                 /* cntrl */
348      string_pNd,           /* digit */
349      NULL,                 /* graph */
350      NULL,                 /* print */
351      NULL,                 /* punct */
352      string_pXps,          /* space */    /* NOTE: Xps is POSIX space */
353      string_pXwd,          /* word */
354      NULL,                 /* xdigit */
355    /* Negated cases */    /* Negated cases */
356    (uschar *)"\\P{L}",     /* ^alpha */    string_PL,            /* ^alpha */
357    (uschar *)"\\P{Ll}",    /* ^lower */    string_PLl,           /* ^lower */
358    (uschar *)"\\P{Lu}",    /* ^upper */    string_PLu,           /* ^upper */
359    (uschar *)"\\P{Xan}",   /* ^alnum */    string_PXan,          /* ^alnum */
360    NULL,                   /* ^ascii */    NULL,                 /* ^ascii */
361    (uschar *)"\\H",        /* ^blank */    string_H,             /* ^blank */
362    NULL,                   /* ^cntrl */    NULL,                 /* ^cntrl */
363    (uschar *)"\\P{Nd}",    /* ^digit */    string_PNd,           /* ^digit */
364    NULL,                   /* ^graph */    NULL,                 /* ^graph */
365    NULL,                   /* ^print */    NULL,                 /* ^print */
366    NULL,                   /* ^punct */    NULL,                 /* ^punct */
367    (uschar *)"\\P{Xps}",   /* ^space */   /* NOTE: Xps is POSIX space */    string_PXps,          /* ^space */   /* NOTE: Xps is POSIX space */
368    (uschar *)"\\P{Xwd}",   /* ^word */    string_PXwd,          /* ^word */
369    NULL                    /* ^xdigit */    NULL                  /* ^xdigit */
370  };  };
371  #define POSIX_SUBSIZE (sizeof(posix_substitutes)/sizeof(uschar *))  #define POSIX_SUBSIZE (sizeof(posix_substitutes) / sizeof(pcre_uchar *))
372  #endif  #endif
373    
374  #define STRING(a)  # a  #define STRING(a)  # a
# Line 412  static const char error_texts[] = Line 474  static const char error_texts[] =
474    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"    "\\k is not followed by a braced, angle-bracketed, or quoted name\0"
475    /* 70 */    /* 70 */
476    "internal error: unknown opcode in find_fixedlength()\0"    "internal error: unknown opcode in find_fixedlength()\0"
477      "Not allowed UTF-8 / UTF-16 code point (>= 0xd800 && <= 0xdfff)\0"
478    ;    ;
479    
480  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 430  For convenience, we use the same bit def Line 493  For convenience, we use the same bit def
493    
494  Then we can use ctype_digit and ctype_xdigit in the code. */  Then we can use ctype_digit and ctype_xdigit in the code. */
495    
496    /* Using a simple comparison for decimal numbers rather than a memory read
497    is much faster, and the resulting code is simpler (the compiler turns it
498    into a subtraction and unsigned comparison). */
499    
500    #define IS_DIGIT(x) ((x) >= CHAR_0 && (x) <= CHAR_9)
501    
502  #ifndef EBCDIC  #ifndef EBCDIC
503    
504  /* This is the "normal" case, for ASCII systems, and EBCDIC systems running in  /* This is the "normal" case, for ASCII systems, and EBCDIC systems running in
505  UTF-8 mode. */  UTF-8 mode. */
506    
507  static const unsigned char digitab[] =  static const pcre_uint8 digitab[] =
508    {    {
509    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7 */
510    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15 */
# Line 474  static const unsigned char digitab[] = Line 543  static const unsigned char digitab[] =
543    
544  /* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */  /* This is the "abnormal" case, for EBCDIC systems not running in UTF-8 mode. */
545    
546  static const unsigned char digitab[] =  static const pcre_uint8 digitab[] =
547    {    {
548    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7  0 */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   0-  7  0 */
549    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15    */    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*   8- 15    */
# Line 509  static const unsigned char digitab[] = Line 578  static const unsigned char digitab[] =
578    0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, /*  0 - 7  F0 */    0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c,0x0c, /*  0 - 7  F0 */
579    0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00};/*  8 -255    */    0x0c,0x0c,0x00,0x00,0x00,0x00,0x00,0x00};/*  8 -255    */
580    
581  static const unsigned char ebcdic_chartab[] = { /* chartable partial dup */  static const pcre_uint8 ebcdic_chartab[] = { /* chartable partial dup */
582    0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*   0-  7 */    0x80,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*   0-  7 */
583    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */    0x00,0x00,0x00,0x00,0x01,0x01,0x00,0x00, /*   8- 15 */
584    0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*  16- 23 */    0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00, /*  16- 23 */
# Line 548  static const unsigned char ebcdic_charta Line 617  static const unsigned char ebcdic_charta
617  /* Definition to allow mutual recursion */  /* Definition to allow mutual recursion */
618    
619  static BOOL  static BOOL
620    compile_regex(int, uschar **, const uschar **, int *, BOOL, BOOL, int, int,    compile_regex(int, pcre_uchar **, const pcre_uchar **, int *, BOOL, BOOL, int, int,
621      int *, int *, branch_chain *, compile_data *, int *);      int *, int *, branch_chain *, compile_data *, int *);
622    
623    
# Line 595  Returns:    TRUE or FALSE Line 664  Returns:    TRUE or FALSE
664  */  */
665    
666  static BOOL  static BOOL
667  is_counted_repeat(const uschar *p)  is_counted_repeat(const pcre_uchar *p)
668  {  {
669  if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  if (!IS_DIGIT(*p)) return FALSE;
670  while ((digitab[*p] & ctype_digit) != 0) p++;  p++;
671    while (IS_DIGIT(*p)) p++;
672  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
673    
674  if (*p++ != CHAR_COMMA) return FALSE;  if (*p++ != CHAR_COMMA) return FALSE;
675  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
676    
677  if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  if (!IS_DIGIT(*p)) return FALSE;
678  while ((digitab[*p] & ctype_digit) != 0) p++;  p++;
679    while (IS_DIGIT(*p)) p++;
680    
681  return (*p == CHAR_RIGHT_CURLY_BRACKET);  return (*p == CHAR_RIGHT_CURLY_BRACKET);
682  }  }
# Line 637  Returns:         zero or positive => a d Line 708  Returns:         zero or positive => a d
708  */  */
709    
710  static int  static int
711  check_escape(const uschar **ptrptr, int *errorcodeptr, int bracount,  check_escape(const pcre_uchar **ptrptr, int *errorcodeptr, int bracount,
712    int options, BOOL isclass)    int options, BOOL isclass)
713  {  {
714  BOOL utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
715  const uschar *ptr = *ptrptr + 1;  BOOL utf = (options & PCRE_UTF8) != 0;
716  int c, i;  const pcre_uchar *ptr = *ptrptr + 1;
717    pcre_int32 c;
718    int i;
719    
720  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */  GETCHARINCTEST(c, ptr);           /* Get character value, increment pointer */
721  ptr--;                            /* Set pointer back to the last byte */  ptr--;                            /* Set pointer back to the last byte */
# Line 656  in a table. A non-zero result is somethi Line 729  in a table. A non-zero result is somethi
729  Otherwise further processing may be required. */  Otherwise further processing may be required. */
730    
731  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
732  else if (c < CHAR_0 || c > CHAR_z) {}                     /* Not alphanumeric */  /* Not alphanumeric */
733    else if (c < CHAR_0 || c > CHAR_z) {}
734  else if ((i = escapes[c - CHAR_0]) != 0) c = i;  else if ((i = escapes[c - CHAR_0]) != 0) c = i;
735    
736  #else           /* EBCDIC coding */  #else           /* EBCDIC coding */
737  else if (c < 'a' || (ebcdic_chartab[c] & 0x0E) == 0) {}   /* Not alphanumeric */  /* Not alphanumeric */
738    else if (c < 'a' || (!MAX_255(c) || (ebcdic_chartab[c] & 0x0E) == 0)) {}
739  else if ((i = escapes[c - 0x48]) != 0)  c = i;  else if ((i = escapes[c - 0x48]) != 0)  c = i;
740  #endif  #endif
741    
# Line 668  else if ((i = escapes[c - 0x48]) != 0) Line 743  else if ((i = escapes[c - 0x48]) != 0)
743    
744  else  else
745    {    {
746    const uschar *oldptr;    const pcre_uchar *oldptr;
747    BOOL braced, negated;    BOOL braced, negated;
748    
749    switch (c)    switch (c)
# Line 686  else Line 761  else
761        {        {
762        /* In JavaScript, \u must be followed by four hexadecimal numbers.        /* In JavaScript, \u must be followed by four hexadecimal numbers.
763        Otherwise it is a lowercase u letter. */        Otherwise it is a lowercase u letter. */
764        if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0        if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
765             && (digitab[ptr[3]] & ctype_xdigit) != 0 && (digitab[ptr[4]] & ctype_xdigit) != 0)          && MAX_255(ptr[2]) && (digitab[ptr[2]] & ctype_xdigit) != 0
766            && MAX_255(ptr[3]) && (digitab[ptr[3]] & ctype_xdigit) != 0
767            && MAX_255(ptr[4]) && (digitab[ptr[4]] & ctype_xdigit) != 0)
768          {          {
769          c = 0;          c = 0;
770          for (i = 0; i < 4; ++i)          for (i = 0; i < 4; ++i)
# Line 741  else Line 818  else
818    
819      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
820        {        {
821        const uschar *p;        const pcre_uchar *p;
822        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)        for (p = ptr+2; *p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET; p++)
823          if (*p != CHAR_MINUS && (digitab[*p] & ctype_digit) == 0) break;          if (*p != CHAR_MINUS && !IS_DIGIT(*p)) break;
824        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)        if (*p != 0 && *p != CHAR_RIGHT_CURLY_BRACKET)
825          {          {
826          c = -ESC_k;          c = -ESC_k;
# Line 761  else Line 838  else
838        }        }
839      else negated = FALSE;      else negated = FALSE;
840    
841        /* The integer range is limited by the machine's int representation. */
842      c = 0;      c = 0;
843      while ((digitab[ptr[1]] & ctype_digit) != 0)      while (IS_DIGIT(ptr[1]))
844          {
845          if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */
846            {
847            c = -1;
848            break;
849            }
850        c = c * 10 + *(++ptr) - CHAR_0;        c = c * 10 + *(++ptr) - CHAR_0;
851          }
852      if (c < 0)   /* Integer overflow */      if (((unsigned int)c) > INT_MAX) /* Integer overflow */
853        {        {
854          while (IS_DIGIT(ptr[1]))
855            ptr++;
856        *errorcodeptr = ERR61;        *errorcodeptr = ERR61;
857        break;        break;
858        }        }
# Line 814  else Line 900  else
900      if (!isclass)      if (!isclass)
901        {        {
902        oldptr = ptr;        oldptr = ptr;
903          /* The integer range is limited by the machine's int representation. */
904        c -= CHAR_0;        c -= CHAR_0;
905        while ((digitab[ptr[1]] & ctype_digit) != 0)        while (IS_DIGIT(ptr[1]))
906            {
907            if (((unsigned int)c) > INT_MAX / 10) /* Integer overflow */
908              {
909              c = -1;
910              break;
911              }
912          c = c * 10 + *(++ptr) - CHAR_0;          c = c * 10 + *(++ptr) - CHAR_0;
913        if (c < 0)    /* Integer overflow */          }
914          if (((unsigned int)c) > INT_MAX) /* Integer overflow */
915          {          {
916            while (IS_DIGIT(ptr[1]))
917              ptr++;
918          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
919          break;          break;
920          }          }
# Line 851  else Line 947  else
947      c -= CHAR_0;      c -= CHAR_0;
948      while(i++ < 2 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7)      while(i++ < 2 && ptr[1] >= CHAR_0 && ptr[1] <= CHAR_7)
949          c = c * 8 + *(++ptr) - CHAR_0;          c = c * 8 + *(++ptr) - CHAR_0;
950      if (!utf8 && c > 255) *errorcodeptr = ERR51;      if (!utf && c > 0xff) *errorcodeptr = ERR51;
951      break;      break;
952    
953      /* \x is complicated. \x{ddd} is a character number which can be greater      /* \x is complicated. \x{ddd} is a character number which can be greater
954      than 0xff in utf8 mode, but only if the ddd are hex digits. If not, { is      than 0xff in utf or non-8bit mode, but only if the ddd are hex digits.
955      treated as a data character. */      If not, { is treated as a data character. */
956    
957      case CHAR_x:      case CHAR_x:
958      if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)      if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
959        {        {
960        /* In JavaScript, \x must be followed by two hexadecimal numbers.        /* In JavaScript, \x must be followed by two hexadecimal numbers.
961        Otherwise it is a lowercase x letter. */        Otherwise it is a lowercase x letter. */
962        if ((digitab[ptr[1]] & ctype_xdigit) != 0 && (digitab[ptr[2]] & ctype_xdigit) != 0)        if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
963            && MAX_255(ptr[2]) && (digitab[ptr[2]] & ctype_xdigit) != 0)
964          {          {
965          c = 0;          c = 0;
966          for (i = 0; i < 2; ++i)          for (i = 0; i < 2; ++i)
# Line 883  else Line 980  else
980    
981      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)      if (ptr[1] == CHAR_LEFT_CURLY_BRACKET)
982        {        {
983        const uschar *pt = ptr + 2;        const pcre_uchar *pt = ptr + 2;
       int count = 0;  
984    
985        c = 0;        c = 0;
986        while ((digitab[*pt] & ctype_xdigit) != 0)        while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0)
987          {          {
988          register int cc = *pt++;          register int cc = *pt++;
989          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */          if (c == 0 && cc == CHAR_0) continue;     /* Leading zeroes */
         count++;  
990    
991  #ifndef EBCDIC  /* ASCII/UTF-8 coding */  #ifndef EBCDIC  /* ASCII/UTF-8 coding */
992          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */          if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
# Line 900  else Line 995  else
995          if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */          if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
996          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));          c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
997  #endif  #endif
998    
999    #ifdef COMPILE_PCRE8
1000            if (c > (utf ? 0x10ffff : 0xff)) { c = -1; break; }
1001    #else
1002    #ifdef COMPILE_PCRE16
1003            if (c > (utf ? 0x10ffff : 0xffff)) { c = -1; break; }
1004    #endif
1005    #endif
1006            }
1007    
1008          if (c < 0)
1009            {
1010            while (MAX_255(*pt) && (digitab[*pt] & ctype_xdigit) != 0) pt++;
1011            *errorcodeptr = ERR34;
1012          }          }
1013    
1014        if (*pt == CHAR_RIGHT_CURLY_BRACKET)        if (*pt == CHAR_RIGHT_CURLY_BRACKET)
1015          {          {
1016          if (c < 0 || count > (utf8? 8 : 2)) *errorcodeptr = ERR34;          if (utf && c >= 0xd800 && c <= 0xdfff) *errorcodeptr = ERR71;
1017          ptr = pt;          ptr = pt;
1018          break;          break;
1019          }          }
# Line 916  else Line 1025  else
1025      /* Read just a single-byte hex-defined char */      /* Read just a single-byte hex-defined char */
1026    
1027      c = 0;      c = 0;
1028      while (i++ < 2 && (digitab[ptr[1]] & ctype_xdigit) != 0)      while (i++ < 2 && MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0)
1029        {        {
1030        int cc;                                  /* Some compilers don't like */        int cc;                                  /* Some compilers don't like */
1031        cc = *(++ptr);                           /* ++ in initializers */        cc = *(++ptr);                           /* ++ in initializers */
# Line 1014  Returns:         type value from ucp_typ Line 1123  Returns:         type value from ucp_typ
1123  */  */
1124    
1125  static int  static int
1126  get_ucp(const uschar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)  get_ucp(const pcre_uchar **ptrptr, BOOL *negptr, int *dptr, int *errorcodeptr)
1127  {  {
1128  int c, i, bot, top;  int c, i, bot, top;
1129  const uschar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
1130  char name[32];  pcre_uchar name[32];
1131    
1132  c = *(++ptr);  c = *(++ptr);
1133  if (c == 0) goto ERROR_RETURN;  if (c == 0) goto ERROR_RETURN;
# Line 1059  else Line 1168  else
1168  /* Search for a recognized property name using binary chop */  /* Search for a recognized property name using binary chop */
1169    
1170  bot = 0;  bot = 0;
1171  top = _pcre_utt_size;  top = PRIV(utt_size);
1172    
1173  while (bot < top)  while (bot < top)
1174    {    {
1175    i = (bot + top) >> 1;    i = (bot + top) >> 1;
1176    c = strcmp(name, _pcre_utt_names + _pcre_utt[i].name_offset);    c = STRCMP_UC_C8(name, PRIV(utt_names) + PRIV(utt)[i].name_offset);
1177    if (c == 0)    if (c == 0)
1178      {      {
1179      *dptr = _pcre_utt[i].value;      *dptr = PRIV(utt)[i].value;
1180      return _pcre_utt[i].type;      return PRIV(utt)[i].type;
1181      }      }
1182    if (c > 0) bot = i + 1; else top = i;    if (c > 0) bot = i + 1; else top = i;
1183    }    }
# Line 1106  Returns:         pointer to '}' on succe Line 1215  Returns:         pointer to '}' on succe
1215                   current ptr on error, with errorcodeptr set non-zero                   current ptr on error, with errorcodeptr set non-zero
1216  */  */
1217    
1218  static const uschar *  static const pcre_uchar *
1219  read_repeat_counts(const uschar *p, int *minp, int *maxp, int *errorcodeptr)  read_repeat_counts(const pcre_uchar *p, int *minp, int *maxp, int *errorcodeptr)
1220  {  {
1221  int min = 0;  int min = 0;
1222  int max = -1;  int max = -1;
# Line 1115  int max = -1; Line 1224  int max = -1;
1224  /* Read the minimum value and do a paranoid check: a negative value indicates  /* Read the minimum value and do a paranoid check: a negative value indicates
1225  an integer overflow. */  an integer overflow. */
1226    
1227  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - CHAR_0;  while (IS_DIGIT(*p)) min = min * 10 + *p++ - CHAR_0;
1228  if (min < 0 || min > 65535)  if (min < 0 || min > 65535)
1229    {    {
1230    *errorcodeptr = ERR5;    *errorcodeptr = ERR5;
# Line 1130  if (*p == CHAR_RIGHT_CURLY_BRACKET) max Line 1239  if (*p == CHAR_RIGHT_CURLY_BRACKET) max
1239    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)    if (*(++p) != CHAR_RIGHT_CURLY_BRACKET)
1240      {      {
1241      max = 0;      max = 0;
1242      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - CHAR_0;      while(IS_DIGIT(*p)) max = max * 10 + *p++ - CHAR_0;
1243      if (max < 0 || max > 65535)      if (max < 0 || max > 65535)
1244        {        {
1245        *errorcodeptr = ERR5;        *errorcodeptr = ERR5;
# Line 1185  Arguments: Line 1294  Arguments:
1294    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1295    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1296    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1297    utf8         TRUE if we are in UTF-8 mode    utf          TRUE if we are in UTF-8 / UTF-16 mode
1298    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1299    
1300  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
1301  */  */
1302    
1303  static int  static int
1304  find_parens_sub(uschar **ptrptr, compile_data *cd, const uschar *name, int lorn,  find_parens_sub(pcre_uchar **ptrptr, compile_data *cd, const pcre_uchar *name, int lorn,
1305    BOOL xmode, BOOL utf8, int *count)    BOOL xmode, BOOL utf, int *count)
1306  {  {
1307  uschar *ptr = *ptrptr;  pcre_uchar *ptr = *ptrptr;
1308  int start_count = *count;  int start_count = *count;
1309  int hwm_count = start_count;  int hwm_count = start_count;
1310  BOOL dup_parens = FALSE;  BOOL dup_parens = FALSE;
# Line 1262  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1371  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1371          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)
1372        {        {
1373        int term;        int term;
1374        const uschar *thisname;        const pcre_uchar *thisname;
1375        *count += 1;        *count += 1;
1376        if (name == NULL && *count == lorn) return *count;        if (name == NULL && *count == lorn) return *count;
1377        term = *ptr++;        term = *ptr++;
# Line 1270  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1379  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1379        thisname = ptr;        thisname = ptr;
1380        while (*ptr != term) ptr++;        while (*ptr != term) ptr++;
1381        if (name != NULL && lorn == ptr - thisname &&        if (name != NULL && lorn == ptr - thisname &&
1382            strncmp((const char *)name, (const char *)thisname, lorn) == 0)            STRNCMP_UC_UC(name, thisname, lorn) == 0)
1383          return *count;          return *count;
1384        term++;        term++;
1385        }        }
# Line 1313  for (; ptr < cd->end_pattern; ptr++) Line 1422  for (; ptr < cd->end_pattern; ptr++)
1422          {          {
1423          if (ptr[2] == CHAR_E)          if (ptr[2] == CHAR_E)
1424            ptr+= 2;            ptr+= 2;
1425          else if (strncmp((const char *)ptr+2,          else if (STRNCMP_UC_C8(ptr + 2,
1426                   STR_Q STR_BACKSLASH STR_E, 3) == 0)                   STR_Q STR_BACKSLASH STR_E, 3) == 0)
1427            ptr += 4;            ptr += 4;
1428          else          else
# Line 1361  for (; ptr < cd->end_pattern; ptr++) Line 1470  for (; ptr < cd->end_pattern; ptr++)
1470        {        {
1471        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }        if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
1472        ptr++;        ptr++;
1473  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1474        if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;        if (utf) FORWARDCHAR(ptr);
1475  #endif  #endif
1476        }        }
1477      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
# Line 1373  for (; ptr < cd->end_pattern; ptr++) Line 1482  for (; ptr < cd->end_pattern; ptr++)
1482    
1483    if (*ptr == CHAR_LEFT_PARENTHESIS)    if (*ptr == CHAR_LEFT_PARENTHESIS)
1484      {      {
1485      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, count);
1486      if (rc > 0) return rc;      if (rc > 0) return rc;
1487      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
1488      }      }
# Line 1419  Arguments: Line 1528  Arguments:
1528    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1529    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1530    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1531    utf8         TRUE if we are in UTF-8 mode    utf          TRUE if we are in UTF-8 / UTF-16 mode
1532    
1533  Returns:       the number of the found subpattern, or -1 if not found  Returns:       the number of the found subpattern, or -1 if not found
1534  */  */
1535    
1536  static int  static int
1537  find_parens(compile_data *cd, const uschar *name, int lorn, BOOL xmode,  find_parens(compile_data *cd, const pcre_uchar *name, int lorn, BOOL xmode,
1538    BOOL utf8)    BOOL utf)
1539  {  {
1540  uschar *ptr = (uschar *)cd->start_pattern;  pcre_uchar *ptr = (pcre_uchar *)cd->start_pattern;
1541  int count = 0;  int count = 0;
1542  int rc;  int rc;
1543    
# Line 1439  matching closing parens. That is why we Line 1548  matching closing parens. That is why we
1548    
1549  for (;;)  for (;;)
1550    {    {
1551    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf8, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, utf, &count);
1552    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == 0) break;
1553    }    }
1554    
# Line 1466  Arguments: Line 1575  Arguments:
1575  Returns:       pointer to the first significant opcode  Returns:       pointer to the first significant opcode
1576  */  */
1577    
1578  static const uschar*  static const pcre_uchar*
1579  first_significant_code(const uschar *code, BOOL skipassert)  first_significant_code(const pcre_uchar *code, BOOL skipassert)
1580  {  {
1581  for (;;)  for (;;)
1582    {    {
# Line 1478  for (;;) Line 1587  for (;;)
1587      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1588      if (!skipassert) return code;      if (!skipassert) return code;
1589      do code += GET(code, 1); while (*code == OP_ALT);      do code += GET(code, 1); while (*code == OP_ALT);
1590      code += _pcre_OP_lengths[*code];      code += PRIV(OP_lengths)[*code];
1591      break;      break;
1592    
1593      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
# Line 1492  for (;;) Line 1601  for (;;)
1601      case OP_RREF:      case OP_RREF:
1602      case OP_NRREF:      case OP_NRREF:
1603      case OP_DEF:      case OP_DEF:
1604      code += _pcre_OP_lengths[*code];      code += PRIV(OP_lengths)[*code];
1605      break;      break;
1606    
1607      default:      default:
# Line 1522  and doing the check at the end; a flag s Line 1631  and doing the check at the end; a flag s
1631    
1632  Arguments:  Arguments:
1633    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1634    utf8     TRUE in UTF-8 mode    utf      TRUE in UTF-8 / UTF-16 mode
1635    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1636    cd       the "compile data" structure    cd       the "compile data" structure
1637    
1638  Returns:   the fixed length,  Returns:   the fixed length,
1639               or -1 if there is no fixed length,               or -1 if there is no fixed length,
1640               or -2 if \C was encountered               or -2 if \C was encountered (in UTF-8 mode only)
1641               or -3 if an OP_RECURSE item was encountered and atend is FALSE               or -3 if an OP_RECURSE item was encountered and atend is FALSE
1642               or -4 if an unknown opcode was encountered (internal error)               or -4 if an unknown opcode was encountered (internal error)
1643  */  */
1644    
1645  static int  static int
1646  find_fixedlength(uschar *code, BOOL utf8, BOOL atend, compile_data *cd)  find_fixedlength(pcre_uchar *code, BOOL utf, BOOL atend, compile_data *cd)
1647  {  {
1648  int length = -1;  int length = -1;
1649    
1650  register int branchlength = 0;  register int branchlength = 0;
1651  register uschar *cc = code + 1 + LINK_SIZE;  register pcre_uchar *cc = code + 1 + LINK_SIZE;
1652    
1653  /* Scan along the opcodes for this branch. If we get to the end of the  /* Scan along the opcodes for this branch. If we get to the end of the
1654  branch, check the length against that of the other branches. */  branch, check the length against that of the other branches. */
# Line 1547  branch, check the length against that of Line 1656  branch, check the length against that of
1656  for (;;)  for (;;)
1657    {    {
1658    int d;    int d;
1659    uschar *ce, *cs;    pcre_uchar *ce, *cs;
1660    register int op = *cc;    register int op = *cc;
1661    switch (op)    switch (op)
1662      {      {
# Line 1561  for (;;) Line 1670  for (;;)
1670      case OP_ONCE:      case OP_ONCE:
1671      case OP_ONCE_NC:      case OP_ONCE_NC:
1672      case OP_COND:      case OP_COND:
1673      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), utf8, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? IMM2_SIZE : 0), utf, atend, cd);
1674      if (d < 0) return d;      if (d < 0) return d;
1675      branchlength += d;      branchlength += d;
1676      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 1592  for (;;) Line 1701  for (;;)
1701    
1702      case OP_RECURSE:      case OP_RECURSE:
1703      if (!atend) return -3;      if (!atend) return -3;
1704      cs = ce = (uschar *)cd->start_code + GET(cc, 1);  /* Start subpattern */      cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
1705      do ce += GET(ce, 1); while (*ce == OP_ALT);       /* End subpattern */      do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */
1706      if (cc > cs && cc < ce) return -1;                /* Recursion */      if (cc > cs && cc < ce) return -1;                    /* Recursion */
1707      d = find_fixedlength(cs + 2, utf8, atend, cd);      d = find_fixedlength(cs + 2, utf, atend, cd);
1708      if (d < 0) return d;      if (d < 0) return d;
1709      branchlength += d;      branchlength += d;
1710      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
# Line 1616  for (;;) Line 1725  for (;;)
1725      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
1726      case OP_SKIP_ARG:      case OP_SKIP_ARG:
1727      case OP_THEN_ARG:      case OP_THEN_ARG:
1728      cc += cc[1] + _pcre_OP_lengths[*cc];      cc += cc[1] + PRIV(OP_lengths)[*cc];
1729      break;      break;
1730    
1731      case OP_CALLOUT:      case OP_CALLOUT:
# Line 1643  for (;;) Line 1752  for (;;)
1752      case OP_SOM:      case OP_SOM:
1753      case OP_THEN:      case OP_THEN:
1754      case OP_WORD_BOUNDARY:      case OP_WORD_BOUNDARY:
1755      cc += _pcre_OP_lengths[*cc];      cc += PRIV(OP_lengths)[*cc];
1756      break;      break;
1757    
1758      /* Handle literal characters */      /* Handle literal characters */
# Line 1654  for (;;) Line 1763  for (;;)
1763      case OP_NOTI:      case OP_NOTI:
1764      branchlength++;      branchlength++;
1765      cc += 2;      cc += 2;
1766  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1767      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1768  #endif  #endif
1769      break;      break;
1770    
# Line 1667  for (;;) Line 1776  for (;;)
1776      case OP_NOTEXACT:      case OP_NOTEXACT:
1777      case OP_NOTEXACTI:      case OP_NOTEXACTI:
1778      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1779      cc += 4;      cc += 2 + IMM2_SIZE;
1780  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1781      if (utf8 && cc[-1] >= 0xc0) cc += _pcre_utf8_table4[cc[-1] & 0x3f];      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
1782  #endif  #endif
1783      break;      break;
1784    
1785      case OP_TYPEEXACT:      case OP_TYPEEXACT:
1786      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1787      if (cc[3] == OP_PROP || cc[3] == OP_NOTPROP) cc += 2;      if (cc[1 + IMM2_SIZE] == OP_PROP || cc[1 + IMM2_SIZE] == OP_NOTPROP) cc += 2;
1788      cc += 4;      cc += 1 + IMM2_SIZE + 1;
1789      break;      break;
1790    
1791      /* Handle single-char matchers */      /* Handle single-char matchers */
# Line 1702  for (;;) Line 1811  for (;;)
1811      cc++;      cc++;
1812      break;      break;
1813    
1814      /* The single-byte matcher isn't allowed */      /* The single-byte matcher isn't allowed. This only happens in UTF-8 mode;
1815        otherwise \C is coded as OP_ALLANY. */
1816    
1817      case OP_ANYBYTE:      case OP_ANYBYTE:
1818      return -2;      return -2;
1819    
1820      /* Check a class for variable quantification */      /* Check a class for variable quantification */
1821    
1822  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || defined COMPILE_PCRE16
1823      case OP_XCLASS:      case OP_XCLASS:
1824      cc += GET(cc, 1) - 33;      cc += GET(cc, 1) - PRIV(OP_lengths)[OP_CLASS];
1825      /* Fall through */      /* Fall through */
1826  #endif  #endif
1827    
1828      case OP_CLASS:      case OP_CLASS:
1829      case OP_NCLASS:      case OP_NCLASS:
1830      cc += 33;      cc += PRIV(OP_lengths)[OP_CLASS];
1831    
1832      switch (*cc)      switch (*cc)
1833        {        {
# Line 1731  for (;;) Line 1841  for (;;)
1841    
1842        case OP_CRRANGE:        case OP_CRRANGE:
1843        case OP_CRMINRANGE:        case OP_CRMINRANGE:
1844        if (GET2(cc,1) != GET2(cc,3)) return -1;        if (GET2(cc,1) != GET2(cc,1+IMM2_SIZE)) return -1;
1845        branchlength += GET2(cc,1);        branchlength += GET2(cc,1);
1846        cc += 5;        cc += 1 + 2 * IMM2_SIZE;
1847        break;        break;
1848    
1849        default:        default:
# Line 1848  length. Line 1958  length.
1958    
1959  Arguments:  Arguments:
1960    code        points to start of expression    code        points to start of expression
1961    utf8        TRUE in UTF-8 mode    utf         TRUE in UTF-8 / UTF-16 mode
1962    number      the required bracket number or negative to find a lookbehind    number      the required bracket number or negative to find a lookbehind
1963    
1964  Returns:      pointer to the opcode for the bracket, or NULL if not found  Returns:      pointer to the opcode for the bracket, or NULL if not found
1965  */  */
1966    
1967  const uschar *  const pcre_uchar *
1968  _pcre_find_bracket(const uschar *code, BOOL utf8, int number)  PRIV(find_bracket)(const pcre_uchar *code, BOOL utf, int number)
1969  {  {
1970  for (;;)  for (;;)
1971    {    {
# Line 1873  for (;;) Line 1983  for (;;)
1983    
1984    else if (c == OP_REVERSE)    else if (c == OP_REVERSE)
1985      {      {
1986      if (number < 0) return (uschar *)code;      if (number < 0) return (pcre_uchar *)code;
1987      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
1988      }      }
1989    
1990    /* Handle capturing bracket */    /* Handle capturing bracket */
# Line 1883  for (;;) Line 1993  for (;;)
1993             c == OP_CBRAPOS || c == OP_SCBRAPOS)             c == OP_CBRAPOS || c == OP_SCBRAPOS)
1994      {      {
1995      int n = GET2(code, 1+LINK_SIZE);      int n = GET2(code, 1+LINK_SIZE);
1996      if (n == number) return (uschar *)code;      if (n == number) return (pcre_uchar *)code;
1997      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
1998      }      }
1999    
2000    /* Otherwise, we can get the item's length from the table, except that for    /* Otherwise, we can get the item's length from the table, except that for
# Line 1912  for (;;) Line 2022  for (;;)
2022        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2023        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2024        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
2025        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[1 + IMM2_SIZE] == OP_PROP
2026            || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;
2027        break;        break;
2028    
2029        case OP_MARK:        case OP_MARK:
# Line 1928  for (;;) Line 2039  for (;;)
2039    
2040      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
2041    
2042      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
2043    
2044    /* In UTF-8 mode, opcodes that are followed by a character may be followed by    /* In UTF-8 mode, opcodes that are followed by a character may be followed by
2045    a multi-byte character. The length in the table is a minimum, so we have to    a multi-byte character. The length in the table is a minimum, so we have to
2046    arrange to skip the extra bytes. */    arrange to skip the extra bytes. */
2047    
2048  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2049      if (utf8) switch(c)      if (utf) switch(c)
2050        {        {
2051        case OP_CHAR:        case OP_CHAR:
2052        case OP_CHARI:        case OP_CHARI:
# Line 1965  for (;;) Line 2076  for (;;)
2076        case OP_MINQUERYI:        case OP_MINQUERYI:
2077        case OP_POSQUERY:        case OP_POSQUERY:
2078        case OP_POSQUERYI:        case OP_POSQUERYI:
2079        if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];        if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);
2080        break;        break;
2081        }        }
2082  #else  #else
2083      (void)(utf8);  /* Keep compiler happy by referencing function argument */      (void)(utf);  /* Keep compiler happy by referencing function argument */
2084  #endif  #endif
2085      }      }
2086    }    }
# Line 1986  instance of OP_RECURSE. Line 2097  instance of OP_RECURSE.
2097    
2098  Arguments:  Arguments:
2099    code        points to start of expression    code        points to start of expression
2100    utf8        TRUE in UTF-8 mode    utf         TRUE in UTF-8 / UTF-16 mode
2101    
2102  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found  Returns:      pointer to the opcode for OP_RECURSE, or NULL if not found
2103  */  */
2104    
2105  static const uschar *  static const pcre_uchar *
2106  find_recurse(const uschar *code, BOOL utf8)  find_recurse(const pcre_uchar *code, BOOL utf)
2107  {  {
2108  for (;;)  for (;;)
2109    {    {
# Line 2031  for (;;) Line 2142  for (;;)
2142        case OP_TYPEUPTO:        case OP_TYPEUPTO:
2143        case OP_TYPEMINUPTO:        case OP_TYPEMINUPTO:
2144        case OP_TYPEEXACT:        case OP_TYPEEXACT:
2145        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[1 + IMM2_SIZE] == OP_PROP
2146            || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;
2147        break;        break;
2148    
2149        case OP_MARK:        case OP_MARK:
# Line 2047  for (;;) Line 2159  for (;;)
2159    
2160      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
2161    
2162      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
2163    
2164      /* In UTF-8 mode, opcodes that are followed by a character may be followed      /* In UTF-8 mode, opcodes that are followed by a character may be followed
2165      by a multi-byte character. The length in the table is a minimum, so we have      by a multi-byte character. The length in the table is a minimum, so we have
2166      to arrange to skip the extra bytes. */      to arrange to skip the extra bytes. */
2167    
2168  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2169      if (utf8) switch(c)      if (utf) switch(c)
2170        {        {
2171        case OP_CHAR:        case OP_CHAR:
2172        case OP_CHARI:        case OP_CHARI:
# Line 2084  for (;;) Line 2196  for (;;)
2196        case OP_MINQUERYI:        case OP_MINQUERYI:
2197        case OP_POSQUERY:        case OP_POSQUERY:
2198        case OP_POSQUERYI:        case OP_POSQUERYI:
2199        if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];        if (HAS_EXTRALEN(code[-1])) code += GET_EXTRALEN(code[-1]);
2200        break;        break;
2201        }        }
2202  #else  #else
2203      (void)(utf8);  /* Keep compiler happy by referencing function argument */      (void)(utf);  /* Keep compiler happy by referencing function argument */
2204  #endif  #endif
2205      }      }
2206    }    }
# Line 2111  bracket whose current branch will alread Line 2223  bracket whose current branch will alread
2223  Arguments:  Arguments:
2224    code        points to start of search    code        points to start of search
2225    endcode     points to where to stop    endcode     points to where to stop
2226    utf8        TRUE if in UTF8 mode    utf         TRUE if in UTF-8 / UTF-16 mode
2227    cd          contains pointers to tables etc.    cd          contains pointers to tables etc.
2228    
2229  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2230  */  */
2231    
2232  static BOOL  static BOOL
2233  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2234    compile_data *cd)    BOOL utf, compile_data *cd)
2235  {  {
2236  register int c;  register int c;
2237  for (code = first_significant_code(code + _pcre_OP_lengths[*code], TRUE);  for (code = first_significant_code(code + PRIV(OP_lengths)[*code], TRUE);
2238       code < endcode;       code < endcode;
2239       code = first_significant_code(code + _pcre_OP_lengths[c], TRUE))       code = first_significant_code(code + PRIV(OP_lengths)[c], TRUE))
2240    {    {
2241    const uschar *ccode;    const pcre_uchar *ccode;
2242    
2243    c = *code;    c = *code;
2244    
# Line 2149  for (code = first_significant_code(code Line 2261  for (code = first_significant_code(code
2261    
2262    if (c == OP_RECURSE)    if (c == OP_RECURSE)
2263      {      {
2264      const uschar *scode;      const pcre_uchar *scode;
2265      BOOL empty_branch;      BOOL empty_branch;
2266    
2267      /* Test for forward reference */      /* Test for forward reference */
# Line 2167  for (code = first_significant_code(code Line 2279  for (code = first_significant_code(code
2279    
2280      do      do
2281        {        {
2282        if (could_be_empty_branch(scode, endcode, utf8, cd))        if (could_be_empty_branch(scode, endcode, utf, cd))
2283          {          {
2284          empty_branch = TRUE;          empty_branch = TRUE;
2285          break;          break;
# Line 2185  for (code = first_significant_code(code Line 2297  for (code = first_significant_code(code
2297    if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO ||    if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO ||
2298        c == OP_BRAPOSZERO)        c == OP_BRAPOSZERO)
2299      {      {
2300      code += _pcre_OP_lengths[c];      code += PRIV(OP_lengths)[c];
2301      do code += GET(code, 1); while (*code == OP_ALT);      do code += GET(code, 1); while (*code == OP_ALT);
2302      c = *code;      c = *code;
2303      continue;      continue;
# Line 2223  for (code = first_significant_code(code Line 2335  for (code = first_significant_code(code
2335        empty_branch = FALSE;        empty_branch = FALSE;
2336        do        do
2337          {          {
2338          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd))
2339            empty_branch = TRUE;            empty_branch = TRUE;
2340          code += GET(code, 1);          code += GET(code, 1);
2341          }          }
# Line 2241  for (code = first_significant_code(code Line 2353  for (code = first_significant_code(code
2353      {      {
2354      /* Check for quantifiers after a class. XCLASS is used for classes that      /* Check for quantifiers after a class. XCLASS is used for classes that
2355      cannot be represented just by a bit map. This includes negated single      cannot be represented just by a bit map. This includes negated single
2356      high-valued characters. The length in _pcre_OP_lengths[] is zero; the      high-valued characters. The length in PRIV(OP_lengths)[] is zero; the
2357      actual length is stored in the compiled code, so we must update "code"      actual length is stored in the compiled code, so we must update "code"
2358      here. */      here. */
2359    
# Line 2253  for (code = first_significant_code(code Line 2365  for (code = first_significant_code(code
2365    
2366      case OP_CLASS:      case OP_CLASS:
2367      case OP_NCLASS:      case OP_NCLASS:
2368      ccode = code + 33;      ccode = code + PRIV(OP_lengths)[OP_CLASS];
2369    
2370  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2371      CHECK_CLASS_REPEAT:      CHECK_CLASS_REPEAT:
# Line 2328  for (code = first_significant_code(code Line 2440  for (code = first_significant_code(code
2440      case OP_TYPEUPTO:      case OP_TYPEUPTO:
2441      case OP_TYPEMINUPTO:      case OP_TYPEMINUPTO:
2442      case OP_TYPEPOSUPTO:      case OP_TYPEPOSUPTO:
2443      if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;      if (code[1 + IMM2_SIZE] == OP_PROP
2444          || code[1 + IMM2_SIZE] == OP_NOTPROP) code += 2;
2445      break;      break;
2446    
2447      /* End of branch */      /* End of branch */
# Line 2343  for (code = first_significant_code(code Line 2456  for (code = first_significant_code(code
2456      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,      /* In UTF-8 mode, STAR, MINSTAR, POSSTAR, QUERY, MINQUERY, POSQUERY, UPTO,
2457      MINUPTO, and POSUPTO may be followed by a multibyte character */      MINUPTO, and POSUPTO may be followed by a multibyte character */
2458    
2459  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2460      case OP_STAR:      case OP_STAR:
2461      case OP_STARI:      case OP_STARI:
2462      case OP_MINSTAR:      case OP_MINSTAR:
# Line 2356  for (code = first_significant_code(code Line 2469  for (code = first_significant_code(code
2469      case OP_MINQUERYI:      case OP_MINQUERYI:
2470      case OP_POSQUERY:      case OP_POSQUERY:
2471      case OP_POSQUERYI:      case OP_POSQUERYI:
2472      if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];      if (utf && HAS_EXTRALEN(code[1])) code += GET_EXTRALEN(code[1]);
2473      break;      break;
2474    
2475      case OP_UPTO:      case OP_UPTO:
# Line 2365  for (code = first_significant_code(code Line 2478  for (code = first_significant_code(code
2478      case OP_MINUPTOI:      case OP_MINUPTOI:
2479      case OP_POSUPTO:      case OP_POSUPTO:
2480      case OP_POSUPTOI:      case OP_POSUPTOI:
2481      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];      if (utf && HAS_EXTRALEN(code[1 + IMM2_SIZE])) code += GET_EXTRALEN(code[1 + IMM2_SIZE]);
2482      break;      break;
2483  #endif  #endif
2484    
# Line 2409  Arguments: Line 2522  Arguments:
2522    code        points to start of the recursion    code        points to start of the recursion
2523    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2524    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2525    utf8        TRUE if in UTF-8 mode    utf         TRUE if in UTF-8 / UTF-16 mode
2526    cd          pointers to tables etc    cd          pointers to tables etc
2527    
2528  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2529  */  */
2530    
2531  static BOOL  static BOOL
2532  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const pcre_uchar *code, const pcre_uchar *endcode,
2533    BOOL utf8, compile_data *cd)    branch_chain *bcptr, BOOL utf, compile_data *cd)
2534  {  {
2535  while (bcptr != NULL && bcptr->current_branch >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2536    {    {
2537    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf, cd))
2538      return FALSE;      return FALSE;
2539    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2540    }    }
# Line 2473  Returns:   TRUE or FALSE Line 2586  Returns:   TRUE or FALSE
2586  */  */
2587    
2588  static BOOL  static BOOL
2589  check_posix_syntax(const uschar *ptr, const uschar **endptr)  check_posix_syntax(const pcre_uchar *ptr, const pcre_uchar **endptr)
2590  {  {
2591  int terminator;          /* Don't combine these lines; the Solaris cc */  int terminator;          /* Don't combine these lines; the Solaris cc */
2592  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */  terminator = *(++ptr);   /* compiler warns about "non-constant" initializer. */
# Line 2517  Returns:     a value representing the na Line 2630  Returns:     a value representing the na
2630  */  */
2631    
2632  static int  static int
2633  check_posix_name(const uschar *ptr, int len)  check_posix_name(const pcre_uchar *ptr, int len)
2634  {  {
2635  const char *pn = posix_names;  const char *pn = posix_names;
2636  register int yield = 0;  register int yield = 0;
2637  while (posix_name_lengths[yield] != 0)  while (posix_name_lengths[yield] != 0)
2638    {    {
2639    if (len == posix_name_lengths[yield] &&    if (len == posix_name_lengths[yield] &&
2640      strncmp((const char *)ptr, pn, len) == 0) return yield;      STRNCMP_UC_C8(ptr, pn, len) == 0) return yield;
2641    pn += posix_name_lengths[yield] + 1;    pn += posix_name_lengths[yield] + 1;
2642    yield++;    yield++;
2643    }    }
# Line 2556  value in the reference (which is a group Line 2669  value in the reference (which is a group
2669  Arguments:  Arguments:
2670    group      points to the start of the group    group      points to the start of the group
2671    adjust     the amount by which the group is to be moved    adjust     the amount by which the group is to be moved
2672    utf8       TRUE in UTF-8 mode    utf        TRUE in UTF-8 / UTF-16 mode
2673    cd         contains pointers to tables etc.    cd         contains pointers to tables etc.
2674    save_hwm   the hwm forward reference pointer at the start of the group    save_hwm   the hwm forward reference pointer at the start of the group
2675    
# Line 2564  Returns:     nothing Line 2677  Returns:     nothing
2677  */  */
2678    
2679  static void  static void
2680  adjust_recurse(uschar *group, int adjust, BOOL utf8, compile_data *cd,  adjust_recurse(pcre_uchar *group, int adjust, BOOL utf, compile_data *cd,
2681    uschar *save_hwm)    pcre_uchar *save_hwm)
2682  {  {
2683  uschar *ptr = group;  pcre_uchar *ptr = group;
2684    
2685  while ((ptr = (uschar *)find_recurse(ptr, utf8)) != NULL)  while ((ptr = (pcre_uchar *)find_recurse(ptr, utf)) != NULL)
2686    {    {
2687    int offset;    int offset;
2688    uschar *hc;    pcre_uchar *hc;
2689    
2690    /* See if this recursion is on the forward reference list. If so, adjust the    /* See if this recursion is on the forward reference list. If so, adjust the
2691    reference. */    reference. */
# Line 2617  Arguments: Line 2730  Arguments:
2730  Returns:         new code pointer  Returns:         new code pointer
2731  */  */
2732    
2733  static uschar *  static pcre_uchar *
2734  auto_callout(uschar *code, const uschar *ptr, compile_data *cd)  auto_callout(pcre_uchar *code, const pcre_uchar *ptr, compile_data *cd)
2735  {  {
2736  *code++ = OP_CALLOUT;  *code++ = OP_CALLOUT;
2737  *code++ = 255;  *code++ = 255;
2738  PUT(code, 0, (int)(ptr - cd->start_pattern));  /* Pattern offset */  PUT(code, 0, (int)(ptr - cd->start_pattern));  /* Pattern offset */
2739  PUT(code, LINK_SIZE, 0);                       /* Default length */  PUT(code, LINK_SIZE, 0);                       /* Default length */
2740  return code + 2*LINK_SIZE;  return code + 2 * LINK_SIZE;
2741  }  }
2742    
2743    
# Line 2646  Returns:             nothing Line 2759  Returns:             nothing
2759  */  */
2760    
2761  static void  static void
2762  complete_callout(uschar *previous_callout, const uschar *ptr, compile_data *cd)  complete_callout(pcre_uchar *previous_callout, const pcre_uchar *ptr, compile_data *cd)
2763  {  {
2764  int length = (int)(ptr - cd->start_pattern - GET(previous_callout, 2));  int length = (int)(ptr - cd->start_pattern - GET(previous_callout, 2));
2765  PUT(previous_callout, 2 + LINK_SIZE, length);  PUT(previous_callout, 2 + LINK_SIZE, length);
# Line 2729  switch(ptype) Line 2842  switch(ptype)
2842            prop->chartype == ucp_Lt) == negated;            prop->chartype == ucp_Lt) == negated;
2843    
2844    case PT_GC:    case PT_GC:
2845    return (pdata == _pcre_ucp_gentype[prop->chartype]) == negated;    return (pdata == PRIV(ucp_gentype)[prop->chartype]) == negated;
2846    
2847    case PT_PC:    case PT_PC:
2848    return (pdata == prop->chartype) == negated;    return (pdata == prop->chartype) == negated;
# Line 2740  switch(ptype) Line 2853  switch(ptype)
2853    /* These are specials */    /* These are specials */
2854    
2855    case PT_ALNUM:    case PT_ALNUM:
2856    return (_pcre_ucp_gentype[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2857            _pcre_ucp_gentype[prop->chartype] == ucp_N) == negated;            PRIV(ucp_gentype)[prop->chartype] == ucp_N) == negated;
2858    
2859    case PT_SPACE:    /* Perl space */    case PT_SPACE:    /* Perl space */
2860    return (_pcre_ucp_gentype[prop->chartype] == ucp_Z ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2861            c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)            c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2862            == negated;            == negated;
2863    
2864    case PT_PXSPACE:  /* POSIX space */    case PT_PXSPACE:  /* POSIX space */
2865    return (_pcre_ucp_gentype[prop->chartype] == ucp_Z ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2866            c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||            c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2867            c == CHAR_FF || c == CHAR_CR)            c == CHAR_FF || c == CHAR_CR)
2868            == negated;            == negated;
2869    
2870    case PT_WORD:    case PT_WORD:
2871    return (_pcre_ucp_gentype[prop->chartype] == ucp_L ||    return (PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2872            _pcre_ucp_gentype[prop->chartype] == ucp_N ||            PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2873            c == CHAR_UNDERSCORE) == negated;            c == CHAR_UNDERSCORE) == negated;
2874    }    }
2875  return FALSE;  return FALSE;
# Line 2775  sense to automatically possessify the re Line 2888  sense to automatically possessify the re
2888    
2889  Arguments:  Arguments:
2890    previous      pointer to the repeated opcode    previous      pointer to the repeated opcode
2891    utf8          TRUE in UTF-8 mode    utf           TRUE in UTF-8 / UTF-16 mode
2892    ptr           next character in pattern    ptr           next character in pattern
2893    options       options bits    options       options bits
2894    cd            contains pointers to tables etc.    cd            contains pointers to tables etc.
# Line 2784  Returns:        TRUE if possessifying is Line 2897  Returns:        TRUE if possessifying is
2897  */  */
2898    
2899  static BOOL  static BOOL
2900  check_auto_possessive(const uschar *previous, BOOL utf8, const uschar *ptr,  check_auto_possessive(const pcre_uchar *previous, BOOL utf,
2901    int options, compile_data *cd)    const pcre_uchar *ptr, int options, compile_data *cd)
2902  {  {
2903  int c, next;  pcre_int32 c, next;
2904  int op_code = *previous++;  int op_code = *previous++;
2905    
2906  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
# Line 2804  if ((options & PCRE_EXTENDED) != 0) Line 2917  if ((options & PCRE_EXTENDED) != 0)
2917          {          {
2918          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2919          ptr++;          ptr++;
2920  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2921          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) FORWARDCHAR(ptr);
2922  #endif  #endif
2923          }          }
2924        }        }
# Line 2823  if (*ptr == CHAR_BACKSLASH) Line 2936  if (*ptr == CHAR_BACKSLASH)
2936    if (temperrorcode != 0) return FALSE;    if (temperrorcode != 0) return FALSE;
2937    ptr++;    /* Point after the escape sequence */    ptr++;    /* Point after the escape sequence */
2938    }    }
2939    else if (!MAX_255(*ptr) || (cd->ctypes[*ptr] & ctype_meta) == 0)
 else if ((cd->ctypes[*ptr] & ctype_meta) == 0)  
2940    {    {
2941  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2942    if (utf8) { GETCHARINC(next, ptr); } else    if (utf) { GETCHARINC(next, ptr); } else
2943  #endif  #endif
2944    next = *ptr++;    next = *ptr++;
2945    }    }
   
2946  else return FALSE;  else return FALSE;
2947    
2948  /* Skip whitespace and comments in extended mode */  /* Skip whitespace and comments in extended mode */
# Line 2848  if ((options & PCRE_EXTENDED) != 0) Line 2959  if ((options & PCRE_EXTENDED) != 0)
2959          {          {
2960          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen; break; }
2961          ptr++;          ptr++;
2962  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2963          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) FORWARDCHAR(ptr);
2964  #endif  #endif
2965          }          }
2966        }        }
# Line 2860  if ((options & PCRE_EXTENDED) != 0) Line 2971  if ((options & PCRE_EXTENDED) != 0)
2971  /* If the next thing is itself optional, we have to give up. */  /* If the next thing is itself optional, we have to give up. */
2972    
2973  if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||  if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
2974    strncmp((char *)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)
2975      return FALSE;      return FALSE;
2976    
2977  /* Now compare the next item with the previous opcode. First, handle cases when  /* Now compare the next item with the previous opcode. First, handle cases when
# Line 2888  if (next >= 0) switch(op_code) Line 2999  if (next >= 0) switch(op_code)
2999  #endif  #endif
3000    if (c == next) return FALSE;    if (c == next) return FALSE;
3001  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3002    if (utf8)    if (utf)
3003      {      {
3004      unsigned int othercase;      unsigned int othercase;
3005      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 2913  if (next >= 0) switch(op_code) Line 3024  if (next >= 0) switch(op_code)
3024    case OP_NOTI:    case OP_NOTI:
3025    if ((c = *previous) == next) return TRUE;    if ((c = *previous) == next) return TRUE;
3026  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3027    if (utf8)    if (utf)
3028      {      {
3029      unsigned int othercase;      unsigned int othercase;
3030      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 3122  switch(op_code) Line 3233  switch(op_code)
3233        to the original \d etc. At this point, ptr will point to a zero byte. */        to the original \d etc. At this point, ptr will point to a zero byte. */
3234    
3235        if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||        if (*ptr == CHAR_ASTERISK || *ptr == CHAR_QUESTION_MARK ||
3236          strncmp((char *)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)
3237            return FALSE;            return FALSE;
3238    
3239        /* Do the property check. */        /* Do the property check. */
# Line 3200  Arguments: Line 3311  Arguments:
3311    codeptr        points to the pointer to the current code point    codeptr        points to the pointer to the current code point
3312    ptrptr         points to the current pattern pointer    ptrptr         points to the current pattern pointer
3313    errorcodeptr   points to error code variable    errorcodeptr   points to error code variable
3314    firstbyteptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)    firstcharptr   set to initial literal character, or < 0 (REQ_UNSET, REQ_NONE)
3315    reqbyteptr     set to the last literal character required, else < 0    reqcharptr     set to the last literal character required, else < 0
3316    bcptr          points to current branch chain    bcptr          points to current branch chain
3317    cond_depth     conditional nesting depth    cond_depth     conditional nesting depth
3318    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
# Line 3213  Returns:         TRUE on success Line 3324  Returns:         TRUE on success
3324  */  */
3325    
3326  static BOOL  static BOOL
3327  compile_branch(int *optionsptr, uschar **codeptr, const uschar **ptrptr,  compile_branch(int *optionsptr, pcre_uchar **codeptr,
3328    int *errorcodeptr, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr,    const pcre_uchar **ptrptr, int *errorcodeptr, pcre_int32 *firstcharptr,
3329    int cond_depth, compile_data *cd, int *lengthptr)    pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,
3330      compile_data *cd, int *lengthptr)
3331  {  {
3332  int repeat_type, op_type;  int repeat_type, op_type;
3333  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3334  int bravalue = 0;  int bravalue = 0;
3335  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3336  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
3337  int zeroreqbyte, zerofirstbyte;  pcre_int32 zeroreqchar, zerofirstchar;
3338  int req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3339  int options = *optionsptr;               /* May change dynamically */  int options = *optionsptr;               /* May change dynamically */
3340  int after_manual_callout = 0;  int after_manual_callout = 0;
3341  int length_prevgroup = 0;  int length_prevgroup = 0;
3342  register int c;  register int c;
3343  register uschar *code = *codeptr;  register pcre_uchar *code = *codeptr;
3344  uschar *last_code = code;  pcre_uchar *last_code = code;
3345  uschar *orig_code = code;  pcre_uchar *orig_code = code;
3346  uschar *tempcode;  pcre_uchar *tempcode;
3347  BOOL inescq = FALSE;  BOOL inescq = FALSE;
3348  BOOL groupsetfirstbyte = FALSE;  BOOL groupsetfirstchar = FALSE;
3349  const uschar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
3350  const uschar *tempptr;  const pcre_uchar *tempptr;
3351  const uschar *nestptr = NULL;  const pcre_uchar *nestptr = NULL;
3352  uschar *previous = NULL;  pcre_uchar *previous = NULL;
3353  uschar *previous_callout = NULL;  pcre_uchar *previous_callout = NULL;
3354  uschar *save_hwm = NULL;  pcre_uchar *save_hwm = NULL;
3355  uschar classbits[32];  pcre_uint8 classbits[32];
3356    
3357  /* We can fish out the UTF-8 setting once and for all into a BOOL, but we  /* We can fish out the UTF-8 setting once and for all into a BOOL, but we
3358  must not do this for other options (e.g. PCRE_EXTENDED) because they may change  must not do this for other options (e.g. PCRE_EXTENDED) because they may change
3359  dynamically as we process the pattern. */  dynamically as we process the pattern. */
3360    
3361  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3362  BOOL class_utf8;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
3363  BOOL utf8 = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
3364  uschar *class_utf8data;  pcre_uchar utf_chars[6];
 uschar *class_utf8data_base;  
 uschar utf8_char[6];  
3365  #else  #else
3366  BOOL utf8 = FALSE;  BOOL utf = FALSE;
3367    #endif
3368    
3369    /* Helper variables for OP_XCLASS opcode (for characters > 255). */
3370    
3371    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3372    BOOL xclass;
3373    pcre_uchar *class_uchardata;
3374    pcre_uchar *class_uchardata_base;
3375  #endif  #endif
3376    
3377  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
# Line 3267  greedy_non_default = greedy_default ^ 1; Line 3385  greedy_non_default = greedy_default ^ 1;
3385    
3386  /* Initialize no first byte, no required byte. REQ_UNSET means "no char  /* Initialize no first byte, no required byte. REQ_UNSET means "no char
3387  matching encountered yet". It gets changed to REQ_NONE if we hit something that  matching encountered yet". It gets changed to REQ_NONE if we hit something that
3388  matches a non-fixed char first char; reqbyte just remains unset if we never  matches a non-fixed char first char; reqchar just remains unset if we never
3389  find one.  find one.
3390    
3391  When we hit a repeat whose minimum is zero, we may have to adjust these values  When we hit a repeat whose minimum is zero, we may have to adjust these values
3392  to take the zero repeat into account. This is implemented by setting them to  to take the zero repeat into account. This is implemented by setting them to
3393  zerofirstbyte and zeroreqbyte when such a repeat is encountered. The individual  zerofirstbyte and zeroreqchar when such a repeat is encountered. The individual
3394  item types that can be repeated set these backoff variables appropriately. */  item types that can be repeated set these backoff variables appropriately. */
3395    
3396  firstbyte = reqbyte = zerofirstbyte = zeroreqbyte = REQ_UNSET;  firstchar = reqchar = zerofirstchar = zeroreqchar = REQ_UNSET;
3397    
3398  /* The variable req_caseopt contains either the REQ_CASELESS value or zero,  /* The variable req_caseopt contains either the REQ_CASELESS value
3399  according to the current setting of the caseless flag. REQ_CASELESS is a bit  or zero, according to the current setting of the caseless flag. The
3400  value > 255. It is added into the firstbyte or reqbyte variables to record the  REQ_CASELESS leaves the lower 28 bit empty. It is added into the
3401  case status of the value. This is used only for ASCII characters. */  firstchar or reqchar variables to record the case status of the
3402    value. This is used only for ASCII characters. */
3403    
3404  req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;  req_caseopt = ((options & PCRE_CASELESS) != 0)? REQ_CASELESS:0;
3405    
3406  /* Switch on next character until the end of the branch */  /* Switch on next character until the end of the branch */
3407    
# Line 3300  for (;; ptr++) Line 3419  for (;; ptr++)
3419    int recno;    int recno;
3420    int refsign;    int refsign;
3421    int skipbytes;    int skipbytes;
3422    int subreqbyte;    int subreqchar;
3423    int subfirstbyte;    int subfirstchar;
3424    int terminator;    int terminator;
3425    int mclength;    int mclength;
3426    int tempbracount;    int tempbracount;
3427    uschar mcbuffer[8];    pcre_uchar mcbuffer[8];
3428    
3429    /* Get next byte in the pattern */    /* Get next character in the pattern */
3430    
3431    c = *ptr;    c = *ptr;
3432    
# Line 3352  for (;; ptr++) Line 3471  for (;; ptr++)
3471        }        }
3472    
3473      *lengthptr += (int)(code - last_code);      *lengthptr += (int)(code - last_code);
3474      DPRINTF(("length=%d added %d c=%c\n", *lengthptr, code - last_code, c));      DPRINTF(("length=%d added %d c=%c (0x%x)\n", *lengthptr,
3475          (int)(code - last_code), c, c));
3476    
3477      /* If "previous" is set and it is not at the start of the work space, move      /* If "previous" is set and it is not at the start of the work space, move
3478      it back to there, in order to avoid filling up the work space. Otherwise,      it back to there, in order to avoid filling up the work space. Otherwise,
# Line 3362  for (;; ptr++) Line 3482  for (;; ptr++)
3482        {        {
3483        if (previous > orig_code)        if (previous > orig_code)
3484          {          {
3485          memmove(orig_code, previous, code - previous);          memmove(orig_code, previous, IN_UCHARS(code - previous));
3486          code -= previous - orig_code;          code -= previous - orig_code;
3487          previous = orig_code;          previous = orig_code;
3488          }          }
# Line 3438  for (;; ptr++) Line 3558  for (;; ptr++)
3558          {          {
3559          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }          if (IS_NEWLINE(ptr)) { ptr += cd->nllen - 1; break; }
3560          ptr++;          ptr++;
3561  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3562          if (utf8) while ((*ptr & 0xc0) == 0x80) ptr++;          if (utf) FORWARDCHAR(ptr);
3563  #endif  #endif
3564          }          }
3565        if (*ptr != 0) continue;        if (*ptr != 0) continue;
# Line 3463  for (;; ptr++) Line 3583  for (;; ptr++)
3583      case 0:                        /* The branch terminates at string end */      case 0:                        /* The branch terminates at string end */
3584      case CHAR_VERTICAL_LINE:       /* or | or ) */      case CHAR_VERTICAL_LINE:       /* or | or ) */
3585      case CHAR_RIGHT_PARENTHESIS:      case CHAR_RIGHT_PARENTHESIS:
3586      *firstbyteptr = firstbyte;      *firstcharptr = firstchar;
3587      *reqbyteptr = reqbyte;      *reqcharptr = reqchar;
3588      *codeptr = code;      *codeptr = code;
3589      *ptrptr = ptr;      *ptrptr = ptr;
3590      if (lengthptr != NULL)      if (lengthptr != NULL)
# Line 3488  for (;; ptr++) Line 3608  for (;; ptr++)
3608      previous = NULL;      previous = NULL;
3609      if ((options & PCRE_MULTILINE) != 0)      if ((options & PCRE_MULTILINE) != 0)
3610        {        {
3611        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3612        *code++ = OP_CIRCM;        *code++ = OP_CIRCM;
3613        }        }
3614      else *code++ = OP_CIRC;      else *code++ = OP_CIRC;
# Line 3500  for (;; ptr++) Line 3620  for (;; ptr++)
3620      break;      break;
3621    
3622      /* There can never be a first char if '.' is first, whatever happens about      /* There can never be a first char if '.' is first, whatever happens about
3623      repeats. The value of reqbyte doesn't change either. */      repeats. The value of reqchar doesn't change either. */
3624    
3625      case CHAR_DOT:      case CHAR_DOT:
3626      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3627      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
3628      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
3629      previous = code;      previous = code;
3630      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;      *code++ = ((options & PCRE_DOTALL) != 0)? OP_ALLANY: OP_ANY;
3631      break;      break;
# Line 3560  for (;; ptr++) Line 3680  for (;; ptr++)
3680          {          {
3681          if (ptr[1] == CHAR_E)          if (ptr[1] == CHAR_E)
3682            ptr++;            ptr++;
3683          else if (strncmp((const char *)ptr+1,          else if (STRNCMP_UC_C8(ptr + 1, STR_Q STR_BACKSLASH STR_E, 3) == 0)
                           STR_Q STR_BACKSLASH STR_E, 3) == 0)  
3684            ptr += 3;            ptr += 3;
3685          else          else
3686            break;            break;
# Line 3580  for (;; ptr++) Line 3699  for (;; ptr++)
3699          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)          (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
3700        {        {
3701        *code++ = negate_class? OP_ALLANY : OP_FAIL;        *code++ = negate_class? OP_ALLANY : OP_FAIL;
3702        if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;        if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
3703        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
3704        break;        break;
3705        }        }
3706    
# Line 3603  for (;; ptr++) Line 3722  for (;; ptr++)
3722      than 256), because in that case the compiled code doesn't use the bit map.      than 256), because in that case the compiled code doesn't use the bit map.
3723      */      */
3724    
3725      memset(classbits, 0, 32 * sizeof(uschar));      memset(classbits, 0, 32 * sizeof(pcre_uint8));
3726    
3727  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3728      class_utf8 = FALSE;                       /* No chars >= 256 */      xclass = FALSE;                           /* No chars >= 256 */
3729      class_utf8data = code + LINK_SIZE + 2;    /* For UTF-8 items */      class_uchardata = code + LINK_SIZE + 2;   /* For UTF-8 items */
3730      class_utf8data_base = class_utf8data;     /* For resetting in pass 1 */      class_uchardata_base = class_uchardata;   /* For resetting in pass 1 */
3731  #endif  #endif
3732    
3733      /* Process characters until ] is reached. By writing this as a "do" it      /* Process characters until ] is reached. By writing this as a "do" it
# Line 3617  for (;; ptr++) Line 3736  for (;; ptr++)
3736    
3737      if (c != 0) do      if (c != 0) do
3738        {        {
3739        const uschar *oldptr;        const pcre_uchar *oldptr;
3740    
3741  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
3742        if (utf8 && c > 127)        if (utf && c > 127)
3743          {                           /* Braces are required because the */          {                           /* Braces are required because the */
3744          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
3745          }          }
3746    #endif
3747    
3748        /* In the pre-compile phase, accumulate the length of any UTF-8 extra  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3749          /* In the pre-compile phase, accumulate the length of any extra
3750        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
3751        contain a zillion UTF-8 characters no longer overwrite the work space        contain a zillion > 255 characters no longer overwrite the work space
3752        (which is on the stack). */        (which is on the stack). */
3753    
3754        if (lengthptr != NULL)        if (lengthptr != NULL)
3755          {          {
3756          *lengthptr += class_utf8data - class_utf8data_base;          *lengthptr += class_uchardata - class_uchardata_base;
3757          class_utf8data = class_utf8data_base;          class_uchardata = class_uchardata_base;
3758          }          }
   
3759  #endif  #endif
3760    
3761        /* Inside \Q...\E everything is literal except \E */        /* Inside \Q...\E everything is literal except \E */
# Line 3663  for (;; ptr++) Line 3783  for (;; ptr++)
3783          {          {
3784          BOOL local_negate = FALSE;          BOOL local_negate = FALSE;
3785          int posix_class, taboffset, tabopt;          int posix_class, taboffset, tabopt;
3786          register const uschar *cbits = cd->cbits;          register const pcre_uint8 *cbits = cd->cbits;
3787          uschar pbits[32];          pcre_uint8 pbits[32];
3788    
3789          if (ptr[1] != CHAR_COLON)          if (ptr[1] != CHAR_COLON)
3790            {            {
# Line 3719  for (;; ptr++) Line 3839  for (;; ptr++)
3839          /* Copy in the first table (always present) */          /* Copy in the first table (always present) */
3840    
3841          memcpy(pbits, cbits + posix_class_maps[posix_class],          memcpy(pbits, cbits + posix_class_maps[posix_class],
3842            32 * sizeof(uschar));            32 * sizeof(pcre_uint8));
3843    
3844          /* If there is a second table, add or remove it as required. */          /* If there is a second table, add or remove it as required. */
3845    
# Line 3781  for (;; ptr++) Line 3901  for (;; ptr++)
3901    
3902          if (c < 0)          if (c < 0)
3903            {            {
3904            register const uschar *cbits = cd->cbits;            register const pcre_uint8 *cbits = cd->cbits;
3905            class_charcount += 2;     /* Greater than 1 is what matters */            class_charcount += 2;     /* Greater than 1 is what matters */
3906    
3907            switch (-c)            switch (-c)
# Line 3836  for (;; ptr++) Line 3956  for (;; ptr++)
3956              SETBIT(classbits, 0x09); /* VT */              SETBIT(classbits, 0x09); /* VT */
3957              SETBIT(classbits, 0x20); /* SPACE */              SETBIT(classbits, 0x20); /* SPACE */
3958              SETBIT(classbits, 0xa0); /* NSBP */              SETBIT(classbits, 0xa0); /* NSBP */
3959  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3960              if (utf8)              if (utf)
3961                {                {
3962                class_utf8 = TRUE;                xclass = TRUE;
3963                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3964                class_utf8data += _pcre_ord2utf8(0x1680, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x1680, class_uchardata);
3965                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3966                class_utf8data += _pcre_ord2utf8(0x180e, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x180e, class_uchardata);
3967                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
3968                class_utf8data += _pcre_ord2utf8(0x2000, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2000, class_uchardata);
3969                class_utf8data += _pcre_ord2utf8(0x200A, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x200A, class_uchardata);
3970                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3971                class_utf8data += _pcre_ord2utf8(0x202f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x202f, class_uchardata);
3972                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3973                class_utf8data += _pcre_ord2utf8(0x205f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x205f, class_uchardata);
3974                *class_utf8data++ = XCL_SINGLE;                *class_uchardata++ = XCL_SINGLE;
3975                class_utf8data += _pcre_ord2utf8(0x3000, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x3000, class_uchardata);
3976                }                }
3977  #endif  #endif
3978              continue;              continue;
# Line 3871  for (;; ptr++) Line 3991  for (;; ptr++)
3991                classbits[c] |= x;                classbits[c] |= x;
3992                }                }
3993    
3994  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3995              if (utf8)              if (utf)
3996                {                {
3997                class_utf8 = TRUE;                xclass = TRUE;
3998                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
3999                class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);
4000                class_utf8data += _pcre_ord2utf8(0x167f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x167f, class_uchardata);
4001                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4002                class_utf8data += _pcre_ord2utf8(0x1681, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x1681, class_uchardata);
4003                class_utf8data += _pcre_ord2utf8(0x180d, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x180d, class_uchardata);
4004                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4005                class_utf8data += _pcre_ord2utf8(0x180f, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x180f, class_uchardata);
4006                class_utf8data += _pcre_ord2utf8(0x1fff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x1fff, class_uchardata);
4007                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4008                class_utf8data += _pcre_ord2utf8(0x200B, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x200B, class_uchardata);
4009                class_utf8data += _pcre_ord2utf8(0x202e, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x202e, class_uchardata);
4010                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4011                class_utf8data += _pcre_ord2utf8(0x2030, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2030, class_uchardata);
4012                class_utf8data += _pcre_ord2utf8(0x205e, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x205e, class_uchardata);
4013                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4014                class_utf8data += _pcre_ord2utf8(0x2060, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2060, class_uchardata);
4015                class_utf8data += _pcre_ord2utf8(0x2fff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2fff, class_uchardata);
4016                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4017                class_utf8data += _pcre_ord2utf8(0x3001, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x3001, class_uchardata);
4018                class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4019                }                }
4020  #endif  #endif
4021              continue;              continue;
# Line 3906  for (;; ptr++) Line 4026  for (;; ptr++)
4026              SETBIT(classbits, 0x0c); /* FF */              SETBIT(classbits, 0x0c); /* FF */
4027              SETBIT(classbits, 0x0d); /* CR */              SETBIT(classbits, 0x0d); /* CR */
4028              SETBIT(classbits, 0x85); /* NEL */              SETBIT(classbits, 0x85); /* NEL */
4029  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4030              if (utf8)              if (utf)
4031                {                {
4032                class_utf8 = TRUE;                xclass = TRUE;
4033                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4034                class_utf8data += _pcre_ord2utf8(0x2028, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2028, class_uchardata);
4035                class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4036                }                }
4037  #endif  #endif
4038              continue;              continue;
# Line 3934  for (;; ptr++) Line 4054  for (;; ptr++)
4054                classbits[c] |= x;                classbits[c] |= x;
4055                }                }
4056    
4057  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4058              if (utf8)              if (utf)
4059                {                {
4060                class_utf8 = TRUE;                xclass = TRUE;
4061                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4062                class_utf8data += _pcre_ord2utf8(0x0100, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x0100, class_uchardata);
4063                class_utf8data += _pcre_ord2utf8(0x2027, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2027, class_uchardata);
4064                *class_utf8data++ = XCL_RANGE;                *class_uchardata++ = XCL_RANGE;
4065                class_utf8data += _pcre_ord2utf8(0x2029, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x2029, class_uchardata);
4066                class_utf8data += _pcre_ord2utf8(0x7fffffff, class_utf8data);                class_uchardata += PRIV(ord2utf)(0x10ffff, class_uchardata);
4067                }                }
4068  #endif  #endif
4069              continue;              continue;
# Line 3956  for (;; ptr++) Line 4076  for (;; ptr++)
4076                int pdata;                int pdata;
4077                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);                int ptype = get_ucp(&ptr, &negated, &pdata, errorcodeptr);
4078                if (ptype < 0) goto FAILED;                if (ptype < 0) goto FAILED;
4079                class_utf8 = TRUE;                xclass = TRUE;
4080                *class_utf8data++ = ((-c == ESC_p) != negated)?                *class_uchardata++ = ((-c == ESC_p) != negated)?
4081                  XCL_PROP : XCL_NOTPROP;                  XCL_PROP : XCL_NOTPROP;
4082                *class_utf8data++ = ptype;                *class_uchardata++ = ptype;
4083                *class_utf8data++ = pdata;                *class_uchardata++ = pdata;
4084                class_charcount -= 2;   /* Not a < 256 character */                class_charcount -= 2;   /* Not a < 256 character */
4085                continue;                continue;
4086                }                }
# Line 3982  for (;; ptr++) Line 4102  for (;; ptr++)
4102            }            }
4103    
4104          /* Fall through if we have a single character (c >= 0). This may be          /* Fall through if we have a single character (c >= 0). This may be
4105          greater than 256 in UTF-8 mode. */          greater than 256 mode. */
4106    
4107          }   /* End of backslash handling */          }   /* End of backslash handling */
4108    
# Line 4031  for (;; ptr++) Line 4151  for (;; ptr++)
4151            }            }
4152    
4153  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4154          if (utf8)          if (utf)
4155            {                           /* Braces are required because the */            {                           /* Braces are required because the */
4156            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */
4157            }            }
# Line 4080  for (;; ptr++) Line 4200  for (;; ptr++)
4200          matching for characters > 127 is available only if UCP support is          matching for characters > 127 is available only if UCP support is
4201          available. */          available. */
4202    
4203  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4204          if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))          if (utf && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))
4205    #endif
4206    #ifndef COMPILE_PCRE8
4207            if (d > 255)
4208    #endif
4209    #if defined SUPPORT_UTF || defined COMPILE_PCRE16
4210            {            {
4211            class_utf8 = TRUE;            xclass = TRUE;
4212    
4213            /* With UCP support, we can find the other case equivalents of            /* With UCP support, we can find the other case equivalents of
4214            the relevant characters. There may be several ranges. Optimize how            the relevant characters. There may be several ranges. Optimize how
# Line 4116  for (;; ptr++) Line 4241  for (;; ptr++)
4241    
4242                if (occ == ocd)                if (occ == ocd)
4243                  {                  {
4244                  *class_utf8data++ = XCL_SINGLE;                  *class_uchardata++ = XCL_SINGLE;
4245                  }                  }
4246                else                else
4247                  {                  {
4248                  *class_utf8data++ = XCL_RANGE;                  *class_uchardata++ = XCL_RANGE;
4249                  class_utf8data += _pcre_ord2utf8(occ, class_utf8data);                  class_uchardata += PRIV(ord2utf)(occ, class_uchardata);
4250                  }                  }
4251                class_utf8data += _pcre_ord2utf8(ocd, class_utf8data);                class_uchardata += PRIV(ord2utf)(ocd, class_uchardata);
4252                }                }
4253              }              }
4254  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 4131  for (;; ptr++) Line 4256  for (;; ptr++)
4256            /* Now record the original range, possibly modified for UCP caseless            /* Now record the original range, possibly modified for UCP caseless
4257            overlapping ranges. */            overlapping ranges. */
4258    
4259            *class_utf8data++ = XCL_RANGE;            *class_uchardata++ = XCL_RANGE;
4260            class_utf8data += _pcre_ord2utf8(c, class_utf8data);  #ifdef SUPPORT_UTF
4261            class_utf8data += _pcre_ord2utf8(d, class_utf8data);            class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4262              class_uchardata += PRIV(ord2utf)(d, class_uchardata);
4263    #else
4264              *class_uchardata++ = c;
4265              *class_uchardata++ = d;
4266    #endif
4267    
4268            /* With UCP support, we are done. Without UCP support, there is no            /* With UCP support, we are done. Without UCP support, there is no
4269            caseless matching for UTF-8 characters > 127; we can use the bit map            caseless matching for UTF characters > 127; we can use the bit map
4270            for the smaller ones. */            for the smaller ones. As for 16 bit characters without UTF, we
4271              can still use  */
4272    
4273  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4274            continue;    /* With next character in the class */            continue;    /* With next character in the class */
4275  #else  #else
4276    #ifdef SUPPORT_UTF
4277            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;
   
4278            /* Adjust upper limit and fall through to set up the map */            /* Adjust upper limit and fall through to set up the map */
   
4279            d = 127;            d = 127;
4280    #else
4281              if (c > 255) continue;
4282              /* Adjust upper limit and fall through to set up the map */
4283              d = 255;
4284    #endif  /* SUPPORT_UTF */
4285  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
4286            }            }
4287  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 || COMPILE_PCRE16 */
4288    
4289          /* We use the bit map for all cases when not in UTF-8 mode; else          /* We use the bit map for 8 bit mode, or when the characters fall
4290          ranges that lie entirely within 0-127 when there is UCP support; else          partially or entirely to [0-255] ([0-127] for UCP) ranges. */
         for partial ranges without UCP support. */  
4291    
4292          class_charcount += d - c + 1;          class_charcount += d - c + 1;
4293          class_lastchar = d;          class_lastchar = d;
# Line 4182  for (;; ptr++) Line 4315  for (;; ptr++)
4315    
4316        /* Handle a character that cannot go in the bit map */        /* Handle a character that cannot go in the bit map */
4317    
4318  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4319        if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))        if (utf && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))
4320    #endif
4321    #ifndef COMPILE_PCRE8
4322          if (c > 255)
4323    #endif
4324    #if defined SUPPORT_UTF || defined COMPILE_PCRE16
4325          {          {
4326          class_utf8 = TRUE;          xclass = TRUE;
4327          *class_utf8data++ = XCL_SINGLE;          *class_uchardata++ = XCL_SINGLE;
4328          class_utf8data += _pcre_ord2utf8(c, class_utf8data);  #ifdef SUPPORT_UTF
4329            class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4330    #else
4331            *class_uchardata++ = c;
4332    #endif
4333    
4334  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4335          if ((options & PCRE_CASELESS) != 0)          if ((options & PCRE_CASELESS) != 0)
# Line 4195  for (;; ptr++) Line 4337  for (;; ptr++)
4337            unsigned int othercase;            unsigned int othercase;
4338            if ((othercase = UCD_OTHERCASE(c)) != c)            if ((othercase = UCD_OTHERCASE(c)) != c)
4339              {              {
4340              *class_utf8data++ = XCL_SINGLE;              *class_uchardata++ = XCL_SINGLE;
4341              class_utf8data += _pcre_ord2utf8(othercase, class_utf8data);              class_uchardata += PRIV(ord2utf)(othercase, class_uchardata);
4342              }              }
4343            }            }
4344  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 4248  for (;; ptr++) Line 4390  for (;; ptr++)
4390      The optimization throws away the bit map. We turn the item into a      The optimization throws away the bit map. We turn the item into a
4391      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.
4392      Note that OP_NOT[I] does not support multibyte characters. In the positive      Note that OP_NOT[I] does not support multibyte characters. In the positive
4393      case, it can cause firstbyte to be set. Otherwise, there can be no first      case, it can cause firstchar to be set. Otherwise, there can be no first
4394      char if this item is first, whatever repeat count may follow. In the case      char if this item is first, whatever repeat count may follow. In the case
4395      of reqbyte, save the previous value for reinstating. */      of reqchar, save the previous value for reinstating. */
4396    
4397  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4398      if (class_charcount == 1 && !class_utf8 &&      if (class_charcount == 1 && !xclass &&
4399        (!utf8 || !negate_class || class_lastchar < 128))        (!utf || !negate_class || class_lastchar < 128))
4400  #else  #else
4401      if (class_charcount == 1)      if (class_charcount == 1)
4402  #endif  #endif
4403        {        {
4404        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
4405    
4406        /* The OP_NOT[I] opcodes work on one-byte characters only. */        /* The OP_NOT[I] opcodes work on one-byte characters only. */
4407    
4408        if (negate_class)        if (negate_class)
4409          {          {
4410          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4411          zerofirstbyte = firstbyte;          zerofirstchar = firstchar;
4412          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4413          *code++ = class_lastchar;          *code++ = class_lastchar;
4414          break;          break;
# Line 4276  for (;; ptr++) Line 4418  for (;; ptr++)
4418        then we can handle this with the normal one-character code. */        then we can handle this with the normal one-character code. */
4419    
4420  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4421        if (utf8 && class_lastchar > 127)        if (utf && class_lastchar > 127)
4422          mclength = _pcre_ord2utf8(class_lastchar, mcbuffer);          mclength = PRIV(ord2utf)(class_lastchar, mcbuffer);
4423        else        else
4424  #endif  #endif
4425          {          {
# Line 4289  for (;; ptr++) Line 4431  for (;; ptr++)
4431    
4432      /* The general case - not the one-char optimization. If this is the first      /* The general case - not the one-char optimization. If this is the first
4433      thing in the branch, there can be no first char setting, whatever the      thing in the branch, there can be no first char setting, whatever the
4434      repeat count. Any reqbyte setting must remain unchanged after any kind of      repeat count. Any reqchar setting must remain unchanged after any kind of
4435      repeat. */      repeat. */
4436    
4437      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4438      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
4439      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
4440    
4441      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4442      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 4304  for (;; ptr++) Line 4446  for (;; ptr++)
4446      be listed) there are no characters < 256, we can omit the bitmap in the      be listed) there are no characters < 256, we can omit the bitmap in the
4447      actual compiled code. */      actual compiled code. */
4448    
4449  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4450      if (class_utf8 && (!should_flip_negation || (options & PCRE_UCP) != 0))      if (xclass && (!should_flip_negation || (options & PCRE_UCP) != 0))
4451    #endif
4452    #ifndef COMPILE_PCRE8
4453        if (xclass && !should_flip_negation)
4454    #endif
4455    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4456        {        {
4457        *class_utf8data++ = XCL_END;    /* Marks the end of extra data */        *class_uchardata++ = XCL_END;    /* Marks the end of extra data */
4458        *code++ = OP_XCLASS;        *code++ = OP_XCLASS;
4459        code += LINK_SIZE;        code += LINK_SIZE;
4460        *code = negate_class? XCL_NOT : 0;        *code = negate_class? XCL_NOT:0;
4461    
4462        /* If the map is required, move up the extra data to make room for it;        /* If the map is required, move up the extra data to make room for it;
4463        otherwise just move the code pointer to the end of the extra data. */        otherwise just move the code pointer to the end of the extra data. */
# Line 4318  for (;; ptr++) Line 4465  for (;; ptr++)
4465        if (class_charcount > 0)        if (class_charcount > 0)
4466          {          {
4467          *code++ |= XCL_MAP;          *code++ |= XCL_MAP;
4468          memmove(code + 32, code, class_utf8data - code);          memmove(code + (32 / sizeof(pcre_uchar)), code,
4469              IN_UCHARS(class_uchardata - code));
4470          memcpy(code, classbits, 32);          memcpy(code, classbits, 32);
4471          code = class_utf8data + 32;          code = class_uchardata + (32 / sizeof(pcre_uchar));
4472          }          }
4473        else code = class_utf8data;        else code = class_uchardata;
4474    
4475        /* Now fill in the complete length of the item */        /* Now fill in the complete length of the item */
4476    
# Line 4338  for (;; ptr++) Line 4486  for (;; ptr++)
4486      negating it if necessary. */      negating it if necessary. */
4487    
4488      *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;      *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;
4489      if (negate_class)      if (lengthptr == NULL)    /* Save time in the pre-compile phase */
       {  
       if (lengthptr == NULL)    /* Save time in the pre-compile phase */  
         for (c = 0; c < 32; c++) code[c] = ~classbits[c];  
       }  
     else  
4490        {        {
4491          if (negate_class)
4492            for (c = 0; c < 32; c++) classbits[c] = ~classbits[c];
4493        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4494        }        }
4495      code += 32;      code += 32 / sizeof(pcre_uchar);
4496      break;      break;
4497    
4498    
# Line 4384  for (;; ptr++) Line 4529  for (;; ptr++)
4529    
4530      if (repeat_min == 0)      if (repeat_min == 0)
4531        {        {
4532        firstbyte = zerofirstbyte;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4533        reqbyte = zeroreqbyte;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4534        }        }
4535    
4536      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4427  for (;; ptr++) Line 4572  for (;; ptr++)
4572    
4573      if (*previous == OP_RECURSE)      if (*previous == OP_RECURSE)
4574        {        {
4575        memmove(previous + 1 + LINK_SIZE, previous, 1 + LINK_SIZE);        memmove(previous + 1 + LINK_SIZE, previous, IN_UCHARS(1 + LINK_SIZE));
4576        *previous = OP_ONCE;        *previous = OP_ONCE;
4577        PUT(previous, 1, 2 + 2*LINK_SIZE);        PUT(previous, 1, 2 + 2*LINK_SIZE);
4578        previous[2 + 2*LINK_SIZE] = OP_KET;        previous[2 + 2*LINK_SIZE] = OP_KET;
# Line 4450  for (;; ptr++) Line 4595  for (;; ptr++)
4595    
4596      /* If previous was a character match, abolish the item and generate a      /* If previous was a character match, abolish the item and generate a
4597      repeat item instead. If a char item has a minumum of more than one, ensure      repeat item instead. If a char item has a minumum of more than one, ensure
4598      that it is set in reqbyte - it might not be if a sequence such as x{3} is      that it is set in reqchar - it might not be if a sequence such as x{3} is
4599      the first thing in a branch because the x will have gone into firstbyte      the first thing in a branch because the x will have gone into firstchar
4600      instead.  */      instead.  */
4601    
4602      if (*previous == OP_CHAR || *previous == OP_CHARI)      if (*previous == OP_CHAR || *previous == OP_CHARI)
4603        {        {
4604        op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR;        op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR;
4605    
4606        /* Deal with UTF-8 characters that take up more than one byte. It's        /* Deal with UTF characters that take up more than one character. It's
4607        easier to write this out separately than try to macrify it. Use c to        easier to write this out separately than try to macrify it. Use c to
4608        hold the length of the character in bytes, plus 0x80 to flag that it's a        hold the length of the character in bytes, plus UTF_LENGTH to flag that
4609        length rather than a small character. */        it's a length rather than a small character. */
4610    
4611  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4612        if (utf8 && (code[-1] & 0x80) != 0)  #ifdef COMPILE_PCRE8
4613          if (utf && (code[-1] & 0x80) != 0)
4614    #endif /* COMPILE_PCRE8 */
4615    #ifdef COMPILE_PCRE16
4616          if (utf && (code[-1] & 0xfc00) == 0xdc00)
4617    #endif /* COMPILE_PCRE8 */
4618          {          {
4619          uschar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
4620          while((*lastchar & 0xc0) == 0x80) lastchar--;          BACKCHAR(lastchar);
4621          c = code - lastchar;            /* Length of UTF-8 character */          c = code - lastchar;            /* Length of UTF-8 character */
4622          memcpy(utf8_char, lastchar, c); /* Save the char */          memcpy(utf_chars, lastchar, IN_UCHARS(c)); /* Save the char */
4623          c |= 0x80;                      /* Flag c as a length */          c |= UTF_LENGTH;                /* Flag c as a length */
4624          }          }
4625        else        else
4626  #endif  #endif /* SUPPORT_UTF */
4627    
4628        /* Handle the case of a single byte - either with no UTF8 support, or        /* Handle the case of a single charater - either with no UTF support, or
4629        with UTF-8 disabled, or for a UTF-8 character < 128. */        with UTF disabled, or for a single character UTF character. */
4630    
4631          {          {
4632          c = code[-1];          c = code[-1];
4633          if (repeat_min > 1) reqbyte = c | req_caseopt | cd->req_varyopt;          if (repeat_min > 1) reqchar = c | req_caseopt | cd->req_varyopt;
4634          }          }
4635    
4636        /* 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 4490  for (;; ptr++) Line 4640  for (;; ptr++)
4640    
4641        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4642            repeat_max < 0 &&            repeat_max < 0 &&
4643            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4644          {          {
4645          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4646          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4511  for (;; ptr++) Line 4661  for (;; ptr++)
4661        c = previous[1];        c = previous[1];
4662        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4663            repeat_max < 0 &&            repeat_max < 0 &&
4664            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4665          {          {
4666          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4667          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4528  for (;; ptr++) Line 4678  for (;; ptr++)
4678    
4679      else if (*previous < OP_EODN)      else if (*previous < OP_EODN)
4680        {        {
4681        uschar *oldcode;        pcre_uchar *oldcode;
4682        int prop_type, prop_value;        int prop_type, prop_value;
4683        op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */        op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */
4684        c = *previous;        c = *previous;
4685    
4686        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4687            repeat_max < 0 &&            repeat_max < 0 &&
4688            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4689          {          {
4690          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4691          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4615  for (;; ptr++) Line 4765  for (;; ptr++)
4765          we have to insert the character for the previous code. For a repeated          we have to insert the character for the previous code. For a repeated
4766          Unicode property match, there are two extra bytes that define the          Unicode property match, there are two extra bytes that define the
4767          required property. In UTF-8 mode, long characters have their length in          required property. In UTF-8 mode, long characters have their length in
4768          c, with the 0x80 bit as a flag. */          c, with the UTF_LENGTH bit as a flag. */
4769    
4770          if (repeat_max < 0)          if (repeat_max < 0)
4771            {            {
4772  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4773            if (utf8 && c >= 128)            if (utf && (c & UTF_LENGTH) != 0)
4774              {              {
4775              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, IN_UCHARS(c & 7));
4776              code += c & 7;              code += c & 7;
4777              }              }
4778            else            else
# Line 4644  for (;; ptr++) Line 4794  for (;; ptr++)
4794    
4795          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4796            {            {
4797  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4798            if (utf8 && c >= 128)            if (utf && (c & UTF_LENGTH) != 0)
4799              {              {
4800              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, IN_UCHARS(c & 7));
4801              code += c & 7;              code += c & 7;
4802              }              }
4803            else            else
# Line 4674  for (;; ptr++) Line 4824  for (;; ptr++)
4824    
4825        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
4826    
4827  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4828        if (utf8 && c >= 128)        if (utf && (c & UTF_LENGTH) != 0)
4829          {          {
4830          memcpy(code, utf8_char, c & 7);          memcpy(code, utf_chars, IN_UCHARS(c & 7));
4831          code += c & 7;          code += c & 7;
4832          }          }
4833        else        else
# Line 4701  for (;; ptr++) Line 4851  for (;; ptr++)
4851    
4852      else if (*previous == OP_CLASS ||      else if (*previous == OP_CLASS ||
4853               *previous == OP_NCLASS ||               *previous == OP_NCLASS ||
4854  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF8 || !defined COMPILE_PCRE8
4855               *previous == OP_XCLASS ||               *previous == OP_XCLASS ||
4856  #endif  #endif
4857               *previous == OP_REF ||               *previous == OP_REF ||
# Line 4750  for (;; ptr++) Line 4900  for (;; ptr++)
4900        {        {
4901        register int i;        register int i;
4902        int len = (int)(code - previous);        int len = (int)(code - previous);
4903        uschar *bralink = NULL;        pcre_uchar *bralink = NULL;
4904        uschar *brazeroptr = NULL;        pcre_uchar *brazeroptr = NULL;
4905    
4906        /* Repeating a DEFINE group is pointless, but Perl allows the syntax, so        /* Repeating a DEFINE group is pointless, but Perl allows the syntax, so
4907        we just ignore the repeat. */        we just ignore the repeat. */
# Line 4804  for (;; ptr++) Line 4954  for (;; ptr++)
4954          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */
4955            {            {
4956            *code = OP_END;            *code = OP_END;
4957            adjust_recurse(previous, 1, utf8, cd, save_hwm);            adjust_recurse(previous, 1, utf, cd, save_hwm);
4958            memmove(previous+1, previous, len);            memmove(previous + 1, previous, IN_UCHARS(len));
4959            code++;            code++;
4960            if (repeat_max == 0)            if (repeat_max == 0)
4961              {              {
# Line 4828  for (;; ptr++) Line 4978  for (;; ptr++)
4978            {            {
4979            int offset;            int offset;
4980            *code = OP_END;            *code = OP_END;
4981            adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd, save_hwm);            adjust_recurse(previous, 2 + LINK_SIZE, utf, cd, save_hwm);
4982            memmove(previous + 2 + LINK_SIZE, previous, len);            memmove(previous + 2 + LINK_SIZE, previous, IN_UCHARS(len));
4983            code += 2 + LINK_SIZE;            code += 2 + LINK_SIZE;
4984            *previous++ = OP_BRAZERO + repeat_type;            *previous++ = OP_BRAZERO + repeat_type;
4985            *previous++ = OP_BRA;            *previous++ = OP_BRA;
# Line 4879  for (;; ptr++) Line 5029  for (;; ptr++)
5029    
5030            else            else
5031              {              {
5032              if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte;              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;
5033              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5034                {                {
5035                uschar *hc;                pcre_uchar *hc;
5036                uschar *this_hwm = cd->hwm;                pcre_uchar *this_hwm = cd->hwm;
5037                memcpy(code, previous, len);                memcpy(code, previous, IN_UCHARS(len));
5038                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
5039                  {                  {
5040                  PUT(cd->hwm, 0, GET(hc, 0) + len);                  PUT(cd->hwm, 0, GET(hc, 0) + len);
# Line 4934  for (;; ptr++) Line 5084  for (;; ptr++)
5084    
5085          else for (i = repeat_max - 1; i >= 0; i--)          else for (i = repeat_max - 1; i >= 0; i--)
5086            {            {
5087            uschar *hc;            pcre_uchar *hc;
5088            uschar *this_hwm = cd->hwm;            pcre_uchar *this_hwm = cd->hwm;
5089    
5090            *code++ = OP_BRAZERO + repeat_type;            *code++ = OP_BRAZERO + repeat_type;
5091    
# Line 4951  for (;; ptr++) Line 5101  for (;; ptr++)
5101              PUTINC(code, 0, offset);              PUTINC(code, 0, offset);
5102              }              }
5103    
5104            memcpy(code, previous, len);            memcpy(code, previous, IN_UCHARS(len));
5105            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
5106              {              {
5107              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));
# Line 4968  for (;; ptr++) Line 5118  for (;; ptr++)
5118            {            {
5119            int oldlinkoffset;            int oldlinkoffset;
5120            int offset = (int)(code - bralink + 1);            int offset = (int)(code - bralink + 1);
5121            uschar *bra = code - offset;            pcre_uchar *bra = code - offset;
5122            oldlinkoffset = GET(bra, 1);            oldlinkoffset = GET(bra, 1);
5123            bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;            bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;
5124            *code++ = OP_KET;            *code++ = OP_KET;
# Line 4994  for (;; ptr++) Line 5144  for (;; ptr++)
5144        KETRPOS. (It turns out to be convenient at runtime to detect this kind of        KETRPOS. (It turns out to be convenient at runtime to detect this kind of
5145        subpattern at both the start and at the end.) The use of special opcodes        subpattern at both the start and at the end.) The use of special opcodes
5146        makes it possible to reduce greatly the stack usage in pcre_exec(). If        makes it possible to reduce greatly the stack usage in pcre_exec(). If
5147        the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO. Then        the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO.
5148        cancel the possessive flag so that the default action below, of wrapping  
5149        everything inside atomic brackets, does not happen. */        Then, if the minimum number of matches is 1 or 0, cancel the possessive
5150          flag so that the default action below, of wrapping everything inside
5151          atomic brackets, does not happen. When the minimum is greater than 1,
5152          there will be earlier copies of the group, and so we still have to wrap
5153          the whole thing. */
5154    
5155        else        else
5156          {          {
5157          uschar *ketcode = code - 1 - LINK_SIZE;          pcre_uchar *ketcode = code - 1 - LINK_SIZE;
5158          uschar *bracode = ketcode - GET(ketcode, 1);          pcre_uchar *bracode = ketcode - GET(ketcode, 1);
5159    
5160          /* Convert possessive ONCE brackets to non-capturing */          /* Convert possessive ONCE brackets to non-capturing */
5161    
# Line 5023  for (;; ptr++) Line 5177  for (;; ptr++)
5177    
5178            if (lengthptr == NULL)            if (lengthptr == NULL)
5179              {              {
5180              uschar *scode = bracode;              pcre_uchar *scode = bracode;
5181              do              do
5182                {                {
5183                if (could_be_empty_branch(scode, ketcode, utf8, cd))                if (could_be_empty_branch(scode, ketcode, utf, cd))
5184                  {                  {
5185                  *bracode += OP_SBRA - OP_BRA;                  *bracode += OP_SBRA - OP_BRA;
5186                  break;                  break;
# Line 5049  for (;; ptr++) Line 5203  for (;; ptr++)
5203                {                {
5204                int nlen = (int)(code - bracode);                int nlen = (int)(code - bracode);
5205                *code = OP_END;                *code = OP_END;
5206                adjust_recurse(bracode, 1 + LINK_SIZE, utf8, cd, save_hwm);                adjust_recurse(bracode, 1 + LINK_SIZE, utf, cd, save_hwm);
5207                memmove(bracode + 1+LINK_SIZE, bracode, nlen);                memmove(bracode + 1 + LINK_SIZE, bracode, IN_UCHARS(nlen));
5208                code += 1 + LINK_SIZE;                code += 1 + LINK_SIZE;
5209                nlen += 1 + LINK_SIZE;                nlen += 1 + LINK_SIZE;
5210                *bracode = OP_BRAPOS;                *bracode = OP_BRAPOS;
# Line 5068  for (;; ptr++) Line 5222  for (;; ptr++)
5222                }                }
5223    
5224              /* If the minimum is zero, mark it as possessive, then unset the              /* If the minimum is zero, mark it as possessive, then unset the
5225              possessive flag. */              possessive flag when the minimum is 0 or 1. */
5226    
5227              if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;              if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;
5228              possessive_quantifier = FALSE;              if (repeat_min < 2) possessive_quantifier = FALSE;
5229              }              }
5230    
5231            /* Non-possessive quantifier */            /* Non-possessive quantifier */
# Line 5103  for (;; ptr++) Line 5257  for (;; ptr++)
5257      notation is just syntactic sugar, taken from Sun's Java package, but the      notation is just syntactic sugar, taken from Sun's Java package, but the
5258      special opcodes can optimize it.      special opcodes can optimize it.
5259    
5260      Possessively repeated subpatterns have already been handled in the code      Some (but not all) possessively repeated subpatterns have already been
5261      just above, so possessive_quantifier is always FALSE for them at this      completely handled in the code just above. For them, possessive_quantifier
5262      stage.      is always FALSE at this stage.
5263    
5264      Note that the repeated item starts at tempcode, not at previous, which      Note that the repeated item starts at tempcode, not at previous, which
5265      might be the first part of a string whose (former) last char we repeated.      might be the first part of a string whose (former) last char we repeated.
# Line 5119  for (;; ptr++) Line 5273  for (;; ptr++)
5273        int len;        int len;
5274    
5275        if (*tempcode == OP_TYPEEXACT)        if (*tempcode == OP_TYPEEXACT)
5276          tempcode += _pcre_OP_lengths[*tempcode] +          tempcode += PRIV(OP_lengths)[*tempcode] +
5277            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);            ((tempcode[1 + IMM2_SIZE] == OP_PROP
5278              || tempcode[1 + IMM2_SIZE] == OP_NOTPROP)? 2 : 0);
5279    
5280        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5281          {          {
5282          tempcode += _pcre_OP_lengths[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5283  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
5284          if (utf8 && tempcode[-1] >= 0xc0)          if (utf && HAS_EXTRALEN(tempcode[-1]))
5285            tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];            tempcode += GET_EXTRALEN(tempcode[-1]);
5286  #endif  #endif
5287          }          }
5288    
# Line 5164  for (;; ptr++) Line 5319  for (;; ptr++)
5319    
5320          default:          default:
5321          *code = OP_END;          *code = OP_END;
5322          adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);          adjust_recurse(tempcode, 1 + LINK_SIZE, utf, cd, save_hwm);
5323          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1 + LINK_SIZE, tempcode, IN_UCHARS(len));
5324          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
5325          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
5326          tempcode[0] = OP_ONCE;          tempcode[0] = OP_ONCE;
# Line 5177  for (;; ptr++) Line 5332  for (;; ptr++)
5332        }        }
5333    
5334      /* In all case we no longer have a previous item. We also set the      /* In all case we no longer have a previous item. We also set the
5335      "follows varying string" flag for subsequently encountered reqbytes if      "follows varying string" flag for subsequently encountered reqchars if
5336      it isn't already set and we have just passed a varying length item. */      it isn't already set and we have just passed a varying length item. */
5337    
5338      END_REPEAT:      END_REPEAT:
# Line 5206  for (;; ptr++) Line 5361  for (;; ptr++)
5361        int i, namelen;        int i, namelen;
5362        int arglen = 0;        int arglen = 0;
5363        const char *vn = verbnames;        const char *vn = verbnames;
5364        const uschar *name = ptr + 1;        const pcre_uchar *name = ptr + 1;
5365        const uschar *arg = NULL;        const pcre_uchar *arg = NULL;
5366        previous = NULL;        previous = NULL;
5367        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};
5368        namelen = (int)(ptr - name);        namelen = (int)(ptr - name);
# Line 5234  for (;; ptr++) Line 5389  for (;; ptr++)
5389        for (i = 0; i < verbcount; i++)        for (i = 0; i < verbcount; i++)
5390          {          {
5391          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
5392              strncmp((char *)name, vn, namelen) == 0)              STRNCMP_UC_C8(name, vn, namelen) == 0)
5393            {            {
5394            /* Check for open captures before ACCEPT and convert it to            /* Check for open captures before ACCEPT and convert it to
5395            ASSERT_ACCEPT if in an assertion. */            ASSERT_ACCEPT if in an assertion. */
# Line 5255  for (;; ptr++) Line 5410  for (;; ptr++)
5410                }                }
5411              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;              *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5412    
5413              /* Do not set firstbyte after *ACCEPT */              /* Do not set firstchar after *ACCEPT */
5414              if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;              if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
5415              }              }
5416    
5417            /* Handle other cases with/without an argument */            /* Handle other cases with/without an argument */
# Line 5282  for (;; ptr++) Line 5437  for (;; ptr++)
5437              *code = verbs[i].op_arg;              *code = verbs[i].op_arg;
5438              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;
5439              *code++ = arglen;              *code++ = arglen;
5440              memcpy(code, arg, arglen);              memcpy(code, arg, IN_UCHARS(arglen));
5441              code += arglen;              code += arglen;
5442              *code++ = 0;              *code++ = 0;
5443              }              }
# Line 5305  for (;; ptr++) Line 5460  for (;; ptr++)
5460        {        {
5461        int i, set, unset, namelen;        int i, set, unset, namelen;
5462        int *optset;        int *optset;
5463        const uschar *name;        const pcre_uchar *name;
5464        uschar *slot;        pcre_uchar *slot;
5465    
5466        switch (*(++ptr))        switch (*(++ptr))
5467          {          {
# Line 5359  for (;; ptr++) Line 5514  for (;; ptr++)
5514            break;            break;
5515    
5516          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
5517          below), and all need to skip 3 bytes at the start of the group. */          below), and all need to skip 1+IMM2_SIZE bytes at the start of the group. */
5518    
5519          code[1+LINK_SIZE] = OP_CREF;          code[1+LINK_SIZE] = OP_CREF;
5520          skipbytes = 3;          skipbytes = 1+IMM2_SIZE;
5521          refsign = -1;          refsign = -1;
5522    
5523          /* Check for a test for recursion in a named group. */          /* Check for a test for recursion in a named group. */
# Line 5409  for (;; ptr++) Line 5564  for (;; ptr++)
5564          while ((cd->ctypes[*ptr] & ctype_word) != 0)          while ((cd->ctypes[*ptr] & ctype_word) != 0)
5565            {            {
5566            if (recno >= 0)            if (recno >= 0)
5567              recno = ((digitab[*ptr] & ctype_digit) != 0)?              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;
               recno * 10 + *ptr - CHAR_0 : -1;  
5568            ptr++;            ptr++;
5569            }            }
5570          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
# Line 5458  for (;; ptr++) Line 5612  for (;; ptr++)
5612          slot = cd->name_table;          slot = cd->name_table;
5613          for (i = 0; i < cd->names_found; i++)          for (i = 0; i < cd->names_found; i++)
5614            {            {
5615            if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;            if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0) break;
5616            slot += cd->name_entry_size;            slot += cd->name_entry_size;
5617            }            }
5618    
# Line 5474  for (;; ptr++) Line 5628  for (;; ptr++)
5628          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
5629    
5630          else if ((i = find_parens(cd, name, namelen,          else if ((i = find_parens(cd, name, namelen,
5631                          (options & PCRE_EXTENDED) != 0, utf8)) > 0)                          (options & PCRE_EXTENDED) != 0, utf)) > 0)
5632            {            {
5633            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
5634            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
# Line 5500  for (;; ptr++) Line 5654  for (;; ptr++)
5654            recno = 0;            recno = 0;
5655            for (i = 1; i < namelen; i++)            for (i = 1; i < namelen; i++)
5656              {              {
5657              if ((digitab[name[i]] & ctype_digit) == 0)              if (!IS_DIGIT(name[i]))
5658                {                {
5659                *errorcodeptr = ERR15;                *errorcodeptr = ERR15;
5660                goto FAILED;                goto FAILED;
# Line 5515  for (;; ptr++) Line 5669  for (;; ptr++)
5669          /* Similarly, check for the (?(DEFINE) "condition", which is always          /* Similarly, check for the (?(DEFINE) "condition", which is always
5670          false. */          false. */
5671    
5672          else if (namelen == 6 && strncmp((char *)name, STRING_DEFINE, 6) == 0)          else if (namelen == 6 && STRNCMP_UC_C8(name, STRING_DEFINE, 6) == 0)
5673            {            {
5674            code[1+LINK_SIZE] = OP_DEF;            code[1+LINK_SIZE] = OP_DEF;
5675            skipbytes = 1;            skipbytes = 1;
# Line 5595  for (;; ptr++) Line 5749  for (;; ptr++)
5749    
5750          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5751          case CHAR_C:                 /* Callout - may be followed by digits; */          case CHAR_C:                 /* Callout - may be followed by digits; */
5752          previous_callout = code;  /* Save for later completion */          previous_callout = code;     /* Save for later completion */
5753          after_manual_callout = 1; /* Skip one item before completing */          after_manual_callout = 1;    /* Skip one item before completing */
5754          *code++ = OP_CALLOUT;          *code++ = OP_CALLOUT;
5755            {            {
5756            int n = 0;            int n = 0;
5757            while ((digitab[*(++ptr)] & ctype_digit) != 0)            ptr++;
5758              n = n * 10 + *ptr - CHAR_0;            while(IS_DIGIT(*ptr))
5759                n = n * 10 + *ptr++ - CHAR_0;
5760            if (*ptr != CHAR_RIGHT_PARENTHESIS)            if (*ptr != CHAR_RIGHT_PARENTHESIS)
5761              {              {
5762              *errorcodeptr = ERR39;              *errorcodeptr = ERR39;
# Line 5718  for (;; ptr++) Line 5873  for (;; ptr++)
5873                if (crc < 0)                if (crc < 0)
5874                  {                  {
5875                  memmove(slot + cd->name_entry_size, slot,                  memmove(slot + cd->name_entry_size, slot,
5876                    (cd->names_found - i) * cd->name_entry_size);                    IN_UCHARS((cd->names_found - i) * cd->name_entry_size));
5877                  break;                  break;
5878                  }                  }
5879    
# Line 5732  for (;; ptr++) Line 5887  for (;; ptr++)
5887    
5888              if (!dupname)              if (!dupname)
5889                {                {
5890                uschar *cslot = cd->name_table;                pcre_uchar *cslot = cd->name_table;
5891                for (i = 0; i < cd->names_found; i++)                for (i = 0; i < cd->names_found; i++)
5892                  {                  {
5893                  if (cslot != slot)                  if (cslot != slot)
# Line 5749  for (;; ptr++) Line 5904  for (;; ptr++)
5904                }                }
5905    
5906              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
5907              memcpy(slot + 2, name, namelen);              memcpy(slot + 2, name, IN_UCHARS(namelen));
5908              slot[2+namelen] = 0;              slot[2 + namelen] = 0;
5909              }              }
5910            }            }
5911    
# Line 5788  for (;; ptr++) Line 5943  for (;; ptr++)
5943    
5944          if (lengthptr != NULL)          if (lengthptr != NULL)
5945            {            {
5946            const uschar *temp;            const pcre_uchar *temp;
5947    
5948            if (namelen == 0)            if (namelen == 0)
5949              {              {
# Line 5818  for (;; ptr++) Line 5973  for (;; ptr++)
5973            temp = cd->end_pattern;            temp = cd->end_pattern;
5974            cd->end_pattern = ptr;            cd->end_pattern = ptr;
5975            recno = find_parens(cd, name, namelen,            recno = find_parens(cd, name, namelen,
5976              (options & PCRE_EXTENDED) != 0, utf8);              (options & PCRE_EXTENDED) != 0, utf);
5977            cd->end_pattern = temp;            cd->end_pattern = temp;
5978            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */
5979            }            }
# Line 5833  for (;; ptr++) Line 5988  for (;; ptr++)
5988            slot = cd->name_table;            slot = cd->name_table;
5989            for (i = 0; i < cd->names_found; i++)            for (i = 0; i < cd->names_found; i++)
5990              {              {
5991              if (strncmp((char *)name, (char *)slot+2, namelen) == 0 &&              if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0 &&
5992                  slot[2+namelen] == 0)                  slot[2+namelen] == 0)
5993                break;                break;
5994              slot += cd->name_entry_size;              slot += cd->name_entry_size;
# Line 5845  for (;; ptr++) Line 6000  for (;; ptr++)
6000              }              }
6001            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
6002                      find_parens(cd, name, namelen,                      find_parens(cd, name, namelen,
6003                        (options & PCRE_EXTENDED) != 0, utf8)) <= 0)                        (options & PCRE_EXTENDED) != 0, utf)) <= 0)
6004              {              {
6005              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
6006              goto FAILED;              goto FAILED;
# Line 5870  for (;; ptr++) Line 6025  for (;; ptr++)
6025          case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4:          case CHAR_0: case CHAR_1: case CHAR_2: case CHAR_3: case CHAR_4:
6026          case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9:          case CHAR_5: case CHAR_6: case CHAR_7: case CHAR_8: case CHAR_9:
6027            {            {
6028            const uschar *called;            const pcre_uchar *called;
6029            terminator = CHAR_RIGHT_PARENTHESIS;            terminator = CHAR_RIGHT_PARENTHESIS;
6030    
6031            /* Come here from the \g<...> and \g'...' code (Oniguruma            /* Come here from the \g<...> and \g'...' code (Oniguruma
# Line 5884  for (;; ptr++) Line 6039  for (;; ptr++)
6039            if ((refsign = *ptr) == CHAR_PLUS)            if ((refsign = *ptr) == CHAR_PLUS)
6040              {              {
6041              ptr++;              ptr++;
6042              if ((digitab[*ptr] & ctype_digit) == 0)              if (!IS_DIGIT(*ptr))
6043                {                {
6044                *errorcodeptr = ERR63;                *errorcodeptr = ERR63;
6045                goto FAILED;                goto FAILED;
# Line 5892  for (;; ptr++) Line 6047  for (;; ptr++)
6047              }              }
6048            else if (refsign == CHAR_MINUS)            else if (refsign == CHAR_MINUS)
6049              {              {
6050              if ((digitab[ptr[1]] & ctype_digit) == 0)              if (!IS_DIGIT(ptr[1]))
6051                goto OTHER_CHAR_AFTER_QUERY;                goto OTHER_CHAR_AFTER_QUERY;
6052              ptr++;              ptr++;
6053              }              }
6054    
6055            recno = 0;            recno = 0;
6056            while((digitab[*ptr] & ctype_digit) != 0)            while(IS_DIGIT(*ptr))
6057              recno = recno * 10 + *ptr++ - CHAR_0;              recno = recno * 10 + *ptr++ - CHAR_0;
6058    
6059            if (*ptr != terminator)            if (*ptr != terminator)
# Line 5949  for (;; ptr++) Line 6104  for (;; ptr++)
6104              {              {
6105              *code = OP_END;              *code = OP_END;
6106              if (recno != 0)              if (recno != 0)
6107                called = _pcre_find_bracket(cd->start_code, utf8, recno);                called = PRIV(find_bracket)(cd->start_code, utf, recno);
6108    
6109              /* Forward reference */              /* Forward reference */
6110    
6111              if (called == NULL)              if (called == NULL)
6112                {                {
6113                if (find_parens(cd, NULL, recno,                if (find_parens(cd, NULL, recno,
6114                      (options & PCRE_EXTENDED) != 0, utf8) < 0)                      (options & PCRE_EXTENDED) != 0, utf) < 0)
6115                  {                  {
6116                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
6117                  goto FAILED;                  goto FAILED;
# Line 5980  for (;; ptr++) Line 6135  for (;; ptr++)
6135              conditional subpatterns will be picked up then. */              conditional subpatterns will be picked up then. */
6136    
6137              else if (GET(called, 1) == 0 && cond_depth <= 0 &&              else if (GET(called, 1) == 0 && cond_depth <= 0 &&
6138                       could_be_empty(called, code, bcptr, utf8, cd))                       could_be_empty(called, code, bcptr, utf, cd))
6139                {                {
6140                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
6141                goto FAILED;                goto FAILED;
# Line 5996  for (;; ptr++) Line 6151  for (;; ptr++)
6151    
6152          /* Can't determine a first byte now */          /* Can't determine a first byte now */
6153    
6154          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
6155          continue;          continue;
6156    
6157    
# Line 6053  for (;; ptr++) Line 6208  for (;; ptr++)
6208          both phases.          both phases.
6209    
6210          If we are not at the pattern start, reset the greedy defaults and the          If we are not at the pattern start, reset the greedy defaults and the
6211          case value for firstbyte and reqbyte. */          case value for firstchar and reqchar. */
6212    
6213          if (*ptr == CHAR_RIGHT_PARENTHESIS)          if (*ptr == CHAR_RIGHT_PARENTHESIS)
6214            {            {
# Line 6066  for (;; ptr++) Line 6221  for (;; ptr++)
6221              {              {
6222              greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);              greedy_default = ((newoptions & PCRE_UNGREEDY) != 0);
6223              greedy_non_default = greedy_default ^ 1;              greedy_non_default = greedy_default ^ 1;
6224              req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS : 0;              req_caseopt = ((newoptions & PCRE_CASELESS) != 0)? REQ_CASELESS:0;
6225              }              }
6226    
6227            /* Change options at this level, and pass them back for use            /* Change options at this level, and pass them back for use
# Line 6103  for (;; ptr++) Line 6258  for (;; ptr++)
6258        NUMBERED_GROUP:        NUMBERED_GROUP:
6259        cd->bracount += 1;        cd->bracount += 1;
6260        PUT2(code, 1+LINK_SIZE, cd->bracount);        PUT2(code, 1+LINK_SIZE, cd->bracount);
6261        skipbytes = 2;        skipbytes = IMM2_SIZE;
6262        }        }
6263    
6264      /* Process nested bracketed regex. Assertions used not to be repeatable,      /* Process nested bracketed regex. Assertions used not to be repeatable,
# Line 6129  for (;; ptr++) Line 6284  for (;; ptr++)
6284           skipbytes,                       /* Skip over bracket number */           skipbytes,                       /* Skip over bracket number */
6285           cond_depth +           cond_depth +
6286             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */             ((bravalue == OP_COND)?1:0),   /* Depth of condition subpatterns */
6287           &subfirstbyte,                   /* For possible first char */           &subfirstchar,                   /* For possible first char */
6288           &subreqbyte,                     /* For possible last char */           &subreqchar,                     /* For possible last char */
6289           bcptr,                           /* Current branch chain */           bcptr,                           /* Current branch chain */
6290           cd,                              /* Tables block */           cd,                              /* Tables block */
6291           (lengthptr == NULL)? NULL :      /* Actual compile phase */           (lengthptr == NULL)? NULL :      /* Actual compile phase */
# Line 6158  for (;; ptr++) Line 6313  for (;; ptr++)
6313    
6314      if (bravalue == OP_COND && lengthptr == NULL)      if (bravalue == OP_COND && lengthptr == NULL)
6315        {        {
6316        uschar *tc = code;        pcre_uchar *tc = code;
6317        int condcount = 0;        int condcount = 0;
6318    
6319        do {        do {
# Line 6181  for (;; ptr++) Line 6336  for (;; ptr++)
6336          }          }
6337    
6338        /* A "normal" conditional group. If there is just one branch, we must not        /* A "normal" conditional group. If there is just one branch, we must not
6339        make use of its firstbyte or reqbyte, because this is equivalent to an        make use of its firstchar or reqchar, because this is equivalent to an
6340        empty second branch. */        empty second branch. */
6341    
6342        else        else
# Line 6191  for (;; ptr++) Line 6346  for (;; ptr++)
6346            *errorcodeptr = ERR27;            *errorcodeptr = ERR27;
6347            goto FAILED;            goto FAILED;
6348            }            }
6349          if (condcount == 1) subfirstbyte = subreqbyte = REQ_NONE;          if (condcount == 1) subfirstchar = subreqchar = REQ_NONE;
6350          }          }
6351        }        }
6352    
# Line 6235  for (;; ptr++) Line 6390  for (;; ptr++)
6390      /* Handle updating of the required and first characters for other types of      /* Handle updating of the required and first characters for other types of
6391      group. Update for normal brackets of all kinds, and conditions with two      group. Update for normal brackets of all kinds, and conditions with two
6392      branches (see code above). If the bracket is followed by a quantifier with      branches (see code above). If the bracket is followed by a quantifier with
6393      zero repeat, we have to back off. Hence the definition of zeroreqbyte and      zero repeat, we have to back off. Hence the definition of zeroreqchar and
6394      zerofirstbyte outside the main loop so that they can be accessed for the      zerofirstchar outside the main loop so that they can be accessed for the
6395      back off. */      back off. */
6396    
6397      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
6398      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
6399      groupsetfirstbyte = FALSE;      groupsetfirstchar = FALSE;
6400    
6401      if (bravalue >= OP_ONCE)      if (bravalue >= OP_ONCE)
6402        {        {
6403        /* If we have not yet set a firstbyte in this branch, take it from the        /* If we have not yet set a firstchar in this branch, take it from the
6404        subpattern, remembering that it was set here so that a repeat of more        subpattern, remembering that it was set here so that a repeat of more
6405        than one can replicate it as reqbyte if necessary. If the subpattern has        than one can replicate it as reqchar if necessary. If the subpattern has
6406        no firstbyte, set "none" for the whole branch. In both cases, a zero        no firstchar, set "none" for the whole branch. In both cases, a zero
6407        repeat forces firstbyte to "none". */        repeat forces firstchar to "none". */
6408    
6409        if (firstbyte == REQ_UNSET)        if (firstchar == REQ_UNSET)
6410          {          {
6411          if (subfirstbyte >= 0)          if (subfirstchar >= 0)
6412            {            {
6413            firstbyte = subfirstbyte;            firstchar = subfirstchar;
6414            groupsetfirstbyte = TRUE;            groupsetfirstchar = TRUE;
6415            }            }
6416          else firstbyte = REQ_NONE;          else firstchar = REQ_NONE;
6417          zerofirstbyte = REQ_NONE;          zerofirstchar = REQ_NONE;
6418          }          }
6419    
6420        /* If firstbyte was previously set, convert the subpattern's firstbyte        /* If firstchar was previously set, convert the subpattern's firstchar
6421        into reqbyte if there wasn't one, using the vary flag that was in        into reqchar if there wasn't one, using the vary flag that was in
6422        existence beforehand. */        existence beforehand. */
6423    
6424        else if (subfirstbyte >= 0 && subreqbyte < 0)        else if (subfirstchar >= 0 && subreqchar < 0)
6425          subreqbyte = subfirstbyte | tempreqvary;          subreqchar = subfirstchar | tempreqvary;
6426    
6427        /* 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
6428        really the first byte - see above), set it. */        really the first byte - see above), set it. */
6429    
6430        if (subreqbyte >= 0) reqbyte = subreqbyte;        if (subreqchar >= 0) reqchar = subreqchar;
6431        }        }
6432    
6433      /* For a forward assertion, we take the reqbyte, if set. This can be      /* For a forward assertion, we take the reqchar, if set. This can be
6434      helpful if the pattern that follows the assertion doesn't set a different      helpful if the pattern that follows the assertion doesn't set a different
6435      char. For example, it's useful for /(?=abcde).+/. We can't set firstbyte      char. For example, it's useful for /(?=abcde).+/. We can't set firstchar
6436      for an assertion, however because it leads to incorrect effect for patterns      for an assertion, however because it leads to incorrect effect for patterns
6437      such as /(?=a)a.+/ when the "real" "a" would then become a reqbyte instead      such as /(?=a)a.+/ when the "real" "a" would then become a reqchar instead
6438      of a firstbyte. This is overcome by a scan at the end if there's no      of a firstchar. This is overcome by a scan at the end if there's no
6439      firstbyte, looking for an asserted first char. */      firstchar, looking for an asserted first char. */
6440    
6441      else if (bravalue == OP_ASSERT && subreqbyte >= 0) reqbyte = subreqbyte;      else if (bravalue == OP_ASSERT && subreqchar >= 0) reqchar = subreqchar;
6442      break;     /* End of processing '(' */      break;     /* End of processing '(' */
6443    
6444    
# Line 6316  for (;; ptr++) Line 6471  for (;; ptr++)
6471        /* For metasequences that actually match a character, we disable the        /* For metasequences that actually match a character, we disable the
6472        setting of a first character if it hasn't already been set. */        setting of a first character if it hasn't already been set. */
6473    
6474        if (firstbyte == REQ_UNSET && -c > ESC_b && -c < ESC_Z)        if (firstchar == REQ_UNSET && -c > ESC_b && -c < ESC_Z)
6475          firstbyte = REQ_NONE;          firstchar = REQ_NONE;
6476    
6477        /* 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. */
6478    
6479        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
6480        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6481    
6482        /* \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'
6483        is a subroutine call by number (Oniguruma syntax). In fact, the value        is a subroutine call by number (Oniguruma syntax). In fact, the value
# Line 6333  for (;; ptr++) Line 6488  for (;; ptr++)
6488    
6489        if (-c == ESC_g)        if (-c == ESC_g)
6490          {          {
6491          const uschar *p;          const pcre_uchar *p;
6492          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */          save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
6493          terminator = (*(++ptr) == CHAR_LESS_THAN_SIGN)?          terminator = (*(++ptr) == CHAR_LESS_THAN_SIGN)?
6494            CHAR_GREATER_THAN_SIGN : CHAR_APOSTROPHE;            CHAR_GREATER_THAN_SIGN : CHAR_APOSTROPHE;
# Line 6373  for (;; ptr++) Line 6528  for (;; ptr++)
6528          /* Test a signed number in angle brackets or quotes. */          /* Test a signed number in angle brackets or quotes. */
6529    
6530          p = ptr + 2;          p = ptr + 2;
6531          while ((digitab[*p] & ctype_digit) != 0) p++;          while (IS_DIGIT(*p)) p++;
6532          if (*p != terminator)          if (*p != terminator)
6533            {            {
6534            *errorcodeptr = ERR57;            *errorcodeptr = ERR57;
# Line 6401  for (;; ptr++) Line 6556  for (;; ptr++)
6556          goto NAMED_REF_OR_RECURSE;          goto NAMED_REF_OR_RECURSE;
6557          }          }
6558    
6559        /* Back references are handled specially; must disable firstbyte if        /* Back references are handled specially; must disable firstchar if
6560        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
6561        ':' later. */        ':' later. */
6562    
# Line 6411  for (;; ptr++) Line 6566  for (;; ptr++)
6566          recno = -c - ESC_REF;          recno = -c - ESC_REF;
6567    
6568          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
6569          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
6570          previous = code;          previous = code;
6571          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
6572          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
# Line 6473  for (;; ptr++) Line 6628  for (;; ptr++)
6628            }            }
6629          else          else
6630  #endif  #endif
6631            {          /* In non-UTF-8 mode, we turn \C into OP_ALLANY instead of OP_ANYBYTE
6632            so that it works in DFA mode and in lookbehinds. */
6633    
6634              {
6635            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;            previous = (-c > ESC_b && -c < ESC_Z)? code : NULL;
6636            *code++ = -c;            *code++ = (!utf && c == -ESC_C)? OP_ALLANY : -c;
6637            }            }
6638          }          }
6639        continue;        continue;
# Line 6486  for (;; ptr++) Line 6644  for (;; ptr++)
6644      handle it as a data character. */      handle it as a data character. */
6645    
6646  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
6647      if (utf8 && c > 127)      if (utf && c > 127)
6648        mclength = _pcre_ord2utf8(c, mcbuffer);        mclength = PRIV(ord2utf)(c, mcbuffer);
6649      else      else
6650  #endif  #endif
6651    
# Line 6508  for (;; ptr++) Line 6666  for (;; ptr++)
6666      mclength = 1;      mclength = 1;
6667      mcbuffer[0] = c;      mcbuffer[0] = c;
6668    
6669  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
6670      if (utf8 && c >= 0xc0)      if (utf && HAS_EXTRALEN(c))
6671        {        ACROSSCHAR(TRUE, ptr[1], mcbuffer[mclength++] = *(++ptr));
       while ((ptr[1] & 0xc0) == 0x80)  
         mcbuffer[mclength++] = *(++ptr);  
       }  
6672  #endif  #endif
6673    
6674      /* At this point we have the character's bytes in mcbuffer, and the length      /* At this point we have the character's bytes in mcbuffer, and the length
# Line 6531  for (;; ptr++) Line 6686  for (;; ptr++)
6686    
6687      /* Set the first and required bytes appropriately. If no previous first      /* Set the first and required bytes appropriately. If no previous first
6688      byte, set it from this character, but revert to none on a zero repeat.      byte, set it from this character, but revert to none on a zero repeat.
6689      Otherwise, leave the firstbyte value alone, and don't change it on a zero      Otherwise, leave the firstchar value alone, and don't change it on a zero
6690      repeat. */      repeat. */
6691    
6692      if (firstbyte == REQ_UNSET)      if (firstchar == REQ_UNSET)
6693        {        {
6694        zerofirstbyte = REQ_NONE;        zerofirstchar = REQ_NONE;
6695        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6696    
6697        /* If the character is more than one byte long, we can set firstbyte        /* If the character is more than one byte long, we can set firstchar
6698        only if it is not to be matched caselessly. */        only if it is not to be matched caselessly. */
6699    
6700        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6701          {          {
6702          firstbyte = mcbuffer[0] | req_caseopt;          firstchar = mcbuffer[0] | req_caseopt;
6703          if (mclength != 1) reqbyte = code[-1] | cd->req_varyopt;          if (mclength != 1) reqchar = code[-1] | cd->req_varyopt;
6704          }          }
6705        else firstbyte = reqbyte = REQ_NONE;        else firstchar = reqchar = REQ_NONE;
6706        }        }
6707    
6708      /* firstbyte was previously set; we can set reqbyte only if the length is      /* firstchar was previously set; we can set reqchar only if the length is
6709      1 or the matching is caseful. */      1 or the matching is caseful. */
6710    
6711      else      else
6712        {        {
6713        zerofirstbyte = firstbyte;        zerofirstchar = firstchar;
6714        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
6715        if (mclength == 1 || req_caseopt == 0)        if (mclength == 1 || req_caseopt == 0)
6716          reqbyte = code[-1] | req_caseopt | cd->req_varyopt;          reqchar = code[-1] | req_caseopt | cd->req_varyopt;
6717        }        }
6718    
6719      break;            /* End of literal character handling */      break;            /* End of literal character handling */
# Line 6598  Arguments: Line 6753  Arguments:
6753    reset_bracount TRUE to reset the count for each branch    reset_bracount TRUE to reset the count for each branch
6754    skipbytes      skip this many bytes at start (for brackets and OP_COND)    skipbytes      skip this many bytes at start (for brackets and OP_COND)
6755    cond_depth     depth of nesting for conditional subpatterns    cond_depth     depth of nesting for conditional subpatterns
6756    firstbyteptr   place to put the first required character, or a negative number    firstcharptr   place to put the first required character, or a negative number
6757    reqbyteptr     place to put the last required character, or a negative number    reqcharptr     place to put the last required character, or a negative number
6758    bcptr          pointer to the chain of currently open branches    bcptr          pointer to the chain of currently open branches
6759    cd             points to the data block with tables pointers etc.    cd             points to the data block with tables pointers etc.
6760    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
# Line 6609  Returns:         TRUE on success Line 6764  Returns:         TRUE on success
6764  */  */
6765    
6766  static BOOL  static BOOL
6767  compile_regex(int options, uschar **codeptr, const uschar **ptrptr,  compile_regex(int options, pcre_uchar **codeptr, const pcre_uchar **ptrptr,
6768    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,    int *errorcodeptr, BOOL lookbehind, BOOL reset_bracount, int skipbytes,
6769    int cond_depth, int *firstbyteptr, int *reqbyteptr, branch_chain *bcptr,    int cond_depth, pcre_int32 *firstcharptr, pcre_int32 *reqcharptr,
6770    compile_data *cd, int *lengthptr)    branch_chain *bcptr, compile_data *cd, int *lengthptr)
6771  {  {
6772  const uschar *ptr = *ptrptr;  const pcre_uchar *ptr = *ptrptr;
6773  uschar *code = *codeptr;  pcre_uchar *code = *codeptr;
6774  uschar *last_branch = code;  pcre_uchar *last_branch = code;
6775  uschar *start_bracket = code;  pcre_uchar *start_bracket = code;
6776  uschar *reverse_count = NULL;  pcre_uchar *reverse_count = NULL;
6777  open_capitem capitem;  open_capitem capitem;
6778  int capnumber = 0;  int capnumber = 0;
6779  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
6780  int branchfirstbyte, branchreqbyte;  pcre_int32 branchfirstchar, branchreqchar;
6781  int length;  int length;
6782  int orig_bracount;  int orig_bracount;
6783  int max_bracount;  int max_bracount;
# Line 6631  branch_chain bc; Line 6786  branch_chain bc;
6786  bc.outer = bcptr;  bc.outer = bcptr;
6787  bc.current_branch = code;  bc.current_branch = code;
6788    
6789  firstbyte = reqbyte = REQ_UNSET;  firstchar = reqchar = REQ_UNSET;
6790    
6791  /* 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
6792  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 6690  for (;;) Line 6845  for (;;)
6845    /* Now compile the branch; in the pre-compile phase its length gets added    /* Now compile the branch; in the pre-compile phase its length gets added
6846    into the length. */    into the length. */
6847    
6848    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstbyte,    if (!compile_branch(&options, &code, &ptr, errorcodeptr, &branchfirstchar,
6849          &branchreqbyte, &bc, cond_depth, cd,          &branchreqchar, &bc, cond_depth, cd,
6850          (lengthptr == NULL)? NULL : &length))          (lengthptr == NULL)? NULL : &length))
6851      {      {
6852      *ptrptr = ptr;      *ptrptr = ptr;
# Line 6707  for (;;) Line 6862  for (;;)
6862    
6863    if (lengthptr == NULL)    if (lengthptr == NULL)
6864      {      {
6865      /* If this is the first branch, the firstbyte and reqbyte values for the      /* If this is the first branch, the firstchar and reqchar values for the
6866      branch become the values for the regex. */      branch become the values for the regex. */
6867    
6868      if (*last_branch != OP_ALT)      if (*last_branch != OP_ALT)
6869        {        {
6870        firstbyte = branchfirstbyte;        firstchar = branchfirstchar;
6871        reqbyte = branchreqbyte;        reqchar = branchreqchar;
6872        }        }
6873    
6874      /* If this is not the first branch, the first char and reqbyte have to      /* If this is not the first branch, the first char and reqchar have to
6875      match the values from all the previous branches, except that if the      match the values from all the previous branches, except that if the
6876      previous value for reqbyte didn't have REQ_VARY set, it can still match,      previous value for reqchar didn't have REQ_VARY set, it can still match,
6877      and we set REQ_VARY for the regex. */      and we set REQ_VARY for the regex. */
6878    
6879      else      else
6880        {        {
6881        /* If we previously had a firstbyte, but it doesn't match the new branch,        /* If we previously had a firstchar, but it doesn't match the new branch,
6882        we have to abandon the firstbyte for the regex, but if there was        we have to abandon the firstchar for the regex, but if there was
6883        previously no reqbyte, it takes on the value of the old firstbyte. */        previously no reqchar, it takes on the value of the old firstchar. */
6884    
6885        if (firstbyte >= 0 && firstbyte != branchfirstbyte)        if (firstchar >= 0 && firstchar != branchfirstchar)
6886          {          {
6887          if (reqbyte < 0) reqbyte = firstbyte;          if (reqchar < 0) reqchar = firstchar;
6888          firstbyte = REQ_NONE;          firstchar = REQ_NONE;
6889          }          }
6890    
6891        /* If we (now or from before) have no firstbyte, a firstbyte from the        /* If we (now or from before) have no firstchar, a firstchar from the
6892        branch becomes a reqbyte if there isn't a branch reqbyte. */        branch becomes a reqchar if there isn't a branch reqchar. */
6893    
6894        if (firstbyte < 0 && branchfirstbyte >= 0 && branchreqbyte < 0)        if (firstchar < 0 && branchfirstchar >= 0 && branchreqchar < 0)
6895            branchreqbyte = branchfirstbyte;            branchreqchar = branchfirstchar;
6896    
6897        /* Now ensure that the reqbytes match */        /* Now ensure that the reqchars match */
6898    
6899        if ((reqbyte & ~REQ_VARY) != (branchreqbyte & ~REQ_VARY))        if ((reqchar & ~REQ_VARY) != (branchreqchar & ~REQ_VARY))
6900          reqbyte = REQ_NONE;          reqchar = REQ_NONE;
6901        else reqbyte |= branchreqbyte;   /* To "or" REQ_VARY */        else reqchar |= branchreqchar;   /* To "or" REQ_VARY */
6902        }        }
6903    
6904      /* 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 6813  for (;;) Line 6968  for (;;)
6968        if (cd->open_caps->flag)        if (cd->open_caps->flag)
6969          {          {
6970          memmove(start_bracket + 1 + LINK_SIZE, start_bracket,          memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
6971            code - start_bracket);            IN_UCHARS(code - start_bracket));
6972          *start_bracket = OP_ONCE;          *start_bracket = OP_ONCE;
6973          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
6974          PUT(start_bracket, 1, (int)(code - start_bracket));          PUT(start_bracket, 1, (int)(code - start_bracket));
# Line 6833  for (;;) Line 6988  for (;;)
6988    
6989      *codeptr = code;      *codeptr = code;
6990      *ptrptr = ptr;      *ptrptr = ptr;
6991      *firstbyteptr = firstbyte;      *firstcharptr = firstchar;
6992      *reqbyteptr = reqbyte;      *reqcharptr = reqchar;
6993      if (lengthptr != NULL)      if (lengthptr != NULL)
6994        {        {
6995        if (OFLOW_MAX - *lengthptr < length)        if (OFLOW_MAX - *lengthptr < length)
# Line 6915  Returns:     TRUE or FALSE Line 7070  Returns:     TRUE or FALSE
7070  */  */
7071    
7072  static BOOL  static BOOL
7073  is_anchored(register const uschar *code, unsigned int bracket_map,  is_anchored(register const pcre_uchar *code, unsigned int bracket_map,
7074    unsigned int backref_map)    unsigned int backref_map)
7075  {  {
7076  do {  do {
7077     const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code],     const pcre_uchar *scode = first_significant_code(
7078       FALSE);       code + PRIV(OP_lengths)[*code], FALSE);
7079     register int op = *scode;     register int op = *scode;
7080    
7081     /* Non-capturing brackets */     /* Non-capturing brackets */
# Line 6992  Returns:         TRUE or FALSE Line 7147  Returns:         TRUE or FALSE
7147  */  */
7148    
7149  static BOOL  static BOOL
7150  is_startline(const uschar *code, unsigned int bracket_map,  is_startline(const pcre_uchar *code, unsigned int bracket_map,
7151    unsigned int backref_map)    unsigned int backref_map)
7152  {  {
7153  do {  do {
7154     const uschar *scode = first_significant_code(code + _pcre_OP_lengths[*code],     const pcre_uchar *scode = first_significant_code(
7155       FALSE);       code + PRIV(OP_lengths)[*code], FALSE);
7156     register int op = *scode;     register int op = *scode;
7157    
7158     /* If we are at the start of a conditional assertion group, *both* the     /* If we are at the start of a conditional assertion group, *both* the
# Line 7008  do { Line 7163  do {
7163     if (op == OP_COND)     if (op == OP_COND)
7164       {       {
7165       scode += 1 + LINK_SIZE;       scode += 1 + LINK_SIZE;
7166       if (*scode == OP_CALLOUT) scode += _pcre_OP_lengths[OP_CALLOUT];       if (*scode == OP_CALLOUT) scode += PRIV(OP_lengths)[OP_CALLOUT];
7167       switch (*scode)       switch (*scode)
7168         {         {
7169         case OP_CREF:         case OP_CREF:
# Line 7095  Returns:     -1 or the fixed first char Line 7250  Returns:     -1 or the fixed first char
7250  */  */
7251    
7252  static int  static int
7253  find_firstassertedchar(const uschar *code, BOOL inassert)  find_firstassertedchar(const pcre_uchar *code, BOOL inassert)
7254  {  {
7255  register int c = -1;  register int c = -1;
7256  do {  do {
7257     int d;     int d;
7258     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||     int xl = (*code == OP_CBRA || *code == OP_SCBRA ||
7259               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? 2:0;               *code == OP_CBRAPOS || *code == OP_SCBRAPOS)? IMM2_SIZE:0;
7260     const uschar *scode = first_significant_code(code + 1+LINK_SIZE + xl, TRUE);     const pcre_uchar *scode = first_significant_code(code + 1+LINK_SIZE + xl,
7261         TRUE);
7262     register int op = *scode;     register int op = *scode;
7263    
7264     switch(op)     switch(op)
# Line 7126  do { Line 7282  do {
7282       break;       break;
7283    
7284       case OP_EXACT:       case OP_EXACT:
7285       scode += 2;       scode += IMM2_SIZE;
7286       /* Fall through */       /* Fall through */
7287    
7288       case OP_CHAR:       case OP_CHAR:
# Line 7139  do { Line 7295  do {
7295       break;       break;
7296    
7297       case OP_EXACTI:       case OP_EXACTI:
7298       scode += 2;       scode += IMM2_SIZE;
7299       /* Fall through */       /* Fall through */
7300    
7301       case OP_CHARI:       case OP_CHARI:
# Line 7182  Returns:        pointer to compiled data Line 7338  Returns:        pointer to compiled data
7338                  with errorptr and erroroffset set                  with errorptr and erroroffset set
7339  */  */
7340    
7341    #ifdef COMPILE_PCRE8
7342  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7343  pcre_compile(const char *pattern, int options, const char **errorptr,  pcre_compile(const char *pattern, int options, const char **errorptr,
7344    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
7345    #else
7346    PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7347    pcre16_compile(PCRE_SPTR16 pattern, int options, const char **errorptr,
7348      int *erroroffset, const unsigned char *tables)
7349    #endif
7350  {  {
7351    #ifdef COMPILE_PCRE8
7352  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);  return pcre_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7353    #else
7354    return pcre16_compile2(pattern, options, NULL, errorptr, erroroffset, tables);
7355    #endif
7356  }  }
7357    
7358    
7359    #ifdef COMPILE_PCRE8
7360  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION  PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7361  pcre_compile2(const char *pattern, int options, int *errorcodeptr,  pcre_compile2(const char *pattern, int options, int *errorcodeptr,
7362    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
7363    #else
7364    PCRE_EXP_DEFN pcre * PCRE_CALL_CONVENTION
7365    pcre16_compile2(PCRE_SPTR16 pattern, int options, int *errorcodeptr,
7366      const char **errorptr, int *erroroffset, const unsigned char *tables)
7367    #endif
7368  {  {
7369  real_pcre *re;  real_pcre *re;
7370  int length = 1;  /* For final END opcode */  int length = 1;  /* For final END opcode */
7371  int firstbyte, reqbyte, newline;  pcre_int32 firstchar, reqchar;
7372    int newline;
7373  int errorcode = 0;  int errorcode = 0;
7374  int skipatstart = 0;  int skipatstart = 0;
7375  BOOL utf8;  BOOL utf;
7376  size_t size;  size_t size;
7377  uschar *code;  pcre_uchar *code;
7378  const uschar *codestart;  const pcre_uchar *codestart;
7379  const uschar *ptr;  const pcre_uchar *ptr;
7380  compile_data compile_block;  compile_data compile_block;
7381  compile_data *cd = &compile_block;  compile_data *cd = &compile_block;
7382    
# Line 7213  as soon as possible, so that a fairly la Line 7386  as soon as possible, so that a fairly la
7386  this purpose. The same space is used in the second phase for remembering where  this purpose. The same space is used in the second phase for remembering where
7387  to fill in forward references to subpatterns. */  to fill in forward references to subpatterns. */
7388    
7389  uschar cworkspace[COMPILE_WORK_SIZE];  pcre_uchar cworkspace[COMPILE_WORK_SIZE];
7390    
7391  /* Set this early so that early errors get offset 0. */  /* Set this early so that early errors get offset 0. */
7392    
7393  ptr = (const uschar *)pattern;  ptr = (const pcre_uchar *)pattern;
7394    
7395  /* We can't pass back an error message if errorptr is NULL; I guess the best we  /* We can't pass back an error message if errorptr is NULL; I guess the best we
7396  can do is just return NULL, but we can set a code value if there is a code  can do is just return NULL, but we can set a code value if there is a code
# Line 7244  if (erroroffset == NULL) Line 7417  if (erroroffset == NULL)
7417    
7418  /* Set up pointers to the individual character tables */  /* Set up pointers to the individual character tables */
7419    
7420  if (tables == NULL) tables = _pcre_default_tables;  if (tables == NULL) tables = PRIV(default_tables);
7421  cd->lcc = tables + lcc_offset;  cd->lcc = tables + lcc_offset;
7422  cd->fcc = tables + fcc_offset;  cd->fcc = tables + fcc_offset;
7423  cd->cbits = tables + cbits_offset;  cd->cbits = tables + cbits_offset;
# Line 7267  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7440  while (ptr[skipatstart] == CHAR_LEFT_PAR
7440    int newnl = 0;    int newnl = 0;
7441    int newbsr = 0;    int newbsr = 0;
7442    
7443    if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UTF8_RIGHTPAR, 5) == 0)
7444      { skipatstart += 7; options |= PCRE_UTF8; continue; }      { skipatstart += 7; options |= PCRE_UTF8; continue; }
7445    else if (strncmp((char *)(ptr+skipatstart+2), STRING_UCP_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_UCP_RIGHTPAR, 4) == 0)
7446      { skipatstart += 6; options |= PCRE_UCP; continue; }      { skipatstart += 6; options |= PCRE_UCP; continue; }
7447    else if (strncmp((char *)(ptr+skipatstart+2), STRING_NO_START_OPT_RIGHTPAR, 13) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_NO_START_OPT_RIGHTPAR, 13) == 0)
7448      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }      { skipatstart += 15; options |= PCRE_NO_START_OPTIMIZE; continue; }
7449    
7450    if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)    if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CR_RIGHTPAR, 3) == 0)
7451      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
7452    else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_LF_RIGHTPAR, 3)  == 0)
7453      { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }      { skipatstart += 5; newnl = PCRE_NEWLINE_LF; }
7454    else if (strncmp((char *)(ptr+skipatstart+2), STRING_CRLF_RIGHTPAR, 5)  == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_CRLF_RIGHTPAR, 5)  == 0)
7455      { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }      { skipatstart += 7; newnl = PCRE_NEWLINE_CR + PCRE_NEWLINE_LF; }
7456    else if (strncmp((char *)(ptr+skipatstart+2), STRING_ANY_RIGHTPAR, 4) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_ANY_RIGHTPAR, 4) == 0)
7457      { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }      { skipatstart += 6; newnl = PCRE_NEWLINE_ANY; }
7458    else if (strncmp((char *)(ptr+skipatstart+2), STRING_ANYCRLF_RIGHTPAR, 8) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_ANYCRLF_RIGHTPAR, 8) == 0)
7459      { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }      { skipatstart += 10; newnl = PCRE_NEWLINE_ANYCRLF; }
7460    
7461    else if (strncmp((char *)(ptr+skipatstart+2), STRING_BSR_ANYCRLF_RIGHTPAR, 12) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_BSR_ANYCRLF_RIGHTPAR, 12) == 0)
7462      { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }      { skipatstart += 14; newbsr = PCRE_BSR_ANYCRLF; }
7463    else if (strncmp((char *)(ptr+skipatstart+2), STRING_BSR_UNICODE_RIGHTPAR, 12) == 0)    else if (STRNCMP_UC_C8(ptr+skipatstart+2, STRING_BSR_UNICODE_RIGHTPAR, 12) == 0)
7464      { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }      { skipatstart += 14; newbsr = PCRE_BSR_UNICODE; }
7465    
7466    if (newnl != 0)    if (newnl != 0)
# Line 7297  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 7470  while (ptr[skipatstart] == CHAR_LEFT_PAR
7470    else break;    else break;
7471    }    }
7472    
7473  utf8 = (options & PCRE_UTF8) != 0;  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
7474    utf = (options & PCRE_UTF8) != 0;
7475    
7476  /* Can't support UTF8 unless PCRE has been compiled to include the code. The  /* Can't support UTF8 unless PCRE has been compiled to include the code. The
7477  return of an error code from _pcre_valid_utf8() is a new feature, introduced in  return of an error code from PRIV(valid_utf)() is a new feature, introduced in
7478  release 8.13. It is passed back from pcre_[dfa_]exec(), but at the moment is  release 8.13. It is passed back from pcre_[dfa_]exec(), but at the moment is
7479  not used here. */  not used here. */
7480    
7481  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
7482  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf && (options & PCRE_NO_UTF8_CHECK) == 0 &&
7483       (errorcode = _pcre_valid_utf8((USPTR)pattern, -1, erroroffset)) != 0)       (errorcode = PRIV(valid_utf)((PCRE_PUCHAR)pattern, -1, erroroffset)) != 0)
7484    {    {
7485    errorcode = ERR44;    errorcode = ERR44;
7486    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
7487    }    }
7488  #else  #else
7489  if (utf8)  if (utf)
7490    {    {
7491    errorcode = ERR32;    errorcode = ERR32;
7492    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
# Line 7388  cd->backref_map = 0; Line 7562  cd->backref_map = 0;
7562  /* Reflect pattern for debugging output */  /* Reflect pattern for debugging output */
7563    
7564  DPRINTF(("------------------------------------------------------------------\n"));  DPRINTF(("------------------------------------------------------------------\n"));
7565  DPRINTF(("%s\n", pattern));  #ifdef PCRE_DEBUG
7566    print_puchar(stdout, (PCRE_PUCHAR)pattern);
7567    #endif
7568    DPRINTF(("\n"));
7569    
7570  /* Pretend to compile the pattern while actually just accumulating the length  /* Pretend to compile the pattern while actually just accumulating the length
7571  of memory required. This behaviour is triggered by passing a non-NULL final  of memory required. This behaviour is triggered by passing a non-NULL final
# Line 7404  cd->name_table = NULL; Line 7581  cd->name_table = NULL;
7581  cd->start_workspace = cworkspace;  cd->start_workspace = cworkspace;
7582  cd->start_code = cworkspace;  cd->start_code = cworkspace;
7583  cd->hwm = cworkspace;  cd->hwm = cworkspace;
7584  cd->start_pattern = (const uschar *)pattern;  cd->start_pattern = (const pcre_uchar *)pattern;
7585  cd->end_pattern = (const uschar *)(pattern + strlen(pattern));  cd->end_pattern = (const pcre_uchar *)(pattern + STRLEN_UC((const pcre_uchar *)pattern));
7586  cd->req_varyopt = 0;  cd->req_varyopt = 0;
7587  cd->external_options = options;  cd->external_options = options;
7588  cd->external_flags = 0;  cd->external_flags = 0;
# Line 7421  ptr += skipatstart; Line 7598  ptr += skipatstart;
7598  code = cworkspace;  code = cworkspace;
7599  *code = OP_BRA;  *code = OP_BRA;
7600  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,  (void)compile_regex(cd->external_options, &code, &ptr, &errorcode, FALSE,
7601    FALSE, 0, 0, &firstbyte, &reqbyte, NULL, cd, &length);    FALSE, 0, 0, &firstchar, &reqchar, NULL, cd, &length);
7602  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;  if (errorcode != 0) goto PCRE_EARLY_ERROR_RETURN;
7603    
7604  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,  DPRINTF(("end pre-compile: length=%d workspace=%d\n", length,
7605    cd->hwm - cworkspace));    (int)(cd->hwm - cworkspace)));
7606    
7607  if (length > MAX_PATTERN_SIZE)  if (length > MAX_PATTERN_SIZE)
7608    {    {
# Line 7438  externally provided function. Integer ov Line 7615  externally provided function. Integer ov
7615  because nowadays we limit the maximum value of cd->names_found and  because nowadays we limit the maximum value of cd->names_found and
7616  cd->name_entry_size. */  cd->name_entry_size. */
7617    
7618  size = length + sizeof(real_pcre) + cd->names_found * (cd->name_entry_size + 3);  size = sizeof(real_pcre) + (length + cd->names_found * (cd->name_entry_size + 3)) * sizeof(pcre_uchar);
7619  re = (real_pcre *)(pcre_malloc)(size);  re = (real_pcre *)(pcre_malloc)(size);
7620    
7621  if (re == NULL)  if (re == NULL)
# Line 7458  re->size = (int)size; Line 7635  re->size = (int)size;
7635  re->options = cd->external_options;  re->options = cd->external_options;
7636  re->flags = cd->external_flags;  re->flags = cd->external_flags;
7637  re->dummy1 = 0;  re->dummy1 = 0;
7638  re->first_byte = 0;  re->first_char = 0;
7639  re->req_byte = 0;  re->req_char = 0;
7640  re->name_table_offset = sizeof(real_pcre);  re->name_table_offset = sizeof(real_pcre) / sizeof(pcre_uchar);
7641  re->name_entry_size = cd->name_entry_size;  re->name_entry_size = cd->name_entry_size;
7642  re->name_count = cd->names_found;  re->name_count = cd->names_found;
7643  re->ref_count = 0;  re->ref_count = 0;
7644  re->tables = (tables == _pcre_default_tables)? NULL : tables;  re->tables = (tables == PRIV(default_tables))? NULL : tables;
7645  re->nullpad = NULL;  re->nullpad = NULL;
7646    
7647  /* The starting points of the name/number translation table and of the code are  /* The starting points of the name/number translation table and of the code are
# Line 7478  cd->final_bracount = cd->bracount;  /* S Line 7655  cd->final_bracount = cd->bracount;  /* S
7655  cd->assert_depth = 0;  cd->assert_depth = 0;
7656  cd->bracount = 0;  cd->bracount = 0;
7657  cd->names_found = 0;  cd->names_found = 0;
7658  cd->name_table = (uschar *)re + re->name_table_offset;  cd->name_table = (pcre_uchar *)re + re->name_table_offset;
7659  codestart = cd->name_table + re->name_entry_size * re->name_count;  codestart = cd->name_table + re->name_entry_size * re->name_count;
7660  cd->start_code = codestart;  cd->start_code = codestart;
7661  cd->hwm = cworkspace;  cd->hwm = cworkspace;
# Line 7491  cd->open_caps = NULL; Line 7668  cd->open_caps = NULL;
7668  error, errorcode will be set non-zero, so we don't need to look at the result  error, errorcode will be set non-zero, so we don't need to look at the result
7669  of the function here. */  of the function here. */
7670    
7671  ptr = (const uschar *)pattern + skipatstart;  ptr = (const pcre_uchar *)pattern + skipatstart;
7672  code = (uschar *)codestart;  code = (pcre_uchar *)codestart;
7673  *code = OP_BRA;  *code = OP_BRA;
7674  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,  (void)compile_regex(re->options, &code, &ptr, &errorcode, FALSE, FALSE, 0, 0,
7675    &firstbyte, &reqbyte, NULL, cd, NULL);    &firstchar, &reqchar, NULL, cd, NULL);
7676  re->top_bracket = cd->bracount;  re->top_bracket = cd->bracount;
7677  re->top_backref = cd->top_backref;  re->top_backref = cd->top_backref;
7678  re->flags = cd->external_flags;  re->flags = cd->external_flags;
7679    
7680  if (cd->had_accept) reqbyte = REQ_NONE;   /* Must disable after (*ACCEPT) */  if (cd->had_accept) reqchar = REQ_NONE;   /* Must disable after (*ACCEPT) */
7681    
7682  /* If not reached end of pattern on success, there's an excess bracket. */  /* If not reached end of pattern on success, there's an excess bracket. */
7683    
# Line 7520  if (code - codestart > length) errorcode Line 7697  if (code - codestart > length) errorcode
7697  while (errorcode == 0 && cd->hwm > cworkspace)  while (errorcode == 0 && cd->hwm > cworkspace)
7698    {    {
7699    int offset, recno;    int offset, recno;
7700    const uschar *groupptr;    const pcre_uchar *groupptr;
7701    cd->hwm -= LINK_SIZE;    cd->hwm -= LINK_SIZE;
7702    offset = GET(cd->hwm, 0);    offset = GET(cd->hwm, 0);
7703    recno = GET(codestart, offset);    recno = GET(codestart, offset);
7704    groupptr = _pcre_find_bracket(codestart, utf8, recno);    groupptr = PRIV(find_bracket)(codestart, utf, recno);
7705    if (groupptr == NULL) errorcode = ERR53;    if (groupptr == NULL) errorcode = ERR53;
7706      else PUT(((uschar *)codestart), offset, (int)(groupptr - codestart));      else PUT(((pcre_uchar *)codestart), offset, (int)(groupptr - codestart));
7707    }    }
7708    
7709  /* Give an error if there's back reference to a non-existent capturing  /* Give an error if there's back reference to a non-existent capturing
# Line 7544  length, and set their lengths. */ Line 7721  length, and set their lengths. */
7721    
7722  if (cd->check_lookbehind)  if (cd->check_lookbehind)
7723    {    {
7724    uschar *cc = (uschar *)codestart;    pcre_uchar *cc = (pcre_uchar *)codestart;
7725    
7726    /* Loop, searching for OP_REVERSE items, and process those that do not have    /* Loop, searching for OP_REVERSE items, and process those that do not have
7727    their length set. (Actually, it will also re-process any that have a length    their length set. (Actually, it will also re-process any that have a length
7728    of zero, but that is a pathological case, and it does no harm.) When we find    of zero, but that is a pathological case, and it does no harm.) When we find
7729    one, we temporarily terminate the branch it is in while we scan it. */    one, we temporarily terminate the branch it is in while we scan it. */
7730    
7731    for (cc = (uschar *)_pcre_find_bracket(codestart, utf8, -1);    for (cc = (pcre_uchar *)PRIV(find_bracket)(codestart, utf, -1);
7732         cc != NULL;         cc != NULL;
7733         cc = (uschar *)_pcre_find_bracket(cc, utf8, -1))         cc = (pcre_uchar *)PRIV(find_bracket)(cc, utf, -1))
7734      {      {
7735      if (GET(cc, 1) == 0)      if (GET(cc, 1) == 0)
7736        {        {
7737        int fixed_length;        int fixed_length;
7738        uschar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE);        pcre_uchar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE);
7739        int end_op = *be;        int end_op = *be;
7740        *be = OP_END;        *be = OP_END;
7741        fixed_length = find_fixedlength(cc, (re->options & PCRE_UTF8) != 0, TRUE,        fixed_length = find_fixedlength(cc, (re->options & PCRE_UTF8) != 0, TRUE,
# Line 7583  if (errorcode != 0) Line 7760  if (errorcode != 0)
7760    {    {
7761    (pcre_free)(re);    (pcre_free)(re);
7762    PCRE_EARLY_ERROR_RETURN:    PCRE_EARLY_ERROR_RETURN:
7763    *erroroffset = (int)(ptr - (const uschar *)pattern);    *erroroffset = (int)(ptr - (const pcre_uchar *)pattern);
7764    PCRE_EARLY_ERROR_RETURN2:    PCRE_EARLY_ERROR_RETURN2:
7765    *errorptr = find_error_text(errorcode);    *errorptr = find_error_text(errorcode);
7766    if (errorcodeptr != NULL) *errorcodeptr = errorcode;    if (errorcodeptr != NULL) *errorcodeptr = errorcode;
# Line 7606  if ((re->options & PCRE_ANCHORED) == 0) Line 7783  if ((re->options & PCRE_ANCHORED) == 0)
7783      re->options |= PCRE_ANCHORED;      re->options |= PCRE_ANCHORED;
7784    else    else
7785      {      {
7786      if (firstbyte < 0)      if (firstchar < 0)
7787        firstbyte = find_firstassertedchar(codestart, FALSE);        firstchar = find_firstassertedchar(codestart, FALSE);
7788      if (firstbyte >= 0)   /* Remove caseless flag for non-caseable chars */      if (firstchar >= 0)   /* Remove caseless flag for non-caseable chars */
7789        {        {
7790        int ch = firstbyte & 255;  #ifdef COMPILE_PCRE8
7791        re->first_byte = ((firstbyte & REQ_CASELESS) != 0 &&        re->first_char = firstchar & 0xff;
7792           cd->fcc[ch] == ch)? ch : firstbyte;  #else
7793    #ifdef COMPILE_PCRE16
7794          re->first_char = firstchar & 0xffff;
7795    #endif
7796    #endif
7797          if ((firstchar & REQ_CASELESS) != 0)
7798            {
7799    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
7800            /* We ignore non-ASCII first chars in 8 bit mode. */
7801            if (utf)
7802              {
7803              if (re->first_char < 128)
7804                {
7805                if (cd->fcc[re->first_char] != re->first_char)
7806                  re->flags |= PCRE_FCH_CASELESS;
7807                }
7808              else if ((options & PCRE_UCP) != 0
7809                  && UCD_OTHERCASE(re->first_char) != re->first_char)
7810                re->flags |= PCRE_FCH_CASELESS;
7811              }
7812            else
7813    #endif
7814            if (MAX_255(re->first_char)
7815                && cd->fcc[re->first_char] != re->first_char)
7816              re->flags |= PCRE_FCH_CASELESS;
7817            }
7818    
7819        re->flags |= PCRE_FIRSTSET;        re->flags |= PCRE_FIRSTSET;
7820        }        }
7821      else if (is_startline(codestart, 0, cd->backref_map))      else if (is_startline(codestart, 0, cd->backref_map))
# Line 7624  if ((re->options & PCRE_ANCHORED) == 0) Line 7827  if ((re->options & PCRE_ANCHORED) == 0)
7827  variable length item in the regex. Remove the caseless flag for non-caseable  variable length item in the regex. Remove the caseless flag for non-caseable
7828  bytes. */  bytes. */
7829    
7830  if (reqbyte >= 0 &&  if (reqchar >= 0 &&
7831       ((re->options & PCRE_ANCHORED) == 0 || (reqbyte & REQ_VARY) != 0))       ((re->options & PCRE_ANCHORED) == 0 || (reqchar & REQ_VARY) != 0))
7832    {    {
7833    int ch = reqbyte & 255;  #ifdef COMPILE_PCRE8
7834    re->req_byte = ((reqbyte & REQ_CASELESS) != 0 &&    re->req_char = reqchar & 0xff;
7835      cd->fcc[ch] == ch)? (reqbyte & ~REQ_CASELESS) : reqbyte;  #else
7836    #ifdef COMPILE_PCRE16
7837      re->req_char = reqchar & 0xffff;
7838    #endif
7839    #endif
7840      if ((reqchar & REQ_CASELESS) != 0)
7841        {
7842    #if defined SUPPORT_UCP && !(defined COMPILE_PCRE8)
7843        /* We ignore non-ASCII first chars in 8 bit mode. */
7844        if (utf)
7845          {
7846          if (re->first_char < 128)
7847            {
7848            if (cd->fcc[re->first_char] != re->first_char)
7849              re->flags |= PCRE_RCH_CASELESS;
7850            }
7851          else if ((options & PCRE_UCP) != 0
7852              && UCD_OTHERCASE(re->first_char) != re->first_char)
7853            re->flags |= PCRE_RCH_CASELESS;
7854          }
7855        else
7856    #endif
7857        if (MAX_255(re->req_char) && cd->fcc[re->req_char] != re->req_char)
7858          re->flags |= PCRE_RCH_CASELESS;
7859        }
7860    
7861    re->flags |= PCRE_REQCHSET;    re->flags |= PCRE_REQCHSET;
7862    }    }
7863    
# Line 7644  printf("Options=%08x\n", re->options); Line 7872  printf("Options=%08x\n", re->options);
7872    
7873  if ((re->flags & PCRE_FIRSTSET) != 0)  if ((re->flags & PCRE_FIRSTSET) != 0)
7874    {    {
7875    int ch = re->first_byte & 255;    pcre_uchar ch = re->first_char;
7876    const char *caseless = ((re->first_byte & REQ_CASELESS) == 0)?    const char *caseless =
7877      "" : " (caseless)";      ((re->flags & PCRE_FCH_CASELESS) == 0)? "" : " (caseless)";
7878    if (isprint(ch)) printf("First char = %c%s\n", ch, caseless);    if (PRINTABLE(ch)) printf("First char = %c%s\n", ch, caseless);
7879      else printf("First char = \\x%02x%s\n", ch, caseless);      else printf("First char = \\x%02x%s\n", ch, caseless);
7880    }    }
7881    
7882  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
7883    {    {
7884    int ch = re->req_byte & 255;    pcre_uchar ch = re->req_char;
7885    const char *caseless = ((re->req_byte & REQ_CASELESS) == 0)?    const char *caseless =
7886      "" : " (caseless)";      ((re->flags & PCRE_RCH_CASELESS) == 0)? "" : " (caseless)";
7887    if (isprint(ch)) printf("Req char = %c%s\n", ch, caseless);    if (PRINTABLE(ch)) printf("Req char = %c%s\n", ch, caseless);
7888      else printf("Req char = \\x%02x%s\n", ch, caseless);      else printf("Req char = \\x%02x%s\n", ch, caseless);
7889    }    }
7890    
# Line 7669  if (code - codestart > length) Line 7897  if (code - codestart > length)
7897    {    {
7898    (pcre_free)(re);    (pcre_free)(re);
7899    *errorptr = find_error_text(ERR23);    *errorptr = find_error_text(ERR23);
7900    *erroroffset = ptr - (uschar *)pattern;    *erroroffset = ptr - (pcre_uchar *)pattern;
7901    if (errorcodeptr != NULL) *errorcodeptr = ERR23;    if (errorcodeptr != NULL) *errorcodeptr = ERR23;
7902    return NULL;    return NULL;
7903    }    }

Legend:
Removed from v.749  
changed lines
  Added in v.785

  ViewVC Help
Powered by ViewVC 1.1.5