/[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 598 by ph10, Sat May 7 15:37:31 2011 UTC code/branches/pcre16/pcre_compile.c revision 795 by zherczeg, Sat Dec 10 02:20:06 2011 UTC
# Line 97  overrun before it actually does run off Line 97  overrun before it actually does run off
97    
98  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)  #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)
99    
100    /* Private flags added to firstchar and reqchar. */
101    
102    #define REQ_CASELESS   0x10000000l      /* Indicates caselessness */
103    #define REQ_VARY       0x20000000l      /* Reqchar followed non-literal item */
104    
105    /* Repeated character flags. */
106    
107    #define UTF_LENGTH     0x10000000l      /* The char contains its length. */
108    
109  /* Table for handling escaped characters in the range '0'-'z'. Positive returns  /* Table for handling escaped characters in the range '0'-'z'. Positive returns
110  are simple data values; negative values are for special things like \d and so  are simple data values; negative values are for special things like \d and so
# Line 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 393  static const char error_texts[] = Line 455  static const char error_texts[] =
455    "internal error: previously-checked referenced subpattern not found\0"    "internal error: previously-checked referenced subpattern not found\0"
456    "DEFINE group contains more than one branch\0"    "DEFINE group contains more than one branch\0"
457    /* 55 */    /* 55 */
458    "repeating a DEFINE group is not allowed\0"    "repeating a DEFINE group is not allowed\0"  /** DEAD **/
459    "inconsistent NEWLINE options\0"    "inconsistent NEWLINE options\0"
460    "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"    "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"
461    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
# Line 409  static const char error_texts[] = Line 471  static const char error_texts[] =
471    "(*MARK) must have an argument\0"    "(*MARK) must have an argument\0"
472    "this version of PCRE is not compiled with PCRE_UCP support\0"    "this version of PCRE is not compiled with PCRE_UCP support\0"
473    "\\c must be followed by an ASCII character\0"    "\\c must be followed by an ASCII character\0"
474      "\\k is not followed by a braced, angle-bracketed, or quoted name\0"
475      /* 70 */
476      "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 427  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 471  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 506  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 545  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, int, uschar **, const uschar **, int *, BOOL, BOOL, 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 577  return s; Line 649  return s;
649    
650    
651  /*************************************************  /*************************************************
652    *            Check for counted repeat            *
653    *************************************************/
654    
655    /* This function is called when a '{' is encountered in a place where it might
656    start a quantifier. It looks ahead to see if it really is a quantifier or not.
657    It is only a quantifier if it is one of the forms {ddd} {ddd,} or {ddd,ddd}
658    where the ddds are digits.
659    
660    Arguments:
661      p         pointer to the first char after '{'
662    
663    Returns:    TRUE or FALSE
664    */
665    
666    static BOOL
667    is_counted_repeat(const pcre_uchar *p)
668    {
669    if (!IS_DIGIT(*p)) return FALSE;
670    p++;
671    while (IS_DIGIT(*p)) p++;
672    if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
673    
674    if (*p++ != CHAR_COMMA) return FALSE;
675    if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;
676    
677    if (!IS_DIGIT(*p)) return FALSE;
678    p++;
679    while (IS_DIGIT(*p)) p++;
680    
681    return (*p == CHAR_RIGHT_CURLY_BRACKET);
682    }
683    
684    
685    
686    /*************************************************
687  *            Handle escapes                      *  *            Handle escapes                      *
688  *************************************************/  *************************************************/
689    
# Line 601  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 620  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 632  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 642  else Line 753  else
753    
754      case CHAR_l:      case CHAR_l:
755      case CHAR_L:      case CHAR_L:
756        *errorcodeptr = ERR37;
757        break;
758    
759      case CHAR_u:      case CHAR_u:
760        if ((options & PCRE_JAVASCRIPT_COMPAT) != 0)
761          {
762          /* In JavaScript, \u must be followed by four hexadecimal numbers.
763          Otherwise it is a lowercase u letter. */
764          if (MAX_255(ptr[1]) && (digitab[ptr[1]] & ctype_xdigit) != 0
765            && 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;
770            for (i = 0; i < 4; ++i)
771              {
772              register int cc = *(++ptr);
773    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
774              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
775              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
776    #else           /* EBCDIC coding */
777              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
778              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
779    #endif
780              }
781            }
782          }
783        else
784          *errorcodeptr = ERR37;
785        break;
786    
787      case CHAR_U:      case CHAR_U:
788      *errorcodeptr = ERR37;      /* In JavaScript, \U is an uppercase U letter. */
789        if ((options & PCRE_JAVASCRIPT_COMPAT) == 0) *errorcodeptr = ERR37;
790      break;      break;
791    
792      /* \g must be followed by one of a number of specific things:      /* In a character class, \g is just a literal "g". Outside a character
793        class, \g must be followed by one of a number of specific things:
794    
795      (1) A number, either plain or braced. If positive, it is an absolute      (1) A number, either plain or braced. If positive, it is an absolute
796      backreference. If negative, it is a relative backreference. This is a Perl      backreference. If negative, it is a relative backreference. This is a Perl
# Line 664  else Line 807  else
807      the -ESC_g code (cf \k). */      the -ESC_g code (cf \k). */
808    
809      case CHAR_g:      case CHAR_g:
810        if (isclass) break;
811      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)      if (ptr[1] == CHAR_LESS_THAN_SIGN || ptr[1] == CHAR_APOSTROPHE)
812        {        {
813        c = -ESC_g;        c = -ESC_g;
# Line 674  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 694  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 747  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 784  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)
959          {
960          /* In JavaScript, \x must be followed by two hexadecimal numbers.
961          Otherwise it is a lowercase x letter. */
962          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;
966            for (i = 0; i < 2; ++i)
967              {
968              register int cc = *(++ptr);
969    #ifndef EBCDIC  /* ASCII/UTF-8 coding */
970              if (cc >= CHAR_a) cc -= 32;               /* Convert to upper case */
971              c = (c << 4) + cc - ((cc < CHAR_A)? CHAR_0 : (CHAR_A - 10));
972    #else           /* EBCDIC coding */
973              if (cc >= CHAR_a && cc <= CHAR_z) cc += 64;  /* Convert to upper case */
974              c = (c << 4) + cc - ((cc >= CHAR_0)? CHAR_0 : (CHAR_A - 10));
975    #endif
976              }
977            }
978          break;
979          }
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 811  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 827  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 885  else Line 1083  else
1083    }    }
1084    
1085  /* Perl supports \N{name} for character names, as well as plain \N for "not  /* Perl supports \N{name} for character names, as well as plain \N for "not
1086  newline". PCRE does not support \N{name}. */  newline". PCRE does not support \N{name}. However, it does support
1087    quantification such as \N{2,3}. */
1088    
1089  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET)  if (c == -ESC_N && ptr[1] == CHAR_LEFT_CURLY_BRACKET &&
1090         !is_counted_repeat(ptr+2))
1091    *errorcodeptr = ERR37;    *errorcodeptr = ERR37;
1092    
1093  /* If PCRE_UCP is set, we change the values for \d etc. */  /* If PCRE_UCP is set, we change the values for \d etc. */
# Line 923  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 968  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 997  return -1; Line 1197  return -1;
1197    
1198    
1199  /*************************************************  /*************************************************
 *            Check for counted repeat            *  
 *************************************************/  
   
 /* This function is called when a '{' is encountered in a place where it might  
 start a quantifier. It looks ahead to see if it really is a quantifier or not.  
 It is only a quantifier if it is one of the forms {ddd} {ddd,} or {ddd,ddd}  
 where the ddds are digits.  
   
 Arguments:  
   p         pointer to the first char after '{'  
   
 Returns:    TRUE or FALSE  
 */  
   
 static BOOL  
 is_counted_repeat(const uschar *p)  
 {  
 if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  
 while ((digitab[*p] & ctype_digit) != 0) p++;  
 if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  
   
 if (*p++ != CHAR_COMMA) return FALSE;  
 if (*p == CHAR_RIGHT_CURLY_BRACKET) return TRUE;  
   
 if ((digitab[*p++] & ctype_digit) == 0) return FALSE;  
 while ((digitab[*p] & ctype_digit) != 0) p++;  
   
 return (*p == CHAR_RIGHT_CURLY_BRACKET);  
 }  
   
   
   
 /*************************************************  
1200  *         Read repeat counts                     *  *         Read repeat counts                     *
1201  *************************************************/  *************************************************/
1202    
# Line 1048  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 1057  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 1072  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 1127  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 1204  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 1212  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 1255  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 1303  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 1315  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 1361  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 1381  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 1397  return rc; Line 1564  return rc;
1564    
1565  /* This is called by several functions that scan a compiled expression looking  /* This is called by several functions that scan a compiled expression looking
1566  for a fixed first character, or an anchoring op code etc. It skips over things  for a fixed first character, or an anchoring op code etc. It skips over things
1567  that do not influence this. For some calls, a change of option is important.  that do not influence this. For some calls, it makes sense to skip negative
1568  For some calls, it makes sense to skip negative forward and all backward  forward and all backward assertions, and also the \b assertion; for others it
1569  assertions, and also the \b assertion; for others it does not.  does not.
1570    
1571  Arguments:  Arguments:
1572    code         pointer to the start of the group    code         pointer to the start of the group
   options      pointer to external options  
   optbit       the option bit whose changing is significant, or  
                  zero if none are  
1573    skipassert   TRUE if certain assertions are to be skipped    skipassert   TRUE if certain assertions are to be skipped
1574    
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, int *options, int optbit,  first_significant_code(const pcre_uchar *code, BOOL skipassert)
   BOOL skipassert)  
1580  {  {
1581  for (;;)  for (;;)
1582    {    {
1583    switch ((int)*code)    switch ((int)*code)
1584      {      {
     case OP_OPT:  
     if (optbit > 0 && ((int)code[1] & optbit) != (*options & optbit))  
       *options = (int)code[1];  
     code += 2;  
     break;  
   
1585      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1586      case OP_ASSERTBACK:      case OP_ASSERTBACK:
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 1444  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 1474  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    options  the compiling options    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)
1643  */  */
1644    
1645  static int  static int
1646  find_fixedlength(uschar *code, int options, 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 1498  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      {      {
1663        /* We only need to continue for OP_CBRA (normal capturing bracket) and
1664        OP_BRA (normal non-capturing bracket) because the other variants of these
1665        opcodes are all concerned with unlimited repeated groups, which of course
1666        are not of fixed length. */
1667    
1668      case OP_CBRA:      case OP_CBRA:
1669      case OP_BRA:      case OP_BRA:
1670      case OP_ONCE:      case OP_ONCE:
1671        case OP_ONCE_NC:
1672      case OP_COND:      case OP_COND:
1673      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options, 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);
1677      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
1678      break;      break;
1679    
1680      /* Reached end of a branch; if it's a ket it is the end of a nested      /* Reached end of a branch; if it's a ket it is the end of a nested call.
1681      call. If it's ALT it is an alternation in a nested call. If it is      If it's ALT it is an alternation in a nested call. An ACCEPT is effectively
1682      END it's the end of the outer call. All can be handled by the same code. */      an ALT. If it is END it's the end of the outer call. All can be handled by
1683        the same code. Note that we must not include the OP_KETRxxx opcodes here,
1684        because they all imply an unlimited repeat. */
1685    
1686      case OP_ALT:      case OP_ALT:
1687      case OP_KET:      case OP_KET:
     case OP_KETRMAX:  
     case OP_KETRMIN:  
1688      case OP_END:      case OP_END:
1689        case OP_ACCEPT:
1690        case OP_ASSERT_ACCEPT:
1691      if (length < 0) length = branchlength;      if (length < 0) length = branchlength;
1692        else if (length != branchlength) return -1;        else if (length != branchlength) return -1;
1693      if (*cc != OP_ALT) return length;      if (*cc != OP_ALT) return length;
# Line 1535  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, options, 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 1555  for (;;) Line 1721  for (;;)
1721    
1722      /* Skip over things that don't match chars */      /* Skip over things that don't match chars */
1723    
1724      case OP_REVERSE:      case OP_MARK:
1725        case OP_PRUNE_ARG:
1726        case OP_SKIP_ARG:
1727        case OP_THEN_ARG:
1728        cc += cc[1] + PRIV(OP_lengths)[*cc];
1729        break;
1730    
1731        case OP_CALLOUT:
1732        case OP_CIRC:
1733        case OP_CIRCM:
1734        case OP_CLOSE:
1735        case OP_COMMIT:
1736      case OP_CREF:      case OP_CREF:
     case OP_NCREF:  
     case OP_RREF:  
     case OP_NRREF:  
1737      case OP_DEF:      case OP_DEF:
1738      case OP_OPT:      case OP_DOLL:
1739      case OP_CALLOUT:      case OP_DOLLM:
     case OP_SOD:  
     case OP_SOM:  
     case OP_SET_SOM:  
1740      case OP_EOD:      case OP_EOD:
1741      case OP_EODN:      case OP_EODN:
1742      case OP_CIRC:      case OP_FAIL:
1743      case OP_DOLL:      case OP_NCREF:
1744        case OP_NRREF:
1745      case OP_NOT_WORD_BOUNDARY:      case OP_NOT_WORD_BOUNDARY:
1746        case OP_PRUNE:
1747        case OP_REVERSE:
1748        case OP_RREF:
1749        case OP_SET_SOM:
1750        case OP_SKIP:
1751        case OP_SOD:
1752        case OP_SOM:
1753        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 */
1759    
1760      case OP_CHAR:      case OP_CHAR:
1761      case OP_CHARNC:      case OP_CHARI:
1762      case OP_NOT:      case OP_NOT:
1763        case OP_NOTI:
1764      branchlength++;      branchlength++;
1765      cc += 2;      cc += 2;
1766  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1767      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
       cc += _pcre_utf8_table4[cc[-1] & 0x3f];  
1768  #endif  #endif
1769      break;      break;
1770    
# Line 1592  for (;;) Line 1772  for (;;)
1772      need to skip over a multibyte character in UTF8 mode.  */      need to skip over a multibyte character in UTF8 mode.  */
1773    
1774      case OP_EXACT:      case OP_EXACT:
1775        case OP_EXACTI:
1776        case OP_NOTEXACT:
1777        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 ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)      if (utf && HAS_EXTRALEN(cc[-1])) cc += GET_EXTRALEN(cc[-1]);
       cc += _pcre_utf8_table4[cc[-1] & 0x3f];  
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 1613  for (;;) Line 1795  for (;;)
1795      cc += 2;      cc += 2;
1796      /* Fall through */      /* Fall through */
1797    
1798        case OP_HSPACE:
1799        case OP_VSPACE:
1800        case OP_NOT_HSPACE:
1801        case OP_NOT_VSPACE:
1802      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1803      case OP_DIGIT:      case OP_DIGIT:
1804      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
# Line 1625  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        {        {
1834          case OP_CRPLUS:
1835          case OP_CRMINPLUS:
1836        case OP_CRSTAR:        case OP_CRSTAR:
1837        case OP_CRMINSTAR:        case OP_CRMINSTAR:
1838        case OP_CRQUERY:        case OP_CRQUERY:
# Line 1652  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 1664  for (;;) Line 1853  for (;;)
1853    
1854      /* Anything else is variable length */      /* Anything else is variable length */
1855    
1856      default:      case OP_ANYNL:
1857        case OP_BRAMINZERO:
1858        case OP_BRAPOS:
1859        case OP_BRAPOSZERO:
1860        case OP_BRAZERO:
1861        case OP_CBRAPOS:
1862        case OP_EXTUNI:
1863        case OP_KETRMAX:
1864        case OP_KETRMIN:
1865        case OP_KETRPOS:
1866        case OP_MINPLUS:
1867        case OP_MINPLUSI:
1868        case OP_MINQUERY:
1869        case OP_MINQUERYI:
1870        case OP_MINSTAR:
1871        case OP_MINSTARI:
1872        case OP_MINUPTO:
1873        case OP_MINUPTOI:
1874        case OP_NOTMINPLUS:
1875        case OP_NOTMINPLUSI:
1876        case OP_NOTMINQUERY:
1877        case OP_NOTMINQUERYI:
1878        case OP_NOTMINSTAR:
1879        case OP_NOTMINSTARI:
1880        case OP_NOTMINUPTO:
1881        case OP_NOTMINUPTOI:
1882        case OP_NOTPLUS:
1883        case OP_NOTPLUSI:
1884        case OP_NOTPOSPLUS:
1885        case OP_NOTPOSPLUSI:
1886        case OP_NOTPOSQUERY:
1887        case OP_NOTPOSQUERYI:
1888        case OP_NOTPOSSTAR:
1889        case OP_NOTPOSSTARI:
1890        case OP_NOTPOSUPTO:
1891        case OP_NOTPOSUPTOI:
1892        case OP_NOTQUERY:
1893        case OP_NOTQUERYI:
1894        case OP_NOTSTAR:
1895        case OP_NOTSTARI:
1896        case OP_NOTUPTO:
1897        case OP_NOTUPTOI:
1898        case OP_PLUS:
1899        case OP_PLUSI:
1900        case OP_POSPLUS:
1901        case OP_POSPLUSI:
1902        case OP_POSQUERY:
1903        case OP_POSQUERYI:
1904        case OP_POSSTAR:
1905        case OP_POSSTARI:
1906        case OP_POSUPTO:
1907        case OP_POSUPTOI:
1908        case OP_QUERY:
1909        case OP_QUERYI:
1910        case OP_REF:
1911        case OP_REFI:
1912        case OP_SBRA:
1913        case OP_SBRAPOS:
1914        case OP_SCBRA:
1915        case OP_SCBRAPOS:
1916        case OP_SCOND:
1917        case OP_SKIPZERO:
1918        case OP_STAR:
1919        case OP_STARI:
1920        case OP_TYPEMINPLUS:
1921        case OP_TYPEMINQUERY:
1922        case OP_TYPEMINSTAR:
1923        case OP_TYPEMINUPTO:
1924        case OP_TYPEPLUS:
1925        case OP_TYPEPOSPLUS:
1926        case OP_TYPEPOSQUERY:
1927        case OP_TYPEPOSSTAR:
1928        case OP_TYPEPOSUPTO:
1929        case OP_TYPEQUERY:
1930        case OP_TYPESTAR:
1931        case OP_TYPEUPTO:
1932        case OP_UPTO:
1933        case OP_UPTOI:
1934      return -1;      return -1;
1935    
1936        /* Catch unrecognized opcodes so that when new ones are added they
1937        are not forgotten, as has happened in the past. */
1938    
1939        default:
1940        return -4;
1941      }      }
1942    }    }
1943  /* Control never gets here */  /* Control never gets here */
# Line 1686  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    {    {
1972    register int c = *code;    register int c = *code;
1973    
1974    if (c == OP_END) return NULL;    if (c == OP_END) return NULL;
1975    
1976    /* XCLASS is used for classes that cannot be represented just by a bit    /* XCLASS is used for classes that cannot be represented just by a bit
# Line 1710  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 */
1991    
1992    else if (c == OP_CBRA)    else if (c == OP_CBRA || c == OP_SCBRA ||
1993               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 1748  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 1758  for (;;) Line 2033  for (;;)
2033        break;        break;
2034    
2035        case OP_THEN_ARG:        case OP_THEN_ARG:
2036        code += code[1+LINK_SIZE];        code += code[1];
2037        break;        break;
2038        }        }
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_CHARNC:        case OP_CHARI:
2053        case OP_EXACT:        case OP_EXACT:
2054          case OP_EXACTI:
2055        case OP_UPTO:        case OP_UPTO:
2056          case OP_UPTOI:
2057        case OP_MINUPTO:        case OP_MINUPTO:
2058          case OP_MINUPTOI:
2059        case OP_POSUPTO:        case OP_POSUPTO:
2060          case OP_POSUPTOI:
2061        case OP_STAR:        case OP_STAR:
2062          case OP_STARI:
2063        case OP_MINSTAR:        case OP_MINSTAR:
2064          case OP_MINSTARI:
2065        case OP_POSSTAR:        case OP_POSSTAR:
2066          case OP_POSSTARI:
2067        case OP_PLUS:        case OP_PLUS:
2068          case OP_PLUSI:
2069        case OP_MINPLUS:        case OP_MINPLUS:
2070          case OP_MINPLUSI:
2071        case OP_POSPLUS:        case OP_POSPLUS:
2072          case OP_POSPLUSI:
2073        case OP_QUERY:        case OP_QUERY:
2074          case OP_QUERYI:
2075        case OP_MINQUERY:        case OP_MINQUERY:
2076          case OP_MINQUERYI:
2077        case OP_POSQUERY:        case OP_POSQUERY:
2078        if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];        case OP_POSQUERYI:
2079          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 1809  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 1854  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 1864  for (;;) Line 2153  for (;;)
2153        break;        break;
2154    
2155        case OP_THEN_ARG:        case OP_THEN_ARG:
2156        code += code[1+LINK_SIZE];        code += code[1];
2157        break;        break;
2158        }        }
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_CHARNC:        case OP_CHARI:
2173        case OP_EXACT:        case OP_EXACT:
2174          case OP_EXACTI:
2175        case OP_UPTO:        case OP_UPTO:
2176          case OP_UPTOI:
2177        case OP_MINUPTO:        case OP_MINUPTO:
2178          case OP_MINUPTOI:
2179        case OP_POSUPTO:        case OP_POSUPTO:
2180          case OP_POSUPTOI:
2181        case OP_STAR:        case OP_STAR:
2182          case OP_STARI:
2183        case OP_MINSTAR:        case OP_MINSTAR:
2184          case OP_MINSTARI:
2185        case OP_POSSTAR:        case OP_POSSTAR:
2186          case OP_POSSTARI:
2187        case OP_PLUS:        case OP_PLUS:
2188          case OP_PLUSI:
2189        case OP_MINPLUS:        case OP_MINPLUS:
2190          case OP_MINPLUSI:
2191        case OP_POSPLUS:        case OP_POSPLUS:
2192          case OP_POSPLUSI:
2193        case OP_QUERY:        case OP_QUERY:
2194          case OP_QUERYI:
2195        case OP_MINQUERY:        case OP_MINQUERY:
2196          case OP_MINQUERYI:
2197        case OP_POSQUERY:        case OP_POSQUERY:
2198        if (code[-1] >= 0xc0) code += _pcre_utf8_table4[code[-1] & 0x3f];        case OP_POSQUERYI:
2199          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 1921  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], NULL, 0, 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], NULL, 0, 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 1950  for (code = first_significant_code(code Line 2252  for (code = first_significant_code(code
2252      continue;      continue;
2253      }      }
2254    
   /* Groups with zero repeats can of course be empty; skip them. */  
   
   if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO)  
     {  
     code += _pcre_OP_lengths[c];  
     do code += GET(code, 1); while (*code == OP_ALT);  
     c = *code;  
     continue;  
     }  
   
2255    /* For a recursion/subroutine call, if its end has been reached, which    /* For a recursion/subroutine call, if its end has been reached, which
2256    implies a subroutine call, we can scan it. */    implies a backward reference subroutine call, we can scan it. If it's a
2257      forward reference subroutine call, we can't. To detect forward reference
2258      we have to scan up the list that is kept in the workspace. This function is
2259      called only when doing the real compile, not during the pre-compile that
2260      measures the size of the compiled pattern. */
2261    
2262    if (c == OP_RECURSE)    if (c == OP_RECURSE)
2263      {      {
2264      BOOL empty_branch = FALSE;      const pcre_uchar *scode;
2265      const uschar *scode = cd->start_code + GET(code, 1);      BOOL empty_branch;
2266    
2267        /* Test for forward reference */
2268    
2269        for (scode = cd->start_workspace; scode < cd->hwm; scode += LINK_SIZE)
2270          if (GET(scode, 0) == code + 1 - cd->start_code) return TRUE;
2271    
2272        /* Not a forward reference, test for completed backward reference */
2273    
2274        empty_branch = FALSE;
2275        scode = cd->start_code + GET(code, 1);
2276      if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */      if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */
2277    
2278        /* Completed backwards reference */
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 1978  for (code = first_significant_code(code Line 2287  for (code = first_significant_code(code
2287        scode += GET(scode, 1);        scode += GET(scode, 1);
2288        }        }
2289      while (*scode == OP_ALT);      while (*scode == OP_ALT);
2290    
2291      if (!empty_branch) return FALSE;  /* All branches are non-empty */      if (!empty_branch) return FALSE;  /* All branches are non-empty */
2292      continue;      continue;
2293      }      }
2294    
2295      /* Groups with zero repeats can of course be empty; skip them. */
2296    
2297      if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO ||
2298          c == OP_BRAPOSZERO)
2299        {
2300        code += PRIV(OP_lengths)[c];
2301        do code += GET(code, 1); while (*code == OP_ALT);
2302        c = *code;
2303        continue;
2304        }
2305    
2306      /* A nested group that is already marked as "could be empty" can just be
2307      skipped. */
2308    
2309      if (c == OP_SBRA  || c == OP_SBRAPOS ||
2310          c == OP_SCBRA || c == OP_SCBRAPOS)
2311        {
2312        do code += GET(code, 1); while (*code == OP_ALT);
2313        c = *code;
2314        continue;
2315        }
2316    
2317    /* For other groups, scan the branches. */    /* For other groups, scan the branches. */
2318    
2319    if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND)    if (c == OP_BRA  || c == OP_BRAPOS ||
2320          c == OP_CBRA || c == OP_CBRAPOS ||
2321          c == OP_ONCE || c == OP_ONCE_NC ||
2322          c == OP_COND)
2323      {      {
2324      BOOL empty_branch;      BOOL empty_branch;
2325      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */      if (GET(code, 1) == 0) return TRUE;    /* Hit unclosed bracket */
# Line 2000  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 2018  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    
2360  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2361      case OP_XCLASS:      case OP_XCLASS:
2362      ccode = code += GET(code, 1);      ccode = code += GET(code, 1);
2363      goto CHECK_CLASS_REPEAT;      goto CHECK_CLASS_REPEAT;
# Line 2030  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  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
2371      CHECK_CLASS_REPEAT:      CHECK_CLASS_REPEAT:
2372  #endif  #endif
2373    
# Line 2071  for (code = first_significant_code(code Line 2406  for (code = first_significant_code(code
2406      case OP_ALLANY:      case OP_ALLANY:
2407      case OP_ANYBYTE:      case OP_ANYBYTE:
2408      case OP_CHAR:      case OP_CHAR:
2409      case OP_CHARNC:      case OP_CHARI:
2410      case OP_NOT:      case OP_NOT:
2411        case OP_NOTI:
2412      case OP_PLUS:      case OP_PLUS:
2413      case OP_MINPLUS:      case OP_MINPLUS:
2414      case OP_POSPLUS:      case OP_POSPLUS:
# Line 2104  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 2112  for (code = first_significant_code(code Line 2449  for (code = first_significant_code(code
2449      case OP_KET:      case OP_KET:
2450      case OP_KETRMAX:      case OP_KETRMAX:
2451      case OP_KETRMIN:      case OP_KETRMIN:
2452        case OP_KETRPOS:
2453      case OP_ALT:      case OP_ALT:
2454      return TRUE;      return TRUE;
2455    
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:
2462      case OP_MINSTAR:      case OP_MINSTAR:
2463        case OP_MINSTARI:
2464      case OP_POSSTAR:      case OP_POSSTAR:
2465        case OP_POSSTARI:
2466      case OP_QUERY:      case OP_QUERY:
2467        case OP_QUERYI:
2468      case OP_MINQUERY:      case OP_MINQUERY:
2469        case OP_MINQUERYI:
2470      case OP_POSQUERY:      case OP_POSQUERY:
2471      if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];      case OP_POSQUERYI:
2472        if (utf && HAS_EXTRALEN(code[1])) code += GET_EXTRALEN(code[1]);
2473      break;      break;
2474    
2475      case OP_UPTO:      case OP_UPTO:
2476        case OP_UPTOI:
2477      case OP_MINUPTO:      case OP_MINUPTO:
2478        case OP_MINUPTOI:
2479      case OP_POSUPTO:      case OP_POSUPTO:
2480      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];      case OP_POSUPTOI:
2481        if (utf && HAS_EXTRALEN(code[1 + IMM2_SIZE])) code += GET_EXTRALEN(code[1 + IMM2_SIZE]);
2482      break;      break;
2483  #endif  #endif
2484    
# Line 2145  for (code = first_significant_code(code Line 2492  for (code = first_significant_code(code
2492      break;      break;
2493    
2494      case OP_THEN_ARG:      case OP_THEN_ARG:
2495      code += code[1+LINK_SIZE];      code += code[1];
2496      break;      break;
2497    
2498      /* None of the remaining opcodes are required to match a character. */      /* None of the remaining opcodes are required to match a character. */
# Line 2168  return TRUE; Line 2515  return TRUE;
2515  the current branch of the current pattern to see if it could match the empty  the current branch of the current pattern to see if it could match the empty
2516  string. If it could, we must look outwards for branches at other levels,  string. If it could, we must look outwards for branches at other levels,
2517  stopping when we pass beyond the bracket which is the subject of the recursion.  stopping when we pass beyond the bracket which is the subject of the recursion.
2518    This function is called only during the real compile, not during the
2519    pre-compile.
2520    
2521  Arguments:  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 2218  where Perl recognizes it as the POSIX cl Line 2567  where Perl recognizes it as the POSIX cl
2567  "l\ower". This is a lesser evil that not diagnosing bad classes when Perl does,  "l\ower". This is a lesser evil that not diagnosing bad classes when Perl does,
2568  I think.  I think.
2569    
2570    A user pointed out that PCRE was rejecting [:a[:digit:]] whereas Perl was not.
2571    It seems that the appearance of a nested POSIX class supersedes an apparent
2572    external class. For example, [:a[:digit:]b:] matches "a", "b", ":", or
2573    a digit.
2574    
2575    In Perl, unescaped square brackets may also appear as part of class names. For
2576    example, [:a[:abc]b:] gives unknown POSIX class "[:abc]b:]". However, for
2577    [:a[:abc]b][b:] it gives unknown POSIX class "[:abc]b][b:]", which does not
2578    seem right at all. PCRE does not allow closing square brackets in POSIX class
2579    names.
2580    
2581  Arguments:  Arguments:
2582    ptr      pointer to the initial [    ptr      pointer to the initial [
2583    endptr   where to return the end pointer    endptr   where to return the end pointer
# Line 2226  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. */
2593  for (++ptr; *ptr != 0; ptr++)  for (++ptr; *ptr != 0; ptr++)
2594    {    {
2595    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET) ptr++; else    if (*ptr == CHAR_BACKSLASH && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2596        ptr++;
2597      else if (*ptr == CHAR_RIGHT_SQUARE_BRACKET) return FALSE;
2598      else
2599      {      {
     if (*ptr == CHAR_RIGHT_SQUARE_BRACKET) return FALSE;  
2600      if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)      if (*ptr == terminator && ptr[1] == CHAR_RIGHT_SQUARE_BRACKET)
2601        {        {
2602        *endptr = ptr;        *endptr = ptr;
2603        return TRUE;        return TRUE;
2604        }        }
2605        if (*ptr == CHAR_LEFT_SQUARE_BRACKET &&
2606             (ptr[1] == CHAR_COLON || ptr[1] == CHAR_DOT ||
2607              ptr[1] == CHAR_EQUALS_SIGN) &&
2608            check_posix_syntax(ptr, endptr))
2609          return FALSE;
2610      }      }
2611    }    }
2612  return FALSE;  return FALSE;
# Line 2263  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 2302  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 2310  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 2363  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 2392  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 2475  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 2486  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 2521  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 2530  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 2550  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 2569  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 2594  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 2606  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 2615  the next item is a character. */ Line 2980  the next item is a character. */
2980  if (next >= 0) switch(op_code)  if (next >= 0) switch(op_code)
2981    {    {
2982    case OP_CHAR:    case OP_CHAR:
2983  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2984    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
2985  #else  #else
2986    c = *previous;    c = *previous;
2987  #endif  #endif
2988    return c != next;    return c != next;
2989    
2990    /* For CHARNC (caseless character) we must check the other case. If we have    /* For CHARI (caseless character) we must check the other case. If we have
2991    Unicode property support, we can use it to test the other case of    Unicode property support, we can use it to test the other case of
2992    high-valued characters. */    high-valued characters. */
2993    
2994    case OP_CHARNC:    case OP_CHARI:
2995  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2996    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
2997  #else  #else
2998    c = *previous;    c = *previous;
2999  #endif  #endif
3000    if (c == next) return FALSE;    if (c == next) return FALSE;
3001  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3002    if (utf8)    if (utf)
3003      {      {
3004      unsigned int othercase;      unsigned int othercase;
3005      if (next < 128) othercase = cd->fcc[next]; else      if (next < 128) othercase = cd->fcc[next]; else
# Line 2646  if (next >= 0) switch(op_code) Line 3011  if (next >= 0) switch(op_code)
3011      return (unsigned int)c != othercase;      return (unsigned int)c != othercase;
3012      }      }
3013    else    else
3014  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
3015    return (c != cd->fcc[next]);  /* Non-UTF-8 mode */    return (c != cd->fcc[next]);  /* Non-UTF-8 mode */
3016    
3017    /* For OP_NOT, its data is always a single-byte character. */    /* For OP_NOT and OP_NOTI, the data is always a single-byte character. These
3018      opcodes are not used for multi-byte characters, because they are coded using
3019      an XCLASS instead. */
3020    
3021    case OP_NOT:    case OP_NOT:
3022      return (c = *previous) == next;
3023    
3024      case OP_NOTI:
3025    if ((c = *previous) == next) return TRUE;    if ((c = *previous) == next) return TRUE;
3026    if ((options & PCRE_CASELESS) == 0) return FALSE;  #ifdef SUPPORT_UTF
3027  #ifdef SUPPORT_UTF8    if (utf)
   if (utf8)  
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 2667  if (next >= 0) switch(op_code) Line 3036  if (next >= 0) switch(op_code)
3036      return (unsigned int)c == othercase;      return (unsigned int)c == othercase;
3037      }      }
3038    else    else
3039  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
3040    return (c == cd->fcc[next]);  /* Non-UTF-8 mode */    return (c == cd->fcc[next]);  /* Non-UTF-8 mode */
3041    
3042    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.    /* Note that OP_DIGIT etc. are generated only when PCRE_UCP is *not* set.
# Line 2758  replaced by OP_PROP codes when PCRE_UCP Line 3127  replaced by OP_PROP codes when PCRE_UCP
3127  switch(op_code)  switch(op_code)
3128    {    {
3129    case OP_CHAR:    case OP_CHAR:
3130    case OP_CHARNC:    case OP_CHARI:
3131  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3132    GETCHARTEST(c, previous);    GETCHARTEST(c, previous);
3133  #else  #else
3134    c = *previous;    c = *previous;
# Line 2864  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 2942  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
3318    cd             contains pointers to tables etc.    cd             contains pointers to tables etc.
3319    lengthptr      NULL during the real compile phase    lengthptr      NULL during the real compile phase
3320                   points to length accumulator during pre-compile phase                   points to length accumulator during pre-compile phase
# Line 2954  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      pcre_int32 *reqcharptr, branch_chain *bcptr, int cond_depth,
3330    compile_data *cd, int *lengthptr)    compile_data *cd, int *lengthptr)
3331  {  {
3332  int repeat_type, op_type;  int repeat_type, op_type;
3333  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */  int repeat_min = 0, repeat_max = 0;      /* To please picky compilers */
3334  int bravalue = 0;  int bravalue = 0;
3335  int greedy_default, greedy_non_default;  int greedy_default, greedy_non_default;
3336  int firstbyte, reqbyte;  pcre_int32 firstchar, reqchar;
3337  int zeroreqbyte, zerofirstbyte;  pcre_int32 zeroreqchar, zerofirstchar;
3338  int req_caseopt, reqvary, tempreqvary;  pcre_int32 req_caseopt, reqvary, tempreqvary;
3339  int options = *optionsptr;  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  #ifdef SUPPORT_UTF8  /* We can fish out the UTF-8 setting once and for all into a BOOL, but we
3358  BOOL class_utf8;  must not do this for other options (e.g. PCRE_EXTENDED) because they may change
3359  BOOL utf8 = (options & PCRE_UTF8) != 0;  dynamically as we process the pattern. */
3360  uschar *class_utf8data;  
3361  uschar *class_utf8data_base;  #ifdef SUPPORT_UTF
3362  uschar utf8_char[6];  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
3363    BOOL utf = (options & PCRE_UTF8) != 0;
3364    pcre_uchar utf_chars[6];
3365  #else  #else
3366  BOOL utf8 = FALSE;  BOOL utf = FALSE;
3367  uschar *utf8_char = NULL;  #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 3005  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 3038  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    uschar mcbuffer[8];    int tempbracount;
3427      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 3089  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 3099  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 3163  for (;; ptr++) Line 3546  for (;; ptr++)
3546      previous_callout = NULL;      previous_callout = NULL;
3547      }      }
3548    
3549    /* In extended mode, skip white space and comments */    /* In extended mode, skip white space and comments. */
3550    
3551    if ((options & PCRE_EXTENDED) != 0)    if ((options & PCRE_EXTENDED) != 0)
3552      {      {
# Line 3175  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 3200  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 3222  for (;; ptr++) Line 3605  for (;; ptr++)
3605      the setting of any following char as a first character. */      the setting of any following char as a first character. */
3606    
3607      case CHAR_CIRCUMFLEX_ACCENT:      case CHAR_CIRCUMFLEX_ACCENT:
3608        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;
3613        }        }
3614      previous = NULL;      else *code++ = OP_CIRC;
     *code++ = OP_CIRC;  
3615      break;      break;
3616    
3617      case CHAR_DOLLAR_SIGN:      case CHAR_DOLLAR_SIGN:
3618      previous = NULL;      previous = NULL;
3619      *code++ = OP_DOLL;      *code++ = ((options & PCRE_MULTILINE) != 0)? OP_DOLLM : OP_DOLL;
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 3296  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 3316  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 3339  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 3353  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_UTF
3742        if (utf8 && c > 127)        if (utf && HAS_EXTRALEN(c))
3743          {                           /* Braces are required because the */          {                           /* Braces are required because the */
3744          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */          GETCHARLEN(c, ptr, ptr);    /* macro generates multiple statements */
3745          }          }
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 3399  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 3455  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 3517  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 3572  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 3607  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 3642  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 3670  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 3692  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 3718  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 3766  for (;; ptr++) Line 4150  for (;; ptr++)
4150            goto LONE_SINGLE_CHARACTER;            goto LONE_SINGLE_CHARACTER;
4151            }            }
4152    
4153  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4154          if (utf8)          if (utf)
4155            {                           /* Braces are required because the */            {                           /* Braces are required because the */
4156            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */            GETCHARLEN(d, ptr, ptr);    /* macro generates multiple statements */
4157            }            }
# Line 3816  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  #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)
4204          if (utf8 && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))          if ((d > 255) || (utf && ((options & PCRE_CASELESS) != 0 && d > 127)))
4205    #elif defined  SUPPORT_UTF
4206            if (utf && (d > 255 || ((options & PCRE_CASELESS) != 0 && d > 127)))
4207    #elif !(defined COMPILE_PCRE8)
4208            if (d > 255)
4209    #endif
4210    #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
4211            {            {
4212            class_utf8 = TRUE;            xclass = TRUE;
4213    
4214            /* With UCP support, we can find the other case equivalents of            /* With UCP support, we can find the other case equivalents of
4215            the relevant characters. There may be several ranges. Optimize how            the relevant characters. There may be several ranges. Optimize how
4216            they fit with the basic range. */            they fit with the basic range. */
4217    
4218  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4219    #ifndef COMPILE_PCRE8
4220              if (utf && (options & PCRE_CASELESS) != 0)
4221    #else
4222            if ((options & PCRE_CASELESS) != 0)            if ((options & PCRE_CASELESS) != 0)
4223    #endif
4224              {              {
4225              unsigned int occ, ocd;              unsigned int occ, ocd;
4226              unsigned int cc = c;              unsigned int cc = c;
# Line 3852  for (;; ptr++) Line 4246  for (;; ptr++)
4246    
4247                if (occ == ocd)                if (occ == ocd)
4248                  {                  {
4249                  *class_utf8data++ = XCL_SINGLE;                  *class_uchardata++ = XCL_SINGLE;
4250                  }                  }
4251                else                else
4252                  {                  {
4253                  *class_utf8data++ = XCL_RANGE;                  *class_uchardata++ = XCL_RANGE;
4254                  class_utf8data += _pcre_ord2utf8(occ, class_utf8data);                  class_uchardata += PRIV(ord2utf)(occ, class_uchardata);
4255                  }                  }
4256                class_utf8data += _pcre_ord2utf8(ocd, class_utf8data);                class_uchardata += PRIV(ord2utf)(ocd, class_uchardata);
4257                }                }
4258              }              }
4259  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
# Line 3867  for (;; ptr++) Line 4261  for (;; ptr++)
4261            /* Now record the original range, possibly modified for UCP caseless            /* Now record the original range, possibly modified for UCP caseless
4262            overlapping ranges. */            overlapping ranges. */
4263    
4264            *class_utf8data++ = XCL_RANGE;            *class_uchardata++ = XCL_RANGE;
4265            class_utf8data += _pcre_ord2utf8(c, class_utf8data);  #ifdef SUPPORT_UTF
4266            class_utf8data += _pcre_ord2utf8(d, class_utf8data);  #ifndef COMPILE_PCRE8
4267              if (utf)
4268                {
4269                class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4270                class_uchardata += PRIV(ord2utf)(d, class_uchardata);
4271                }
4272              else
4273                {
4274                *class_uchardata++ = c;
4275                *class_uchardata++ = d;
4276                }
4277    #else
4278              class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4279              class_uchardata += PRIV(ord2utf)(d, class_uchardata);
4280    #endif
4281    #else /* SUPPORT_UTF */
4282              *class_uchardata++ = c;
4283              *class_uchardata++ = d;
4284    #endif /* SUPPORT_UTF */
4285    
4286            /* With UCP support, we are done. Without UCP support, there is no            /* With UCP support, we are done. Without UCP support, there is no
4287            caseless matching for UTF-8 characters > 127; we can use the bit map            caseless matching for UTF characters > 127; we can use the bit map
4288            for the smaller ones. */            for the smaller ones. As for 16 bit characters without UTF, we
4289              can still use  */
4290    
4291  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4292            continue;    /* With next character in the class */  #ifndef COMPILE_PCRE8
4293  #else            if (utf)
4294            if ((options & PCRE_CASELESS) == 0 || c > 127) continue;  #endif
4295                continue;    /* With next character in the class */
4296    #endif  /* SUPPORT_UCP */
4297    
4298    #if defined SUPPORT_UTF && !defined(SUPPORT_UCP) && !(defined COMPILE_PCRE8)
4299              if (utf)
4300                {
4301                if ((options & PCRE_CASELESS) == 0 || c > 127) continue;
4302                /* Adjust upper limit and fall through to set up the map */
4303                d = 127;
4304                }
4305              else
4306                {
4307                if (c > 255) continue;
4308                /* Adjust upper limit and fall through to set up the map */
4309                d = 255;
4310                }
4311    #elif defined SUPPORT_UTF && !defined(SUPPORT_UCP)
4312              if ((options & PCRE_CASELESS) == 0 || c > 127) continue;
4313            /* Adjust upper limit and fall through to set up the map */            /* Adjust upper limit and fall through to set up the map */
   
4314            d = 127;            d = 127;
4315    #else
4316  #endif  /* SUPPORT_UCP */            if (c > 255) continue;
4317              /* Adjust upper limit and fall through to set up the map */
4318              d = 255;
4319    #endif  /* SUPPORT_UTF && !SUPPORT_UCP && !COMPILE_PCRE8 */
4320            }            }
4321  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF || !COMPILE_PCRE8 */
4322    
4323          /* 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
4324          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. */  
4325    
4326          class_charcount += d - c + 1;          class_charcount += d - c + 1;
4327          class_lastchar = d;          class_lastchar = d;
# Line 3918  for (;; ptr++) Line 4349  for (;; ptr++)
4349    
4350        /* Handle a character that cannot go in the bit map */        /* Handle a character that cannot go in the bit map */
4351    
4352  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF && !(defined COMPILE_PCRE8)
4353        if (utf8 && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))        if ((c > 255) || (utf && ((options & PCRE_CASELESS) != 0 && c > 127)))
4354          {  #elif defined SUPPORT_UTF
4355          class_utf8 = TRUE;        if (utf && (c > 255 || ((options & PCRE_CASELESS) != 0 && c > 127)))
4356          *class_utf8data++ = XCL_SINGLE;  #elif !(defined COMPILE_PCRE8)
4357          class_utf8data += _pcre_ord2utf8(c, class_utf8data);        if (c > 255)
4358    #endif
4359    #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
4360            {
4361            xclass = TRUE;
4362            *class_uchardata++ = XCL_SINGLE;
4363    #ifdef SUPPORT_UTF
4364    #ifndef COMPILE_PCRE8
4365            /* In non 8 bit mode, we can get here even
4366            if we are not in UTF mode. */
4367            if (!utf)
4368              *class_uchardata++ = c;
4369            else
4370    #endif
4371              class_uchardata += PRIV(ord2utf)(c, class_uchardata);
4372    #else /* SUPPORT_UTF */
4373            *class_uchardata++ = c;
4374    #endif /* SUPPORT_UTF */
4375    
4376  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
4377    #ifdef COMPILE_PCRE8
4378          if ((options & PCRE_CASELESS) != 0)          if ((options & PCRE_CASELESS) != 0)
4379    #else
4380            /* In non 8 bit mode, we can get here even
4381            if we are not in UTF mode. */
4382            if (utf && (options & PCRE_CASELESS) != 0)
4383    #endif
4384            {            {
4385            unsigned int othercase;            unsigned int othercase;
4386            if ((othercase = UCD_OTHERCASE(c)) != c)            if ((othercase = UCD_OTHERCASE(c)) != c)
4387              {              {
4388              *class_utf8data++ = XCL_SINGLE;              *class_uchardata++ = XCL_SINGLE;
4389              class_utf8data += _pcre_ord2utf8(othercase, class_utf8data);              class_uchardata += PRIV(ord2utf)(othercase, class_uchardata);
4390              }              }
4391            }            }
4392  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
4393    
4394          }          }
4395        else        else
4396  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF || COMPILE_PCRE16 */
   
4397        /* Handle a single-byte character */        /* Handle a single-byte character */
4398          {          {
4399          classbits[c/8] |= (1 << (c&7));          classbits[c/8] |= (1 << (c&7));
# Line 3952  for (;; ptr++) Line 4405  for (;; ptr++)
4405          class_charcount++;          class_charcount++;
4406          class_lastchar = c;          class_lastchar = c;
4407          }          }
4408    
4409        }        }
4410    
4411      /* Loop until ']' reached. This "while" is the end of the "do" far above.      /* Loop until ']' reached. This "while" is the end of the "do" far above.
# Line 3978  for (;; ptr++) Line 4432  for (;; ptr++)
4432    
4433      In UTF-8 mode, we can optimize the negative case only if there were no      In UTF-8 mode, we can optimize the negative case only if there were no
4434      characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR      characters >= 128 because OP_NOT and the related opcodes like OP_NOTSTAR
4435      operate on single-bytes only. This is an historical hangover. Maybe one day      operate on single-bytes characters only. This is an historical hangover.
4436      we can tidy these opcodes to handle multi-byte characters.      Maybe one day we can tidy these opcodes to handle multi-byte characters.
4437    
4438      The optimization throws away the bit map. We turn the item into a      The optimization throws away the bit map. We turn the item into a
4439      1-character OP_CHAR[NC] if it's positive, or OP_NOT if it's negative. Note      1-character OP_CHAR[I] if it's positive, or OP_NOT[I] if it's negative.
4440      that OP_NOT does not support multibyte characters. In the positive case, it      Note that OP_NOT[I] does not support multibyte characters. In the positive
4441      can cause firstbyte to be set. Otherwise, there can be no first char if      case, it can cause firstchar to be set. Otherwise, there can be no first
4442      this item is first, whatever repeat count may follow. In the case of      char if this item is first, whatever repeat count may follow. In the case
4443      reqbyte, save the previous value for reinstating. */      of reqchar, save the previous value for reinstating. */
4444    
4445  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4446      if (class_charcount == 1 && !class_utf8 &&      if (class_charcount == 1 && !xclass &&
4447        (!utf8 || !negate_class || class_lastchar < 128))        (!utf || !negate_class || class_lastchar < 128))
4448  #else  #else
4449      if (class_charcount == 1)      if (class_charcount == 1)
4450  #endif  #endif
4451        {        {
4452        zeroreqbyte = reqbyte;        zeroreqchar = reqchar;
4453    
4454        /* The OP_NOT opcode works on one-byte characters only. */        /* The OP_NOT[I] opcodes work on one-byte characters only. */
4455    
4456        if (negate_class)        if (negate_class)
4457          {          {
4458          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;          if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4459          zerofirstbyte = firstbyte;          zerofirstchar = firstchar;
4460          *code++ = OP_NOT;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_NOTI: OP_NOT;
4461          *code++ = class_lastchar;          *code++ = class_lastchar;
4462          break;          break;
4463          }          }
# Line 4011  for (;; ptr++) Line 4465  for (;; ptr++)
4465        /* For a single, positive character, get the value into mcbuffer, and        /* For a single, positive character, get the value into mcbuffer, and
4466        then we can handle this with the normal one-character code. */        then we can handle this with the normal one-character code. */
4467    
4468  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4469        if (utf8 && class_lastchar > 127)        if (utf && class_lastchar > 127)
4470          mclength = _pcre_ord2utf8(class_lastchar, mcbuffer);          mclength = PRIV(ord2utf)(class_lastchar, mcbuffer);
4471        else        else
4472  #endif  #endif
4473          {          {
# Line 4025  for (;; ptr++) Line 4479  for (;; ptr++)
4479    
4480      /* The general case - not the one-char optimization. If this is the first      /* The general case - not the one-char optimization. If this is the first
4481      thing in the branch, there can be no first char setting, whatever the      thing in the branch, there can be no first char setting, whatever the
4482      repeat count. Any reqbyte setting must remain unchanged after any kind of      repeat count. Any reqchar setting must remain unchanged after any kind of
4483      repeat. */      repeat. */
4484    
4485      if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;      if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
4486      zerofirstbyte = firstbyte;      zerofirstchar = firstchar;
4487      zeroreqbyte = reqbyte;      zeroreqchar = reqchar;
4488    
4489      /* If there are characters with values > 255, we have to compile an      /* If there are characters with values > 255, we have to compile an
4490      extended class, with its own opcode, unless there was a negated special      extended class, with its own opcode, unless there was a negated special
# Line 4040  for (;; ptr++) Line 4494  for (;; ptr++)
4494      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
4495      actual compiled code. */      actual compiled code. */
4496    
4497  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4498      if (class_utf8 && (!should_flip_negation || (options & PCRE_UCP) != 0))      if (xclass && (!should_flip_negation || (options & PCRE_UCP) != 0))
4499    #endif
4500    #ifndef COMPILE_PCRE8
4501        if (xclass && !should_flip_negation)
4502    #endif
4503    #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4504        {        {
4505        *class_utf8data++ = XCL_END;    /* Marks the end of extra data */        *class_uchardata++ = XCL_END;    /* Marks the end of extra data */
4506        *code++ = OP_XCLASS;        *code++ = OP_XCLASS;
4507        code += LINK_SIZE;        code += LINK_SIZE;
4508        *code = negate_class? XCL_NOT : 0;        *code = negate_class? XCL_NOT:0;
4509    
4510        /* 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;
4511        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 4054  for (;; ptr++) Line 4513  for (;; ptr++)
4513        if (class_charcount > 0)        if (class_charcount > 0)
4514          {          {
4515          *code++ |= XCL_MAP;          *code++ |= XCL_MAP;
4516          memmove(code + 32, code, class_utf8data - code);          memmove(code + (32 / sizeof(pcre_uchar)), code,
4517              IN_UCHARS(class_uchardata - code));
4518          memcpy(code, classbits, 32);          memcpy(code, classbits, 32);
4519          code = class_utf8data + 32;          code = class_uchardata + (32 / sizeof(pcre_uchar));
4520          }          }
4521        else code = class_utf8data;        else code = class_uchardata;
4522    
4523        /* Now fill in the complete length of the item */        /* Now fill in the complete length of the item */
4524    
# Line 4074  for (;; ptr++) Line 4534  for (;; ptr++)
4534      negating it if necessary. */      negating it if necessary. */
4535    
4536      *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;      *code++ = (negate_class == should_flip_negation) ? OP_CLASS : OP_NCLASS;
4537      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  
4538        {        {
4539          if (negate_class)
4540            for (c = 0; c < 32; c++) classbits[c] = ~classbits[c];
4541        memcpy(code, classbits, 32);        memcpy(code, classbits, 32);
4542        }        }
4543      code += 32;      code += 32 / sizeof(pcre_uchar);
4544      break;      break;
4545    
4546    
# Line 4120  for (;; ptr++) Line 4577  for (;; ptr++)
4577    
4578      if (repeat_min == 0)      if (repeat_min == 0)
4579        {        {
4580        firstbyte = zerofirstbyte;    /* Adjust for zero repeat */        firstchar = zerofirstchar;    /* Adjust for zero repeat */
4581        reqbyte = zeroreqbyte;        /* Ditto */        reqchar = zeroreqchar;        /* Ditto */
4582        }        }
4583    
4584      /* Remember whether this is a variable length repeat */      /* Remember whether this is a variable length repeat */
# Line 4131  for (;; ptr++) Line 4588  for (;; ptr++)
4588      op_type = 0;                    /* Default single-char op codes */      op_type = 0;                    /* Default single-char op codes */
4589      possessive_quantifier = FALSE;  /* Default not possessive quantifier */      possessive_quantifier = FALSE;  /* Default not possessive quantifier */
4590    
4591      /* Save start of previous item, in case we have to move it up to make space      /* Save start of previous item, in case we have to move it up in order to
4592      for an inserted OP_ONCE for the additional '+' extension. */      insert something before it. */
4593    
4594      tempcode = previous;      tempcode = previous;
4595    
# Line 4155  for (;; ptr++) Line 4612  for (;; ptr++)
4612        }        }
4613      else repeat_type = greedy_default;      else repeat_type = greedy_default;
4614    
4615        /* If previous was a recursion call, wrap it in atomic brackets so that
4616        previous becomes the atomic group. All recursions were so wrapped in the
4617        past, but it no longer happens for non-repeated recursions. In fact, the
4618        repeated ones could be re-implemented independently so as not to need this,
4619        but for the moment we rely on the code for repeating groups. */
4620    
4621        if (*previous == OP_RECURSE)
4622          {
4623          memmove(previous + 1 + LINK_SIZE, previous, IN_UCHARS(1 + LINK_SIZE));
4624          *previous = OP_ONCE;
4625          PUT(previous, 1, 2 + 2*LINK_SIZE);
4626          previous[2 + 2*LINK_SIZE] = OP_KET;
4627          PUT(previous, 3 + 2*LINK_SIZE, 2 + 2*LINK_SIZE);
4628          code += 2 + 2 * LINK_SIZE;
4629          length_prevgroup = 3 + 3*LINK_SIZE;
4630    
4631          /* When actually compiling, we need to check whether this was a forward
4632          reference, and if so, adjust the offset. */
4633    
4634          if (lengthptr == NULL && cd->hwm >= cd->start_workspace + LINK_SIZE)
4635            {
4636            int offset = GET(cd->hwm, -LINK_SIZE);
4637            if (offset == previous + 1 - cd->start_code)
4638              PUT(cd->hwm, -LINK_SIZE, offset + 1 + LINK_SIZE);
4639            }
4640          }
4641    
4642        /* Now handle repetition for the different types of item. */
4643    
4644      /* If previous was a character match, abolish the item and generate a      /* If previous was a character match, abolish the item and generate a
4645      repeat item instead. If a char item has a minumum of more than one, ensure      repeat item instead. If a char item has a minumum of more than one, ensure
4646      that it is set in reqbyte - it might not be if a sequence such as x{3} is      that it is set in reqchar - it might not be if a sequence such as x{3} is
4647      the first thing in a branch because the x will have gone into firstbyte      the first thing in a branch because the x will have gone into firstchar
4648      instead.  */      instead.  */
4649    
4650      if (*previous == OP_CHAR || *previous == OP_CHARNC)      if (*previous == OP_CHAR || *previous == OP_CHARI)
4651        {        {
4652        /* Deal with UTF-8 characters that take up more than one byte. It's        op_type = (*previous == OP_CHAR)? 0 : OP_STARI - OP_STAR;
4653    
4654          /* Deal with UTF characters that take up more than one character. It's
4655        easier to write this out separately than try to macrify it. Use c to        easier to write this out separately than try to macrify it. Use c to
4656        hold the length of the character in bytes, plus 0x80 to flag that it's a        hold the length of the character in bytes, plus UTF_LENGTH to flag that
4657        length rather than a small character. */        it's a length rather than a small character. */
4658    
4659  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4660        if (utf8 && (code[-1] & 0x80) != 0)        if (utf && NOT_FIRSTCHAR(code[-1]))
4661          {          {
4662          uschar *lastchar = code - 1;          pcre_uchar *lastchar = code - 1;
4663          while((*lastchar & 0xc0) == 0x80) lastchar--;          BACKCHAR(lastchar);
4664          c = code - lastchar;            /* Length of UTF-8 character */          c = code - lastchar;            /* Length of UTF-8 character */
4665          memcpy(utf8_char, lastchar, c); /* Save the char */          memcpy(utf_chars, lastchar, IN_UCHARS(c)); /* Save the char */
4666          c |= 0x80;                      /* Flag c as a length */          c |= UTF_LENGTH;                /* Flag c as a length */
4667          }          }
4668        else        else
4669  #endif  #endif /* SUPPORT_UTF */
   
       /* Handle the case of a single byte - either with no UTF8 support, or  
       with UTF-8 disabled, or for a UTF-8 character < 128. */  
4670    
4671          /* Handle the case of a single charater - either with no UTF support, or
4672          with UTF disabled, or for a single character UTF character. */
4673          {          {
4674          c = code[-1];          c = code[-1];
4675          if (repeat_min > 1) reqbyte = c | req_caseopt | cd->req_varyopt;          if (repeat_min > 1) reqchar = c | req_caseopt | cd->req_varyopt;
4676          }          }
4677    
4678        /* If the repetition is unlimited, it pays to see if the next thing on        /* If the repetition is unlimited, it pays to see if the next thing on
# Line 4195  for (;; ptr++) Line 4682  for (;; ptr++)
4682    
4683        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4684            repeat_max < 0 &&            repeat_max < 0 &&
4685            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4686          {          {
4687          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4688          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4207  for (;; ptr++) Line 4694  for (;; ptr++)
4694      /* If previous was a single negated character ([^a] or similar), we use      /* If previous was a single negated character ([^a] or similar), we use
4695      one of the special opcodes, replacing it. The code is shared with single-      one of the special opcodes, replacing it. The code is shared with single-
4696      character repeats by setting opt_type to add a suitable offset into      character repeats by setting opt_type to add a suitable offset into
4697      repeat_type. We can also test for auto-possessification. OP_NOT is      repeat_type. We can also test for auto-possessification. OP_NOT and OP_NOTI
4698      currently used only for single-byte chars. */      are currently used only for single-byte chars. */
4699    
4700      else if (*previous == OP_NOT)      else if (*previous == OP_NOT || *previous == OP_NOTI)
4701        {        {
4702        op_type = OP_NOTSTAR - OP_STAR;  /* Use "not" opcodes */        op_type = ((*previous == OP_NOT)? OP_NOTSTAR : OP_NOTSTARI) - OP_STAR;
4703        c = previous[1];        c = previous[1];
4704        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4705            repeat_max < 0 &&            repeat_max < 0 &&
4706            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4707          {          {
4708          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4709          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4233  for (;; ptr++) Line 4720  for (;; ptr++)
4720    
4721      else if (*previous < OP_EODN)      else if (*previous < OP_EODN)
4722        {        {
4723        uschar *oldcode;        pcre_uchar *oldcode;
4724        int prop_type, prop_value;        int prop_type, prop_value;
4725        op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */        op_type = OP_TYPESTAR - OP_STAR;  /* Use type opcodes */
4726        c = *previous;        c = *previous;
4727    
4728        if (!possessive_quantifier &&        if (!possessive_quantifier &&
4729            repeat_max < 0 &&            repeat_max < 0 &&
4730            check_auto_possessive(previous, utf8, ptr + 1, options, cd))            check_auto_possessive(previous, utf, ptr + 1, options, cd))
4731          {          {
4732          repeat_type = 0;    /* Force greedy */          repeat_type = 0;    /* Force greedy */
4733          possessive_quantifier = TRUE;          possessive_quantifier = TRUE;
# Line 4320  for (;; ptr++) Line 4807  for (;; ptr++)
4807          we have to insert the character for the previous code. For a repeated          we have to insert the character for the previous code. For a repeated
4808          Unicode property match, there are two extra bytes that define the          Unicode property match, there are two extra bytes that define the
4809          required property. In UTF-8 mode, long characters have their length in          required property. In UTF-8 mode, long characters have their length in
4810          c, with the 0x80 bit as a flag. */          c, with the UTF_LENGTH bit as a flag. */
4811    
4812          if (repeat_max < 0)          if (repeat_max < 0)
4813            {            {
4814  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4815            if (utf8 && c >= 128)            if (utf && (c & UTF_LENGTH) != 0)
4816              {              {
4817              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, IN_UCHARS(c & 7));
4818              code += c & 7;              code += c & 7;
4819              }              }
4820            else            else
# Line 4349  for (;; ptr++) Line 4836  for (;; ptr++)
4836    
4837          else if (repeat_max != repeat_min)          else if (repeat_max != repeat_min)
4838            {            {
4839  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4840            if (utf8 && c >= 128)            if (utf && (c & UTF_LENGTH) != 0)
4841              {              {
4842              memcpy(code, utf8_char, c & 7);              memcpy(code, utf_chars, IN_UCHARS(c & 7));
4843              code += c & 7;              code += c & 7;
4844              }              }
4845            else            else
# Line 4379  for (;; ptr++) Line 4866  for (;; ptr++)
4866    
4867        /* The character or character type itself comes last in all cases. */        /* The character or character type itself comes last in all cases. */
4868    
4869  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4870        if (utf8 && c >= 128)        if (utf && (c & UTF_LENGTH) != 0)
4871          {          {
4872          memcpy(code, utf8_char, c & 7);          memcpy(code, utf_chars, IN_UCHARS(c & 7));
4873          code += c & 7;          code += c & 7;
4874          }          }
4875        else        else
# Line 4406  for (;; ptr++) Line 4893  for (;; ptr++)
4893    
4894      else if (*previous == OP_CLASS ||      else if (*previous == OP_CLASS ||
4895               *previous == OP_NCLASS ||               *previous == OP_NCLASS ||
4896  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4897               *previous == OP_XCLASS ||               *previous == OP_XCLASS ||
4898  #endif  #endif
4899               *previous == OP_REF)               *previous == OP_REF ||
4900                 *previous == OP_REFI)
4901        {        {
4902        if (repeat_max == 0)        if (repeat_max == 0)
4903          {          {
# Line 4443  for (;; ptr++) Line 4931  for (;; ptr++)
4931        }        }
4932    
4933      /* If previous was a bracket group, we may have to replicate it in certain      /* If previous was a bracket group, we may have to replicate it in certain
4934      cases. */      cases. Note that at this point we can encounter only the "basic" bracket
4935        opcodes such as BRA and CBRA, as this is the place where they get converted
4936        into the more special varieties such as BRAPOS and SBRA. A test for >=
4937        OP_ASSERT and <= OP_COND includes ASSERT, ASSERT_NOT, ASSERTBACK,
4938        ASSERTBACK_NOT, ONCE, BRA, CBRA, and COND. Originally, PCRE did not allow
4939        repetition of assertions, but now it does, for Perl compatibility. */
4940    
4941      else if (*previous == OP_BRA  || *previous == OP_CBRA ||      else if (*previous >= OP_ASSERT && *previous <= OP_COND)
              *previous == OP_ONCE || *previous == OP_COND)  
4942        {        {
4943        register int i;        register int i;
       int ketoffset = 0;  
4944        int len = (int)(code - previous);        int len = (int)(code - previous);
4945        uschar *bralink = NULL;        pcre_uchar *bralink = NULL;
4946          pcre_uchar *brazeroptr = NULL;
4947    
4948        /* Repeating a DEFINE group is pointless */        /* Repeating a DEFINE group is pointless, but Perl allows the syntax, so
4949          we just ignore the repeat. */
4950    
4951        if (*previous == OP_COND && previous[LINK_SIZE+1] == OP_DEF)        if (*previous == OP_COND && previous[LINK_SIZE+1] == OP_DEF)
4952          {          goto END_REPEAT;
4953          *errorcodeptr = ERR55;  
4954          goto FAILED;        /* There is no sense in actually repeating assertions. The only potential
4955          }        use of repetition is in cases when the assertion is optional. Therefore,
4956          if the minimum is greater than zero, just ignore the repeat. If the
4957          maximum is not not zero or one, set it to 1. */
4958    
4959        /* If the maximum repeat count is unlimited, find the end of the bracket        if (*previous < OP_ONCE)    /* Assertion */
4960        by scanning through from the start, and compute the offset back to it          {
4961        from the current code pointer. There may be an OP_OPT setting following          if (repeat_min > 0) goto END_REPEAT;
4962        the final KET, so we can't find the end just by going back from the code          if (repeat_max < 0 || repeat_max > 1) repeat_max = 1;
       pointer. */  
   
       if (repeat_max == -1)  
         {  
         register uschar *ket = previous;  
         do ket += GET(ket, 1); while (*ket != OP_KET);  
         ketoffset = (int)(code - ket);  
4963          }          }
4964    
4965        /* The case of a zero minimum is special because of the need to stick        /* The case of a zero minimum is special because of the need to stick
# Line 4492  for (;; ptr++) Line 4980  for (;; ptr++)
4980          **   goto END_REPEAT;          **   goto END_REPEAT;
4981          **   }          **   }
4982    
4983          However, that fails when a group is referenced as a subroutine from          However, that fails when a group or a subgroup within it is referenced
4984          elsewhere in the pattern, so now we stick in OP_SKIPZERO in front of it          as a subroutine from elsewhere in the pattern, so now we stick in
4985          so that it is skipped on execution. As we don't have a list of which          OP_SKIPZERO in front of it so that it is skipped on execution. As we
4986          groups are referenced, we cannot do this selectively.          don't have a list of which groups are referenced, we cannot do this
4987            selectively.
4988    
4989          If the maximum is 1 or unlimited, we just have to stick in the BRAZERO          If the maximum is 1 or unlimited, we just have to stick in the BRAZERO
4990          and do no more at this point. However, we do need to adjust any          and do no more at this point. However, we do need to adjust any
# Line 4507  for (;; ptr++) Line 4996  for (;; ptr++)
4996          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */
4997            {            {
4998            *code = OP_END;            *code = OP_END;
4999            adjust_recurse(previous, 1, utf8, cd, save_hwm);            adjust_recurse(previous, 1, utf, cd, save_hwm);
5000            memmove(previous+1, previous, len);            memmove(previous + 1, previous, IN_UCHARS(len));
5001            code++;            code++;
5002            if (repeat_max == 0)            if (repeat_max == 0)
5003              {              {
5004              *previous++ = OP_SKIPZERO;              *previous++ = OP_SKIPZERO;
5005              goto END_REPEAT;              goto END_REPEAT;
5006              }              }
5007              brazeroptr = previous;    /* Save for possessive optimizing */
5008            *previous++ = OP_BRAZERO + repeat_type;            *previous++ = OP_BRAZERO + repeat_type;
5009            }            }
5010    
# Line 4530  for (;; ptr++) Line 5020  for (;; ptr++)
5020            {            {
5021            int offset;            int offset;
5022            *code = OP_END;            *code = OP_END;
5023            adjust_recurse(previous, 2 + LINK_SIZE, utf8, cd, save_hwm);            adjust_recurse(previous, 2 + LINK_SIZE, utf, cd, save_hwm);
5024            memmove(previous + 2 + LINK_SIZE, previous, len);            memmove(previous + 2 + LINK_SIZE, previous, IN_UCHARS(len));
5025            code += 2 + LINK_SIZE;            code += 2 + LINK_SIZE;
5026            *previous++ = OP_BRAZERO + repeat_type;            *previous++ = OP_BRAZERO + repeat_type;
5027            *previous++ = OP_BRA;            *previous++ = OP_BRA;
# Line 4581  for (;; ptr++) Line 5071  for (;; ptr++)
5071    
5072            else            else
5073              {              {
5074              if (groupsetfirstbyte && reqbyte < 0) reqbyte = firstbyte;              if (groupsetfirstchar && reqchar < 0) reqchar = firstchar;
5075              for (i = 1; i < repeat_min; i++)              for (i = 1; i < repeat_min; i++)
5076                {                {
5077                uschar *hc;                pcre_uchar *hc;
5078                uschar *this_hwm = cd->hwm;                pcre_uchar *this_hwm = cd->hwm;
5079                memcpy(code, previous, len);                memcpy(code, previous, IN_UCHARS(len));
5080                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)                for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
5081                  {                  {
5082                  PUT(cd->hwm, 0, GET(hc, 0) + len);                  PUT(cd->hwm, 0, GET(hc, 0) + len);
# Line 4636  for (;; ptr++) Line 5126  for (;; ptr++)
5126    
5127          else for (i = repeat_max - 1; i >= 0; i--)          else for (i = repeat_max - 1; i >= 0; i--)
5128            {            {
5129            uschar *hc;            pcre_uchar *hc;
5130            uschar *this_hwm = cd->hwm;            pcre_uchar *this_hwm = cd->hwm;
5131    
5132            *code++ = OP_BRAZERO + repeat_type;            *code++ = OP_BRAZERO + repeat_type;
5133    
# Line 4653  for (;; ptr++) Line 5143  for (;; ptr++)
5143              PUTINC(code, 0, offset);              PUTINC(code, 0, offset);
5144              }              }
5145    
5146            memcpy(code, previous, len);            memcpy(code, previous, IN_UCHARS(len));
5147            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)            for (hc = save_hwm; hc < this_hwm; hc += LINK_SIZE)
5148              {              {
5149              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 4670  for (;; ptr++) Line 5160  for (;; ptr++)
5160            {            {
5161            int oldlinkoffset;            int oldlinkoffset;
5162            int offset = (int)(code - bralink + 1);            int offset = (int)(code - bralink + 1);
5163            uschar *bra = code - offset;            pcre_uchar *bra = code - offset;
5164            oldlinkoffset = GET(bra, 1);            oldlinkoffset = GET(bra, 1);
5165            bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;            bralink = (oldlinkoffset == 0)? NULL : bralink - oldlinkoffset;
5166            *code++ = OP_KET;            *code++ = OP_KET;
# Line 4679  for (;; ptr++) Line 5169  for (;; ptr++)
5169            }            }
5170          }          }
5171    
5172        /* If the maximum is unlimited, set a repeater in the final copy. We        /* If the maximum is unlimited, set a repeater in the final copy. For
5173        can't just offset backwards from the current code point, because we        ONCE brackets, that's all we need to do. However, possessively repeated
5174        don't know if there's been an options resetting after the ket. The        ONCE brackets can be converted into non-capturing brackets, as the
5175        correct offset was computed above.        behaviour of (?:xx)++ is the same as (?>xx)++ and this saves having to
5176          deal with possessive ONCEs specially.
5177        Then, when we are doing the actual compile phase, check to see whether  
5178        this group is a non-atomic one that could match an empty string. If so,        Otherwise, when we are doing the actual compile phase, check to see
5179          whether this group is one that could match an empty string. If so,
5180        convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so        convert the initial operator to the S form (e.g. OP_BRA -> OP_SBRA) so
5181        that runtime checking can be done. [This check is also applied to        that runtime checking can be done. [This check is also applied to ONCE
5182        atomic groups at runtime, but in a different way.] */        groups at runtime, but in a different way.]
5183    
5184          Then, if the quantifier was possessive and the bracket is not a
5185          conditional, we convert the BRA code to the POS form, and the KET code to
5186          KETRPOS. (It turns out to be convenient at runtime to detect this kind of
5187          subpattern at both the start and at the end.) The use of special opcodes
5188          makes it possible to reduce greatly the stack usage in pcre_exec(). If
5189          the group is preceded by OP_BRAZERO, convert this to OP_BRAPOSZERO.
5190    
5191          Then, if the minimum number of matches is 1 or 0, cancel the possessive
5192          flag so that the default action below, of wrapping everything inside
5193          atomic brackets, does not happen. When the minimum is greater than 1,
5194          there will be earlier copies of the group, and so we still have to wrap
5195          the whole thing. */
5196    
5197        else        else
5198          {          {
5199          uschar *ketcode = code - ketoffset;          pcre_uchar *ketcode = code - 1 - LINK_SIZE;
5200          uschar *bracode = ketcode - GET(ketcode, 1);          pcre_uchar *bracode = ketcode - GET(ketcode, 1);
5201          *ketcode = OP_KETRMAX + repeat_type;  
5202          if (lengthptr == NULL && *bracode != OP_ONCE)          /* Convert possessive ONCE brackets to non-capturing */
5203    
5204            if ((*bracode == OP_ONCE || *bracode == OP_ONCE_NC) &&
5205                possessive_quantifier) *bracode = OP_BRA;
5206    
5207            /* For non-possessive ONCE brackets, all we need to do is to
5208            set the KET. */
5209    
5210            if (*bracode == OP_ONCE || *bracode == OP_ONCE_NC)
5211              *ketcode = OP_KETRMAX + repeat_type;
5212    
5213            /* Handle non-ONCE brackets and possessive ONCEs (which have been
5214            converted to non-capturing above). */
5215    
5216            else
5217            {            {
5218            uschar *scode = bracode;            /* In the compile phase, check for empty string matching. */
5219            do  
5220              if (lengthptr == NULL)
5221              {              {
5222              if (could_be_empty_branch(scode, ketcode, utf8, cd))              pcre_uchar *scode = bracode;
5223                do
5224                {                {
5225                *bracode += OP_SBRA - OP_BRA;                if (could_be_empty_branch(scode, ketcode, utf, cd))
5226                break;                  {
5227                    *bracode += OP_SBRA - OP_BRA;
5228                    break;
5229                    }
5230                  scode += GET(scode, 1);
5231                }                }
5232              scode += GET(scode, 1);              while (*scode == OP_ALT);
5233              }              }
5234            while (*scode == OP_ALT);  
5235              /* Handle possessive quantifiers. */
5236    
5237              if (possessive_quantifier)
5238                {
5239                /* For COND brackets, we wrap the whole thing in a possessively
5240                repeated non-capturing bracket, because we have not invented POS
5241                versions of the COND opcodes. Because we are moving code along, we
5242                must ensure that any pending recursive references are updated. */
5243    
5244                if (*bracode == OP_COND || *bracode == OP_SCOND)
5245                  {
5246                  int nlen = (int)(code - bracode);
5247                  *code = OP_END;
5248                  adjust_recurse(bracode, 1 + LINK_SIZE, utf, cd, save_hwm);
5249                  memmove(bracode + 1 + LINK_SIZE, bracode, IN_UCHARS(nlen));
5250                  code += 1 + LINK_SIZE;
5251                  nlen += 1 + LINK_SIZE;
5252                  *bracode = OP_BRAPOS;
5253                  *code++ = OP_KETRPOS;
5254                  PUTINC(code, 0, nlen);
5255                  PUT(bracode, 1, nlen);
5256                  }
5257    
5258                /* For non-COND brackets, we modify the BRA code and use KETRPOS. */
5259    
5260                else
5261                  {
5262                  *bracode += 1;              /* Switch to xxxPOS opcodes */
5263                  *ketcode = OP_KETRPOS;
5264                  }
5265    
5266                /* If the minimum is zero, mark it as possessive, then unset the
5267                possessive flag when the minimum is 0 or 1. */
5268    
5269                if (brazeroptr != NULL) *brazeroptr = OP_BRAPOSZERO;
5270                if (repeat_min < 2) possessive_quantifier = FALSE;
5271                }
5272    
5273              /* Non-possessive quantifier */
5274    
5275              else *ketcode = OP_KETRMAX + repeat_type;
5276            }            }
5277          }          }
5278        }        }
# Line 4728  for (;; ptr++) Line 5293  for (;; ptr++)
5293        }        }
5294    
5295      /* If the character following a repeat is '+', or if certain optimization      /* If the character following a repeat is '+', or if certain optimization
5296      tests above succeeded, possessive_quantifier is TRUE. For some of the      tests above succeeded, possessive_quantifier is TRUE. For some opcodes,
5297      simpler opcodes, there is an special alternative opcode for this. For      there are special alternative opcodes for this case. For anything else, we
5298      anything else, we wrap the entire repeated item inside OP_ONCE brackets.      wrap the entire repeated item inside OP_ONCE brackets. Logically, the '+'
5299      The '+' notation is just syntactic sugar, taken from Sun's Java package,      notation is just syntactic sugar, taken from Sun's Java package, but the
5300      but the special opcodes can optimize it a bit. The repeated item starts at      special opcodes can optimize it.
5301      tempcode, not at previous, which might be the first part of a string whose  
5302      (former) last char we repeated.      Some (but not all) possessively repeated subpatterns have already been
5303        completely handled in the code just above. For them, possessive_quantifier
5304        is always FALSE at this stage.
5305    
5306        Note that the repeated item starts at tempcode, not at previous, which
5307        might be the first part of a string whose (former) last char we repeated.
5308    
5309      Possessifying an 'exact' quantifier has no effect, so we can ignore it. But      Possessifying an 'exact' quantifier has no effect, so we can ignore it. But
5310      an 'upto' may follow. We skip over an 'exact' item, and then test the      an 'upto' may follow. We skip over an 'exact' item, and then test the
# Line 4745  for (;; ptr++) Line 5315  for (;; ptr++)
5315        int len;        int len;
5316    
5317        if (*tempcode == OP_TYPEEXACT)        if (*tempcode == OP_TYPEEXACT)
5318          tempcode += _pcre_OP_lengths[*tempcode] +          tempcode += PRIV(OP_lengths)[*tempcode] +
5319            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);            ((tempcode[1 + IMM2_SIZE] == OP_PROP
5320              || tempcode[1 + IMM2_SIZE] == OP_NOTPROP)? 2 : 0);
5321    
5322        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
5323          {          {
5324          tempcode += _pcre_OP_lengths[*tempcode];          tempcode += PRIV(OP_lengths)[*tempcode];
5325  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
5326          if (utf8 && tempcode[-1] >= 0xc0)          if (utf && HAS_EXTRALEN(tempcode[-1]))
5327            tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];            tempcode += GET_EXTRALEN(tempcode[-1]);
5328  #endif  #endif
5329          }          }
5330    
# Line 4765  for (;; ptr++) Line 5336  for (;; ptr++)
5336          case OP_QUERY: *tempcode = OP_POSQUERY; break;          case OP_QUERY: *tempcode = OP_POSQUERY; break;
5337          case OP_UPTO:  *tempcode = OP_POSUPTO; break;          case OP_UPTO:  *tempcode = OP_POSUPTO; break;
5338    
5339          case OP_TYPESTAR:  *tempcode = OP_TYPEPOSSTAR; break;          case OP_STARI:  *tempcode = OP_POSSTARI; break;
5340          case OP_TYPEPLUS:  *tempcode = OP_TYPEPOSPLUS; break;          case OP_PLUSI:  *tempcode = OP_POSPLUSI; break;
5341          case OP_TYPEQUERY: *tempcode = OP_TYPEPOSQUERY; break;          case OP_QUERYI: *tempcode = OP_POSQUERYI; break;
5342          case OP_TYPEUPTO:  *tempcode = OP_TYPEPOSUPTO; break;          case OP_UPTOI:  *tempcode = OP_POSUPTOI; break;
5343    
5344          case OP_NOTSTAR:  *tempcode = OP_NOTPOSSTAR; break;          case OP_NOTSTAR:  *tempcode = OP_NOTPOSSTAR; break;
5345          case OP_NOTPLUS:  *tempcode = OP_NOTPOSPLUS; break;          case OP_NOTPLUS:  *tempcode = OP_NOTPOSPLUS; break;
5346          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;
5347          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;
5348    
5349            case OP_NOTSTARI:  *tempcode = OP_NOTPOSSTARI; break;
5350            case OP_NOTPLUSI:  *tempcode = OP_NOTPOSPLUSI; break;
5351            case OP_NOTQUERYI: *tempcode = OP_NOTPOSQUERYI; break;
5352            case OP_NOTUPTOI:  *tempcode = OP_NOTPOSUPTOI; break;
5353    
5354            case OP_TYPESTAR:  *tempcode = OP_TYPEPOSSTAR; break;
5355            case OP_TYPEPLUS:  *tempcode = OP_TYPEPOSPLUS; break;
5356            case OP_TYPEQUERY: *tempcode = OP_TYPEPOSQUERY; break;
5357            case OP_TYPEUPTO:  *tempcode = OP_TYPEPOSUPTO; break;
5358    
5359          /* Because we are moving code along, we must ensure that any          /* Because we are moving code along, we must ensure that any
5360          pending recursive references are updated. */          pending recursive references are updated. */
5361    
5362          default:          default:
5363          *code = OP_END;          *code = OP_END;
5364          adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);          adjust_recurse(tempcode, 1 + LINK_SIZE, utf, cd, save_hwm);
5365          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1 + LINK_SIZE, tempcode, IN_UCHARS(len));
5366          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
5367          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
5368          tempcode[0] = OP_ONCE;          tempcode[0] = OP_ONCE;
# Line 4793  for (;; ptr++) Line 5374  for (;; ptr++)
5374        }        }
5375    
5376      /* In all case we no longer have a previous item. We also set the      /* In all case we no longer have a previous item. We also set the
5377      "follows varying string" flag for subsequently encountered reqbytes if      "follows varying string" flag for subsequently encountered reqchars if
5378      it isn't already set and we have just passed a varying length item. */      it isn't already set and we have just passed a varying length item. */
5379    
5380      END_REPEAT:      END_REPEAT:
# Line 4822  for (;; ptr++) Line 5403  for (;; ptr++)
5403        int i, namelen;        int i, namelen;
5404        int arglen = 0;        int arglen = 0;
5405        const char *vn = verbnames;        const char *vn = verbnames;
5406        const uschar *name = ptr + 1;        const pcre_uchar *name = ptr + 1;
5407        const uschar *arg = NULL;        const pcre_uchar *arg = NULL;
5408        previous = NULL;        previous = NULL;
5409        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};
5410        namelen = (int)(ptr - name);        namelen = (int)(ptr - name);
5411    
5412          /* It appears that Perl allows any characters whatsoever, other than
5413          a closing parenthesis, to appear in arguments, so we no longer insist on
5414          letters, digits, and underscores. */
5415    
5416        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
5417          {          {
5418          arg = ++ptr;          arg = ++ptr;
5419          while ((cd->ctypes[*ptr] & (ctype_letter|ctype_digit)) != 0          while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
           || *ptr == '_') ptr++;  
5420          arglen = (int)(ptr - arg);          arglen = (int)(ptr - arg);
5421          }          }
5422    
# Line 4847  for (;; ptr++) Line 5431  for (;; ptr++)
5431        for (i = 0; i < verbcount; i++)        for (i = 0; i < verbcount; i++)
5432          {          {
5433          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
5434              strncmp((char *)name, vn, namelen) == 0)              STRNCMP_UC_C8(name, vn, namelen) == 0)
5435            {            {
5436            /* Check for open captures before ACCEPT */            /* Check for open captures before ACCEPT and convert it to
5437              ASSERT_ACCEPT if in an assertion. */
5438    
5439            if (verbs[i].op == OP_ACCEPT)            if (verbs[i].op == OP_ACCEPT)
5440              {              {
5441              open_capitem *oc;              open_capitem *oc;
5442                if (arglen != 0)
5443                  {
5444                  *errorcodeptr = ERR59;
5445                  goto FAILED;
5446                  }
5447              cd->had_accept = TRUE;              cd->had_accept = TRUE;
5448              for (oc = cd->open_caps; oc != NULL; oc = oc->next)              for (oc = cd->open_caps; oc != NULL; oc = oc->next)
5449                {                {
5450                *code++ = OP_CLOSE;                *code++ = OP_CLOSE;
5451                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
5452                }                }
5453                *code++ = (cd->assert_depth > 0)? OP_ASSERT_ACCEPT : OP_ACCEPT;
5454    
5455                /* Do not set firstchar after *ACCEPT */
5456                if (firstchar == REQ_UNSET) firstchar = REQ_NONE;
5457              }              }
5458    
5459            /* Handle the cases with/without an argument */            /* Handle other cases with/without an argument */
5460    
5461            if (arglen == 0)            else if (arglen == 0)
5462              {              {
5463              if (verbs[i].op < 0)   /* Argument is mandatory */              if (verbs[i].op < 0)   /* Argument is mandatory */
5464                {                {
# Line 4872  for (;; ptr++) Line 5466  for (;; ptr++)
5466                goto FAILED;                goto FAILED;
5467                }                }
5468              *code = verbs[i].op;              *code = verbs[i].op;
5469              if (*code++ == OP_THEN)              if (*code++ == OP_THEN) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5470              }              }
5471    
5472            else            else
# Line 4887  for (;; ptr++) Line 5477  for (;; ptr++)
5477                goto FAILED;                goto FAILED;
5478                }                }
5479              *code = verbs[i].op_arg;              *code = verbs[i].op_arg;
5480              if (*code++ == OP_THEN_ARG)              if (*code++ == OP_THEN_ARG) cd->external_flags |= PCRE_HASTHEN;
               {  
               PUT(code, 0, code - bcptr->current_branch - 1);  
               code += LINK_SIZE;  
               }  
5481              *code++ = arglen;              *code++ = arglen;
5482              memcpy(code, arg, arglen);              memcpy(code, arg, IN_UCHARS(arglen));
5483              code += arglen;              code += arglen;
5484              *code++ = 0;              *code++ = 0;
5485              }              }
# Line 4916  for (;; ptr++) Line 5502  for (;; ptr++)
5502        {        {
5503        int i, set, unset, namelen;        int i, set, unset, namelen;
5504        int *optset;        int *optset;
5505        const uschar *name;        const pcre_uchar *name;
5506        uschar *slot;        pcre_uchar *slot;
5507    
5508        switch (*(++ptr))        switch (*(++ptr))
5509          {          {
# Line 4970  for (;; ptr++) Line 5556  for (;; ptr++)
5556            break;            break;
5557    
5558          /* Most other conditions use OP_CREF (a couple change to OP_RREF          /* Most other conditions use OP_CREF (a couple change to OP_RREF
5559          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. */
5560    
5561          code[1+LINK_SIZE] = OP_CREF;          code[1+LINK_SIZE] = OP_CREF;
5562          skipbytes = 3;          skipbytes = 1+IMM2_SIZE;
5563          refsign = -1;          refsign = -1;
5564    
5565          /* Check for a test for recursion in a named group. */          /* Check for a test for recursion in a named group. */
# Line 5020  for (;; ptr++) Line 5606  for (;; ptr++)
5606          while ((cd->ctypes[*ptr] & ctype_word) != 0)          while ((cd->ctypes[*ptr] & ctype_word) != 0)
5607            {            {
5608            if (recno >= 0)            if (recno >= 0)
5609              recno = ((digitab[*ptr] & ctype_digit) != 0)?              recno = (IS_DIGIT(*ptr))? recno * 10 + *ptr - CHAR_0 : -1;
               recno * 10 + *ptr - CHAR_0 : -1;  
5610            ptr++;            ptr++;
5611            }            }
5612          namelen = (int)(ptr - name);          namelen = (int)(ptr - name);
# Line 5069  for (;; ptr++) Line 5654  for (;; ptr++)
5654          slot = cd->name_table;          slot = cd->name_table;
5655          for (i = 0; i < cd->names_found; i++)          for (i = 0; i < cd->names_found; i++)
5656            {            {
5657            if (strncmp((char *)name, (char *)slot+2, namelen) == 0) break;            if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0) break;
5658            slot += cd->name_entry_size;            slot += cd->name_entry_size;
5659            }            }
5660    
# Line 5085  for (;; ptr++) Line 5670  for (;; ptr++)
5670          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
5671    
5672          else if ((i = find_parens(cd, name, namelen,          else if ((i = find_parens(cd, name, namelen,
5673                          (options & PCRE_EXTENDED) != 0, utf8)) > 0)                          (options & PCRE_EXTENDED) != 0, utf)) > 0)
5674            {            {
5675            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
5676            code[1+LINK_SIZE]++;            code[1+LINK_SIZE]++;
# Line 5111  for (;; ptr++) Line 5696  for (;; ptr++)
5696            recno = 0;            recno = 0;
5697            for (i = 1; i < namelen; i++)            for (i = 1; i < namelen; i++)
5698              {              {
5699              if ((digitab[name[i]] & ctype_digit) == 0)              if (!IS_DIGIT(name[i]))
5700                {                {
5701                *errorcodeptr = ERR15;                *errorcodeptr = ERR15;
5702                goto FAILED;                goto FAILED;
# Line 5126  for (;; ptr++) Line 5711  for (;; ptr++)
5711          /* Similarly, check for the (?(DEFINE) "condition", which is always          /* Similarly, check for the (?(DEFINE) "condition", which is always
5712          false. */          false. */
5713    
5714          else if (namelen == 6 && strncmp((char *)name, STRING_DEFINE, 6) == 0)          else if (namelen == 6 && STRNCMP_UC_C8(name, STRING_DEFINE, 6) == 0)
5715            {            {
5716            code[1+LINK_SIZE] = OP_DEF;            code[1+LINK_SIZE] = OP_DEF;
5717            skipbytes = 1;            skipbytes = 1;
# Line 5153  for (;; ptr++) Line 5738  for (;; ptr++)
5738          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5739          case CHAR_EQUALS_SIGN:                 /* Positive lookahead */          case CHAR_EQUALS_SIGN:                 /* Positive lookahead */
5740          bravalue = OP_ASSERT;          bravalue = OP_ASSERT;
5741            cd->assert_depth += 1;
5742          ptr++;          ptr++;
5743          break;          break;
5744    
# Line 5167  for (;; ptr++) Line 5753  for (;; ptr++)
5753            continue;            continue;
5754            }            }
5755          bravalue = OP_ASSERT_NOT;          bravalue = OP_ASSERT_NOT;
5756            cd->assert_depth += 1;
5757          break;          break;
5758    
5759    
# Line 5176  for (;; ptr++) Line 5763  for (;; ptr++)
5763            {            {
5764            case CHAR_EQUALS_SIGN:               /* Positive lookbehind */            case CHAR_EQUALS_SIGN:               /* Positive lookbehind */
5765            bravalue = OP_ASSERTBACK;            bravalue = OP_ASSERTBACK;
5766              cd->assert_depth += 1;
5767            ptr += 2;            ptr += 2;
5768            break;            break;
5769    
5770            case CHAR_EXCLAMATION_MARK:          /* Negative lookbehind */            case CHAR_EXCLAMATION_MARK:          /* Negative lookbehind */
5771            bravalue = OP_ASSERTBACK_NOT;            bravalue = OP_ASSERTBACK_NOT;
5772              cd->assert_depth += 1;
5773            ptr += 2;            ptr += 2;
5774            break;            break;
5775    
# Line 5202  for (;; ptr++) Line 5791  for (;; ptr++)
5791    
5792          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
5793          case CHAR_C:                 /* Callout - may be followed by digits; */          case CHAR_C:                 /* Callout - may be followed by digits; */
5794          previous_callout = code;  /* Save for later completion */          previous_callout = code;     /* Save for later completion */
5795          after_manual_callout = 1; /* Skip one item before completing */          after_manual_callout = 1;    /* Skip one item before completing */
5796          *code++ = OP_CALLOUT;          *code++ = OP_CALLOUT;
5797            {            {
5798            int n = 0;            int n = 0;
5799            while ((digitab[*(++ptr)] & ctype_digit) != 0)            ptr++;
5800              n = n * 10 + *ptr - CHAR_0;            while(IS_DIGIT(*ptr))
5801                n = n * 10 + *ptr++ - CHAR_0;
5802            if (*ptr != CHAR_RIGHT_PARENTHESIS)            if (*ptr != CHAR_RIGHT_PARENTHESIS)
5803              {              {
5804              *errorcodeptr = ERR39;              *errorcodeptr = ERR39;
# Line 5270  for (;; ptr++) Line 5860  for (;; ptr++)
5860                *errorcodeptr = ERR49;                *errorcodeptr = ERR49;
5861                goto FAILED;                goto FAILED;
5862                }                }
5863              if (namelen + 3 > cd->name_entry_size)              if (namelen + IMM2_SIZE + 1 > cd->name_entry_size)
5864                {                {
5865                cd->name_entry_size = namelen + 3;                cd->name_entry_size = namelen + IMM2_SIZE + 1;
5866                if (namelen > MAX_NAME_SIZE)                if (namelen > MAX_NAME_SIZE)
5867                  {                  {
5868                  *errorcodeptr = ERR48;                  *errorcodeptr = ERR48;
# Line 5301  for (;; ptr++) Line 5891  for (;; ptr++)
5891    
5892              for (i = 0; i < cd->names_found; i++)              for (i = 0; i < cd->names_found; i++)
5893                {                {
5894                int crc = memcmp(name, slot+2, namelen);                int crc = memcmp(name, slot+IMM2_SIZE, IN_UCHARS(namelen));
5895                if (crc == 0)                if (crc == 0)
5896                  {                  {
5897                  if (slot[2+namelen] == 0)                  if (slot[IMM2_SIZE+namelen] == 0)
5898                    {                    {
5899                    if (GET2(slot, 0) != cd->bracount + 1 &&                    if (GET2(slot, 0) != cd->bracount + 1 &&
5900                        (options & PCRE_DUPNAMES) == 0)                        (options & PCRE_DUPNAMES) == 0)
# Line 5325  for (;; ptr++) Line 5915  for (;; ptr++)
5915                if (crc < 0)                if (crc < 0)
5916                  {                  {
5917                  memmove(slot + cd->name_entry_size, slot,                  memmove(slot + cd->name_entry_size, slot,
5918                    (cd->names_found - i) * cd->name_entry_size);                    IN_UCHARS((cd->names_found - i) * cd->name_entry_size));
5919                  break;                  break;
5920                  }                  }
5921    
# Line 5339  for (;; ptr++) Line 5929  for (;; ptr++)
5929    
5930              if (!dupname)              if (!dupname)
5931                {                {
5932                uschar *cslot = cd->name_table;                pcre_uchar *cslot = cd->name_table;
5933                for (i = 0; i < cd->names_found; i++)                for (i = 0; i < cd->names_found; i++)
5934                  {                  {
5935                  if (cslot != slot)                  if (cslot != slot)
# Line 5356  for (;; ptr++) Line 5946  for (;; ptr++)
5946                }                }
5947    
5948              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
5949              memcpy(slot + 2, name, namelen);              memcpy(slot + IMM2_SIZE, name, IN_UCHARS(namelen));
5950              slot[2+namelen] = 0;              slot[IMM2_SIZE + namelen] = 0;
5951              }              }
5952            }            }
5953    
# Line 5395  for (;; ptr++) Line 5985  for (;; ptr++)
5985    
5986          if (lengthptr != NULL)          if (lengthptr != NULL)
5987            {            {
5988            const uschar *temp;            const pcre_uchar *temp;
5989    
5990            if (namelen == 0)            if (namelen == 0)
5991              {              {
# Line 5425  for (;; ptr++) Line 6015  for (;; ptr++)
6015            temp = cd->end_pattern;            temp = cd->end_pattern;
6016            cd->end_pattern = ptr;            cd->end_pattern = ptr;
6017            recno = find_parens(cd, name, namelen,            recno = find_parens(cd, name, namelen,
6018              (options & PCRE_EXTENDED) != 0, utf8);              (options & PCRE_EXTENDED) != 0, utf);
6019            cd->end_pattern = temp;            cd->end_pattern = temp;
6020            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */            if (recno < 0) recno = 0;    /* Forward ref; set dummy number */
6021            }            }
# Line 5440  for (;; ptr++) Line 6030  for (;; ptr++)
6030            slot = cd->name_table;            slot = cd->name_table;
6031            for (i = 0; i < cd->names_found; i++)            for (i = 0; i < cd->names_found; i++)
6032              {              {
6033              if (strncmp((char *)name, (char *)slot+2, namelen) == 0 &&              if (STRNCMP_UC_UC(name, slot+IMM2_SIZE, namelen) == 0 &&
6034                  slot[2+namelen] == 0)                  slot[IMM2_SIZE+namelen] == 0)
6035                break;                break;
6036              slot += cd->name_entry_size;              slot += cd->name_entry_size;
6037              }              }
# Line 5452  for (;; ptr++) Line 6042  for (;; ptr++)
6042              }              }
6043            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
6044                      find_parens(cd, name, namelen,                      find_parens(cd, name, namelen,
6045                        (options & PCRE_EXTENDED) != 0, utf8)) <= 0)                        (options & PCRE_EXTENDED) != 0, utf)) <= 0)
6046              {              {
6047              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
6048              goto FAILED;              goto FAILED;
# Line 5477  for (;; ptr++)