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

Diff of /code/trunk/pcre_compile.c

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

revision 408 by ph10, Fri Mar 27 17:52:03 2009 UTC revision 500 by ph10, Sat Mar 6 19:00:29 2010 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2009 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 53  supporting internal functions that are n Line 53  supporting internal functions that are n
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    
56  /* When DEBUG is defined, we need the pcre_printint() function, which is also  /* When PCRE_DEBUG is defined, we need the pcre_printint() function, which is
57  used by pcretest. DEBUG is not defined when building a production library. */  also used by pcretest. PCRE_DEBUG is not defined when building a production
58    library. */
59    
60  #ifdef DEBUG  #ifdef PCRE_DEBUG
61  #include "pcre_printint.src"  #include "pcre_printint.src"
62  #endif  #endif
63    
# Line 262  the number of relocations needed when a Line 263  the number of relocations needed when a
263  it is now one long string. We cannot use a table of offsets, because the  it is now one long string. We cannot use a table of offsets, because the
264  lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we  lengths of inserts such as XSTRING(MAX_NAME_SIZE) are not known. Instead, we
265  simply count through to the one we want - this isn't a performance issue  simply count through to the one we want - this isn't a performance issue
266  because these strings are used only when there is a compilation error. */  because these strings are used only when there is a compilation error.
267    
268    Each substring ends with \0 to insert a null character. This includes the final
269    substring, so that the whole string ends with \0\0, which can be detected when
270    counting through. */
271    
272  static const char error_texts[] =  static const char error_texts[] =
273    "no error\0"    "no error\0"
# Line 341  static const char error_texts[] = Line 346  static const char error_texts[] =
346    "number is too big\0"    "number is too big\0"
347    "subpattern name expected\0"    "subpattern name expected\0"
348    "digit expected after (?+\0"    "digit expected after (?+\0"
349    "] is an invalid data character in JavaScript compatibility mode";    "] is an invalid data character in JavaScript compatibility mode\0"
350      /* 65 */
351      "different names for subpatterns of the same number are not allowed\0";
352    
353  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
354  patterns. Note that the tables in chartables are dependent on the locale, and  patterns. Note that the tables in chartables are dependent on the locale, and
# Line 500  static const char * Line 506  static const char *
506  find_error_text(int n)  find_error_text(int n)
507  {  {
508  const char *s = error_texts;  const char *s = error_texts;
509  for (; n > 0; n--) while (*s++ != 0) {};  for (; n > 0; n--)
510      {
511      while (*s++ != 0) {};
512      if (*s == 0) return "Error text not found (please report)";
513      }
514  return s;  return s;
515  }  }
516    
# Line 1019  subpatterns, and counting them. If it fi Line 1029  subpatterns, and counting them. If it fi
1029  name it is given, it returns its number. Alternatively, if the name is NULL, it  name it is given, it returns its number. Alternatively, if the name is NULL, it
1030  returns when it reaches a given numbered subpattern. We know that if (?P< is  returns when it reaches a given numbered subpattern. We know that if (?P< is
1031  encountered, the name will be terminated by '>' because that is checked in the  encountered, the name will be terminated by '>' because that is checked in the
1032  first pass. Recursion is used to keep track of subpatterns that reset the  first pass. Recursion is used to keep track of subpatterns that reset the
1033  capturing group numbers - the (?| feature.  capturing group numbers - the (?| feature.
1034    
1035  Arguments:  Arguments:
# Line 1028  Arguments: Line 1038  Arguments:
1038    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
1039    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
1040    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
1041    count        pointer to the current capturing subpattern number (updated)    count        pointer to the current capturing subpattern number (updated)
1042    
1043  Returns:       the number of the named subpattern, or -1 if not found  Returns:       the number of the named subpattern, or -1 if not found
1044  */  */
# Line 1042  int start_count = *count; Line 1052  int start_count = *count;
1052  int hwm_count = start_count;  int hwm_count = start_count;
1053  BOOL dup_parens = FALSE;  BOOL dup_parens = FALSE;
1054    
1055  /* If the first character is a parenthesis, check on the type of group we are  /* If the first character is a parenthesis, check on the type of group we are
1056  dealing with. The very first call may not start with a parenthesis. */  dealing with. The very first call may not start with a parenthesis. */
1057    
1058  if (ptr[0] == CHAR_LEFT_PARENTHESIS)  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1059    {    {
1060    if (ptr[1] == CHAR_QUESTION_MARK &&    if (ptr[1] == CHAR_QUESTION_MARK &&
1061        ptr[2] == CHAR_VERTICAL_LINE)        ptr[2] == CHAR_VERTICAL_LINE)
1062      {      {
1063      ptr += 3;      ptr += 3;
1064      dup_parens = TRUE;      dup_parens = TRUE;
1065      }      }
1066    
1067    /* Handle a normal, unnamed capturing parenthesis */    /* Handle a normal, unnamed capturing parenthesis */
1068    
1069    else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK)    else if (ptr[1] != CHAR_QUESTION_MARK && ptr[1] != CHAR_ASTERISK)
1070      {      {
1071      *count += 1;      *count += 1;
1072      if (name == NULL && *count == lorn) return *count;      if (name == NULL && *count == lorn) return *count;
1073      ptr++;      ptr++;
1074      }      }
1075    
1076    /* Handle a condition. If it is an assertion, just carry on so that it    /* Handle a condition. If it is an assertion, just carry on so that it
1077    is processed as normal. If not, skip to the closing parenthesis of the    is processed as normal. If not, skip to the closing parenthesis of the
1078    condition (there can't be any nested parens. */    condition (there can't be any nested parens. */
1079    
1080    else if (ptr[2] == CHAR_LEFT_PARENTHESIS)    else if (ptr[2] == CHAR_LEFT_PARENTHESIS)
1081      {      {
1082      ptr += 2;      ptr += 2;
1083      if (ptr[1] != CHAR_QUESTION_MARK)      if (ptr[1] != CHAR_QUESTION_MARK)
1084        {        {
1085        while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;        while (*ptr != 0 && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
1086        if (*ptr != 0) ptr++;        if (*ptr != 0) ptr++;
1087        }        }
1088      }      }
1089    
1090    /* We have either (? or (* and not a condition */    /* We have either (? or (* and not a condition */
1091    
1092    else    else
1093      {      {
1094      ptr += 2;      ptr += 2;
1095      if (*ptr == CHAR_P) ptr++;                      /* Allow optional P */      if (*ptr == CHAR_P) ptr++;                      /* Allow optional P */
1096    
1097      /* We have to disambiguate (?<! and (?<= from (?<name> for named groups */      /* We have to disambiguate (?<! and (?<= from (?<name> for named groups */
1098    
1099      if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&      if ((*ptr == CHAR_LESS_THAN_SIGN && ptr[1] != CHAR_EXCLAMATION_MARK &&
1100          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)          ptr[1] != CHAR_EQUALS_SIGN) || *ptr == CHAR_APOSTROPHE)
1101        {        {
# Line 1100  if (ptr[0] == CHAR_LEFT_PARENTHESIS) Line 1110  if (ptr[0] == CHAR_LEFT_PARENTHESIS)
1110        if (name != NULL && lorn == ptr - thisname &&        if (name != NULL && lorn == ptr - thisname &&
1111            strncmp((const char *)name, (const char *)thisname, lorn) == 0)            strncmp((const char *)name, (const char *)thisname, lorn) == 0)
1112          return *count;          return *count;
1113        }        term++;
1114          }
1115      }      }
1116    }    }
1117    
1118  /* Past any initial parenthesis handling, scan for parentheses or vertical  /* Past any initial parenthesis handling, scan for parentheses or vertical
1119  bars. */  bars. */
1120    
1121  for (; *ptr != 0; ptr++)  for (; *ptr != 0; ptr++)
# Line 1134  for (; *ptr != 0; ptr++) Line 1145  for (; *ptr != 0; ptr++)
1145      BOOL negate_class = FALSE;      BOOL negate_class = FALSE;
1146      for (;;)      for (;;)
1147        {        {
1148        int c = *(++ptr);        if (ptr[1] == CHAR_BACKSLASH)
       if (c == CHAR_BACKSLASH)  
1149          {          {
1150          if (ptr[1] == CHAR_E)          if (ptr[2] == CHAR_E)
1151            ptr++;            ptr+= 2;
1152          else if (strncmp((const char *)ptr+1,          else if (strncmp((const char *)ptr+2,
1153                   STR_Q STR_BACKSLASH STR_E, 3) == 0)                   STR_Q STR_BACKSLASH STR_E, 3) == 0)
1154            ptr += 3;            ptr += 4;
1155          else          else
1156            break;            break;
1157          }          }
1158        else if (!negate_class && c == CHAR_CIRCUMFLEX_ACCENT)        else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT)
1159            {
1160          negate_class = TRUE;          negate_class = TRUE;
1161            ptr++;
1162            }
1163        else break;        else break;
1164        }        }
1165    
# Line 1185  for (; *ptr != 0; ptr++) Line 1198  for (; *ptr != 0; ptr++)
1198      }      }
1199    
1200    /* Check for the special metacharacters */    /* Check for the special metacharacters */
1201    
1202    if (*ptr == CHAR_LEFT_PARENTHESIS)    if (*ptr == CHAR_LEFT_PARENTHESIS)
1203      {      {
1204      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, count);      int rc = find_parens_sub(&ptr, cd, name, lorn, xmode, count);
1205      if (rc > 0) return rc;      if (rc > 0) return rc;
1206      if (*ptr == 0) goto FAIL_EXIT;      if (*ptr == 0) goto FAIL_EXIT;
1207      }      }
1208    
1209    else if (*ptr == CHAR_RIGHT_PARENTHESIS)    else if (*ptr == CHAR_RIGHT_PARENTHESIS)
1210      {      {
1211      if (dup_parens && *count < hwm_count) *count = hwm_count;      if (dup_parens && *count < hwm_count) *count = hwm_count;
1212      *ptrptr = ptr;      *ptrptr = ptr;
1213      return -1;      return -1;
1214      }      }
1215    
1216    else if (*ptr == CHAR_VERTICAL_LINE && dup_parens)    else if (*ptr == CHAR_VERTICAL_LINE && dup_parens)
1217      {      {
1218      if (*count > hwm_count) hwm_count = *count;      if (*count > hwm_count) hwm_count = *count;
1219      *count = start_count;      *count = start_count;
1220      }      }
1221    }    }
1222    
1223  FAIL_EXIT:  FAIL_EXIT:
# Line 1251  to find_parens_sub() will scan right to Line 1264  to find_parens_sub() will scan right to
1264  does start with a parenthesis, find_parens_sub() will return when it hits the  does start with a parenthesis, find_parens_sub() will return when it hits the
1265  matching closing parens. That is why we have to have a loop. */  matching closing parens. That is why we have to have a loop. */
1266    
1267  for (;;)  for (;;)
1268    {    {
1269    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, &count);    rc = find_parens_sub(&ptr, cd, name, lorn, xmode, &count);
1270    if (rc > 0 || *ptr++ == 0) break;    if (rc > 0 || *ptr++ == 0) break;
1271    }    }
1272    
1273  return rc;  return rc;
1274  }  }
1275    
# Line 1312  for (;;) Line 1325  for (;;)
1325    
1326      case OP_CALLOUT:      case OP_CALLOUT:
1327      case OP_CREF:      case OP_CREF:
1328        case OP_NCREF:
1329      case OP_RREF:      case OP_RREF:
1330        case OP_NRREF:
1331      case OP_DEF:      case OP_DEF:
1332      code += _pcre_OP_lengths[*code];      code += _pcre_OP_lengths[*code];
1333      break;      break;
# Line 1328  for (;;) Line 1343  for (;;)
1343    
1344    
1345  /*************************************************  /*************************************************
1346  *        Find the fixed length of a pattern      *  *        Find the fixed length of a branch       *
1347  *************************************************/  *************************************************/
1348    
1349  /* Scan a pattern and compute the fixed length of subject that will match it,  /* Scan a branch and compute the fixed length of subject that will match it,
1350  if the length is fixed. This is needed for dealing with backward assertions.  if the length is fixed. This is needed for dealing with backward assertions.
1351  In UTF8 mode, the result is in characters rather than bytes.  In UTF8 mode, the result is in characters rather than bytes. The branch is
1352    temporarily terminated with OP_END when this function is called.
1353    
1354    This function is called when a backward assertion is encountered, so that if it
1355    fails, the error message can point to the correct place in the pattern.
1356    However, we cannot do this when the assertion contains subroutine calls,
1357    because they can be forward references. We solve this by remembering this case
1358    and doing the check at the end; a flag specifies which mode we are running in.
1359    
1360  Arguments:  Arguments:
1361    code     points to the start of the pattern (the bracket)    code     points to the start of the pattern (the bracket)
1362    options  the compiling options    options  the compiling options
1363      atend    TRUE if called when the pattern is complete
1364      cd       the "compile data" structure
1365    
1366  Returns:   the fixed length, or -1 if there is no fixed length,  Returns:   the fixed length,
1367                 or -1 if there is no fixed length,
1368               or -2 if \C was encountered               or -2 if \C was encountered
1369                 or -3 if an OP_RECURSE item was encountered and atend is FALSE
1370  */  */
1371    
1372  static int  static int
1373  find_fixedlength(uschar *code, int options)  find_fixedlength(uschar *code, int options, BOOL atend, compile_data *cd)
1374  {  {
1375  int length = -1;  int length = -1;
1376    
# Line 1357  branch, check the length against that of Line 1383  branch, check the length against that of
1383  for (;;)  for (;;)
1384    {    {
1385    int d;    int d;
1386      uschar *ce, *cs;
1387    register int op = *cc;    register int op = *cc;
1388    switch (op)    switch (op)
1389      {      {
# Line 1364  for (;;) Line 1391  for (;;)
1391      case OP_BRA:      case OP_BRA:
1392      case OP_ONCE:      case OP_ONCE:
1393      case OP_COND:      case OP_COND:
1394      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options);      d = find_fixedlength(cc + ((op == OP_CBRA)? 2:0), options, atend, cd);
1395      if (d < 0) return d;      if (d < 0) return d;
1396      branchlength += d;      branchlength += d;
1397      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 1387  for (;;) Line 1414  for (;;)
1414      branchlength = 0;      branchlength = 0;
1415      break;      break;
1416    
1417        /* A true recursion implies not fixed length, but a subroutine call may
1418        be OK. If the subroutine is a forward reference, we can't deal with
1419        it until the end of the pattern, so return -3. */
1420    
1421        case OP_RECURSE:
1422        if (!atend) return -3;
1423        cs = ce = (uschar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
1424        do ce += GET(ce, 1); while (*ce == OP_ALT);       /* End subpattern */
1425        if (cc > cs && cc < ce) return -1;                /* Recursion */
1426        d = find_fixedlength(cs + 2, options, atend, cd);
1427        if (d < 0) return d;
1428        branchlength += d;
1429        cc += 1 + LINK_SIZE;
1430        break;
1431    
1432      /* Skip over assertive subpatterns */      /* Skip over assertive subpatterns */
1433    
1434      case OP_ASSERT:      case OP_ASSERT:
# Line 1400  for (;;) Line 1442  for (;;)
1442    
1443      case OP_REVERSE:      case OP_REVERSE:
1444      case OP_CREF:      case OP_CREF:
1445        case OP_NCREF:
1446      case OP_RREF:      case OP_RREF:
1447        case OP_NRREF:
1448      case OP_DEF:      case OP_DEF:
1449      case OP_OPT:      case OP_OPT:
1450      case OP_CALLOUT:      case OP_CALLOUT:
1451      case OP_SOD:      case OP_SOD:
1452      case OP_SOM:      case OP_SOM:
1453        case OP_SET_SOM:
1454      case OP_EOD:      case OP_EOD:
1455      case OP_EODN:      case OP_EODN:
1456      case OP_CIRC:      case OP_CIRC:
# Line 1423  for (;;) Line 1468  for (;;)
1468      branchlength++;      branchlength++;
1469      cc += 2;      cc += 2;
1470  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1471      if ((options & PCRE_UTF8) != 0)      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)
1472        {        cc += _pcre_utf8_table4[cc[-1] & 0x3f];
       while ((*cc & 0xc0) == 0x80) cc++;  
       }  
1473  #endif  #endif
1474      break;      break;
1475    
# Line 1437  for (;;) Line 1480  for (;;)
1480      branchlength += GET2(cc,1);      branchlength += GET2(cc,1);
1481      cc += 4;      cc += 4;
1482  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1483      if ((options & PCRE_UTF8) != 0)      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)
1484        {        cc += _pcre_utf8_table4[cc[-1] & 0x3f];
       while((*cc & 0x80) == 0x80) cc++;  
       }  
1485  #endif  #endif
1486      break;      break;
1487    
# Line 1519  for (;;) Line 1560  for (;;)
1560    
1561    
1562  /*************************************************  /*************************************************
1563  *    Scan compiled regex for numbered bracket    *  *    Scan compiled regex for specific bracket    *
1564  *************************************************/  *************************************************/
1565    
1566  /* This little function scans through a compiled pattern until it finds a  /* This little function scans through a compiled pattern until it finds a
1567  capturing bracket with the given number.  capturing bracket with the given number, or, if the number is negative, an
1568    instance of OP_REVERSE for a lookbehind. The function is global in the C sense
1569    so that it can be called from pcre_study() when finding the minimum matching
1570    length.
1571    
1572  Arguments:  Arguments:
1573    code        points to start of expression    code        points to start of expression
1574    utf8        TRUE in UTF-8 mode    utf8        TRUE in UTF-8 mode
1575    number      the required bracket number    number      the required bracket number or negative to find a lookbehind
1576    
1577  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
1578  */  */
1579    
1580  static const uschar *  const uschar *
1581  find_bracket(const uschar *code, BOOL utf8, int number)  _pcre_find_bracket(const uschar *code, BOOL utf8, int number)
1582  {  {
1583  for (;;)  for (;;)
1584    {    {
# Line 1547  for (;;) Line 1591  for (;;)
1591    
1592    if (c == OP_XCLASS) code += GET(code, 1);    if (c == OP_XCLASS) code += GET(code, 1);
1593    
1594      /* Handle recursion */
1595    
1596      else if (c == OP_REVERSE)
1597        {
1598        if (number < 0) return (uschar *)code;
1599        code += _pcre_OP_lengths[c];
1600        }
1601    
1602    /* Handle capturing bracket */    /* Handle capturing bracket */
1603    
1604    else if (c == OP_CBRA)    else if (c == OP_CBRA)
# Line 1912  for (code = first_significant_code(code Line 1964  for (code = first_significant_code(code
1964      case OP_QUERY:      case OP_QUERY:
1965      case OP_MINQUERY:      case OP_MINQUERY:
1966      case OP_POSQUERY:      case OP_POSQUERY:
1967        if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];
1968        break;
1969    
1970      case OP_UPTO:      case OP_UPTO:
1971      case OP_MINUPTO:      case OP_MINUPTO:
1972      case OP_POSUPTO:      case OP_POSUPTO:
1973      if (utf8) while ((code[2] & 0xc0) == 0x80) code++;      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];
1974      break;      break;
1975  #endif  #endif
1976      }      }
# Line 1948  static BOOL Line 2003  static BOOL
2003  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,
2004    BOOL utf8)    BOOL utf8)
2005  {  {
2006  while (bcptr != NULL && bcptr->current >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2007    {    {
2008    if (!could_be_empty_branch(bcptr->current, endcode, utf8)) return FALSE;    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8))
2009        return FALSE;
2010    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2011    }    }
2012  return TRUE;  return TRUE;
# Line 2612  BOOL utf8 = FALSE; Line 2668  BOOL utf8 = FALSE;
2668  uschar *utf8_char = NULL;  uschar *utf8_char = NULL;
2669  #endif  #endif
2670    
2671  #ifdef DEBUG  #ifdef PCRE_DEBUG
2672  if (lengthptr != NULL) DPRINTF((">> start branch\n"));  if (lengthptr != NULL) DPRINTF((">> start branch\n"));
2673  #endif  #endif
2674    
# Line 2671  for (;; ptr++) Line 2727  for (;; ptr++)
2727    
2728    if (lengthptr != NULL)    if (lengthptr != NULL)
2729      {      {
2730  #ifdef DEBUG  #ifdef PCRE_DEBUG
2731      if (code > cd->hwm) cd->hwm = code;                 /* High water info */      if (code > cd->hwm) cd->hwm = code;                 /* High water info */
2732  #endif  #endif
2733      if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */      if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */
# Line 3869  we set the flag only if there is a liter Line 3925  we set the flag only if there is a liter
3925    
3926        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
3927    
3928          /*--------------------------------------------------------------------*/
3929          /* This code is obsolete from release 8.00; the restriction was finally
3930          removed: */
3931    
3932        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
3933        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
3934    
3935        if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */
3936          /*--------------------------------------------------------------------*/
3937    
3938        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
3939    
# Line 4019  we set the flag only if there is a liter Line 4080  we set the flag only if there is a liter
4080          goto END_REPEAT;          goto END_REPEAT;
4081          }          }
4082    
4083          /*--------------------------------------------------------------------*/
4084          /* This code is obsolete from release 8.00; the restriction was finally
4085          removed: */
4086    
4087        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
4088        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
4089    
4090        if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL;        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */
4091          /*--------------------------------------------------------------------*/
4092    
4093        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
4094          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
# Line 4157  we set the flag only if there is a liter Line 4223  we set the flag only if there is a liter
4223            {            {
4224            /* In the pre-compile phase, we don't actually do the replication. We            /* In the pre-compile phase, we don't actually do the replication. We
4225            just adjust the length as if we had. Do some paranoid checks for            just adjust the length as if we had. Do some paranoid checks for
4226            potential integer overflow. */            potential integer overflow. The INT64_OR_DOUBLE type is a 64-bit
4227              integer type when available, otherwise double. */
4228    
4229            if (lengthptr != NULL)            if (lengthptr != NULL)
4230              {              {
4231              int delta = (repeat_min - 1)*length_prevgroup;              int delta = (repeat_min - 1)*length_prevgroup;
4232              if ((double)(repeat_min - 1)*(double)length_prevgroup >              if ((INT64_OR_DOUBLE)(repeat_min - 1)*
4233                                                              (double)INT_MAX ||                    (INT64_OR_DOUBLE)length_prevgroup >
4234                        (INT64_OR_DOUBLE)INT_MAX ||
4235                  OFLOW_MAX - *lengthptr < delta)                  OFLOW_MAX - *lengthptr < delta)
4236                {                {
4237                *errorcodeptr = ERR20;                *errorcodeptr = ERR20;
# Line 4209  we set the flag only if there is a liter Line 4277  we set the flag only if there is a liter
4277          just adjust the length as if we had. For each repetition we must add 1          just adjust the length as if we had. For each repetition we must add 1
4278          to the length for BRAZERO and for all but the last repetition we must          to the length for BRAZERO and for all but the last repetition we must
4279          add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some          add 2 + 2*LINKSIZE to allow for the nesting that occurs. Do some
4280          paranoid checks to avoid integer overflow. */          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is
4281            a 64-bit integer type when available, otherwise double. */
4282    
4283          if (lengthptr != NULL && repeat_max > 0)          if (lengthptr != NULL && repeat_max > 0)
4284            {            {
4285            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
4286                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */
4287            if ((double)repeat_max *            if ((INT64_OR_DOUBLE)repeat_max *
4288                  (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)                  (INT64_OR_DOUBLE)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)
4289                    > (double)INT_MAX ||                    > (INT64_OR_DOUBLE)INT_MAX ||
4290                OFLOW_MAX - *lengthptr < delta)                OFLOW_MAX - *lengthptr < delta)
4291              {              {
4292              *errorcodeptr = ERR20;              *errorcodeptr = ERR20;
# Line 4337  we set the flag only if there is a liter Line 4406  we set the flag only if there is a liter
4406      if (possessive_quantifier)      if (possessive_quantifier)
4407        {        {
4408        int len;        int len;
4409        if (*tempcode == OP_EXACT || *tempcode == OP_TYPEEXACT ||  
4410            *tempcode == OP_NOTEXACT)        if (*tempcode == OP_TYPEEXACT)
4411          tempcode += _pcre_OP_lengths[*tempcode] +          tempcode += _pcre_OP_lengths[*tempcode] +
4412            ((*tempcode == OP_TYPEEXACT &&            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);
4413               (tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP))? 2:0);  
4414          else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
4415            {
4416            tempcode += _pcre_OP_lengths[*tempcode];
4417    #ifdef SUPPORT_UTF8
4418            if (utf8 && tempcode[-1] >= 0xc0)
4419              tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];
4420    #endif
4421            }
4422    
4423        len = code - tempcode;        len = code - tempcode;
4424        if (len > 0) switch (*tempcode)        if (len > 0) switch (*tempcode)
4425          {          {
# Line 4360  we set the flag only if there is a liter Line 4438  we set the flag only if there is a liter
4438          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;
4439          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;
4440    
4441            /* Because we are moving code along, we must ensure that any
4442            pending recursive references are updated. */
4443    
4444          default:          default:
4445            *code = OP_END;
4446            adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);
4447          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1+LINK_SIZE, tempcode, len);
4448          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
4449          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
# Line 4419  we set the flag only if there is a liter Line 4502  we set the flag only if there is a liter
4502          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
4503              strncmp((char *)name, vn, namelen) == 0)              strncmp((char *)name, vn, namelen) == 0)
4504            {            {
4505            *code = verbs[i].op;            /* Check for open captures before ACCEPT */
4506            if (*code++ == OP_ACCEPT) cd->had_accept = TRUE;  
4507              if (verbs[i].op == OP_ACCEPT)
4508                {
4509                open_capitem *oc;
4510                cd->had_accept = TRUE;
4511                for (oc = cd->open_caps; oc != NULL; oc = oc->next)
4512                  {
4513                  *code++ = OP_CLOSE;
4514                  PUT2INC(code, 0, oc->number);
4515                  }
4516                }
4517              *code++ = verbs[i].op;
4518            break;            break;
4519            }            }
4520          vn += verbs[i].len + 1;          vn += verbs[i].len + 1;
# Line 4582  we set the flag only if there is a liter Line 4676  we set the flag only if there is a liter
4676            }            }
4677    
4678          /* Otherwise (did not start with "+" or "-"), start by looking for the          /* Otherwise (did not start with "+" or "-"), start by looking for the
4679          name. */          name. If we find a name, add one to the opcode to change OP_CREF or
4680            OP_RREF into OP_NCREF or OP_NRREF. These behave exactly the same,
4681            except they record that the reference was originally to a name. The
4682            information is used to check duplicate names. */
4683    
4684          slot = cd->name_table;          slot = cd->name_table;
4685          for (i = 0; i < cd->names_found; i++)          for (i = 0; i < cd->names_found; i++)
# Line 4597  we set the flag only if there is a liter Line 4694  we set the flag only if there is a liter
4694            {            {
4695            recno = GET2(slot, 0);            recno = GET2(slot, 0);
4696            PUT2(code, 2+LINK_SIZE, recno);            PUT2(code, 2+LINK_SIZE, recno);
4697              code[1+LINK_SIZE]++;
4698            }            }
4699    
4700          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
# Line 4605  we set the flag only if there is a liter Line 4703  we set the flag only if there is a liter
4703                          (options & PCRE_EXTENDED) != 0)) > 0)                          (options & PCRE_EXTENDED) != 0)) > 0)
4704            {            {
4705            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
4706              code[1+LINK_SIZE]++;
4707            }            }
4708    
4709          /* If terminator == 0 it means that the name followed directly after          /* If terminator == 0 it means that the name followed directly after
# Line 4797  we set the flag only if there is a liter Line 4896  we set the flag only if there is a liter
4896                }                }
4897              }              }
4898    
4899            /* In the real compile, create the entry in the table */            /* In the real compile, create the entry in the table, maintaining
4900              alphabetical order. Duplicate names for different numbers are
4901              permitted only if PCRE_DUPNAMES is set. Duplicate names for the same
4902              number are always OK. (An existing number can be re-used if (?|
4903              appears in the pattern.) In either event, a duplicate name results in
4904              a duplicate entry in the table, even if the number is the same. This
4905              is because the number of names, and hence the table size, is computed
4906              in the pre-compile, and it affects various numbers and pointers which
4907              would all have to be modified, and the compiled code moved down, if
4908              duplicates with the same number were omitted from the table. This
4909              doesn't seem worth the hassle. However, *different* names for the
4910              same number are not permitted. */
4911    
4912            else            else
4913              {              {
4914                BOOL dupname = FALSE;
4915              slot = cd->name_table;              slot = cd->name_table;
4916    
4917              for (i = 0; i < cd->names_found; i++)              for (i = 0; i < cd->names_found; i++)
4918                {                {
4919                int crc = memcmp(name, slot+2, namelen);                int crc = memcmp(name, slot+2, namelen);
# Line 4809  we set the flag only if there is a liter Line 4921  we set the flag only if there is a liter
4921                  {                  {
4922                  if (slot[2+namelen] == 0)                  if (slot[2+namelen] == 0)
4923                    {                    {
4924                    if ((options & PCRE_DUPNAMES) == 0)                    if (GET2(slot, 0) != cd->bracount + 1 &&
4925                          (options & PCRE_DUPNAMES) == 0)
4926                      {                      {
4927                      *errorcodeptr = ERR43;                      *errorcodeptr = ERR43;
4928                      goto FAILED;                      goto FAILED;
4929                      }                      }
4930                      else dupname = TRUE;
4931                    }                    }
4932                  else crc = -1;      /* Current name is substring */                  else crc = -1;      /* Current name is a substring */
4933                  }                  }
4934    
4935                  /* Make space in the table and break the loop for an earlier
4936                  name. For a duplicate or later name, carry on. We do this for
4937                  duplicates so that in the simple case (when ?(| is not used) they
4938                  are in order of their numbers. */
4939    
4940                if (crc < 0)                if (crc < 0)
4941                  {                  {
4942                  memmove(slot + cd->name_entry_size, slot,                  memmove(slot + cd->name_entry_size, slot,
4943                    (cd->names_found - i) * cd->name_entry_size);                    (cd->names_found - i) * cd->name_entry_size);
4944                  break;                  break;
4945                  }                  }
4946    
4947                  /* Continue the loop for a later or duplicate name */
4948    
4949                slot += cd->name_entry_size;                slot += cd->name_entry_size;
4950                }                }
4951    
4952                /* For non-duplicate names, check for a duplicate number before
4953                adding the new name. */
4954    
4955                if (!dupname)
4956                  {
4957                  uschar *cslot = cd->name_table;
4958                  for (i = 0; i < cd->names_found; i++)
4959                    {
4960                    if (cslot != slot)
4961                      {
4962                      if (GET2(cslot, 0) == cd->bracount + 1)
4963                        {
4964                        *errorcodeptr = ERR65;
4965                        goto FAILED;
4966                        }
4967                      }
4968                    else i--;
4969                    cslot += cd->name_entry_size;
4970                    }
4971                  }
4972    
4973              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
4974              memcpy(slot + 2, name, namelen);              memcpy(slot + 2, name, namelen);
4975              slot[2+namelen] = 0;              slot[2+namelen] = 0;
4976              }              }
4977            }            }
4978    
4979          /* In both cases, count the number of names we've encountered. */          /* In both pre-compile and compile, count the number of names we've
4980            encountered. */
4981    
         ptr++;                    /* Move past > or ' */  
4982          cd->names_found++;          cd->names_found++;
4983            ptr++;                    /* Move past > or ' */
4984          goto NUMBERED_GROUP;          goto NUMBERED_GROUP;
4985    
4986    
# Line 5004  we set the flag only if there is a liter Line 5149  we set the flag only if there is a liter
5149            if (lengthptr == NULL)            if (lengthptr == NULL)
5150              {              {
5151              *code = OP_END;              *code = OP_END;
5152              if (recno != 0) called = find_bracket(cd->start_code, utf8, recno);              if (recno != 0)
5153                  called = _pcre_find_bracket(cd->start_code, utf8, recno);
5154    
5155              /* Forward reference */              /* Forward reference */
5156    
# Line 5016  we set the flag only if there is a liter Line 5162  we set the flag only if there is a liter
5162                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
5163                  goto FAILED;                  goto FAILED;
5164                  }                  }
5165    
5166                  /* Fudge the value of "called" so that when it is inserted as an
5167                  offset below, what it actually inserted is the reference number
5168                  of the group. */
5169    
5170                called = cd->start_code + recno;                called = cd->start_code + recno;
5171                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);
5172                }                }
# Line 5120  we set the flag only if there is a liter Line 5271  we set the flag only if there is a liter
5271              {              {
5272              cd->external_options = newoptions;              cd->external_options = newoptions;
5273              }              }
5274           else            else
5275              {              {
5276              if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))              if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
5277                {                {
# Line 5457  we set the flag only if there is a liter Line 5608  we set the flag only if there is a liter
5608    
5609        if (-c >= ESC_REF)        if (-c >= ESC_REF)
5610          {          {
5611            open_capitem *oc;
5612          recno = -c - ESC_REF;          recno = -c - ESC_REF;
5613    
5614          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
# Line 5466  we set the flag only if there is a liter Line 5618  we set the flag only if there is a liter
5618          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
5619          cd->backref_map |= (recno < 32)? (1 << recno) : 1;          cd->backref_map |= (recno < 32)? (1 << recno) : 1;
5620          if (recno > cd->top_backref) cd->top_backref = recno;          if (recno > cd->top_backref) cd->top_backref = recno;
5621    
5622            /* Check to see if this back reference is recursive, that it, it
5623            is inside the group that it references. A flag is set so that the
5624            group can be made atomic. */
5625    
5626            for (oc = cd->open_caps; oc != NULL; oc = oc->next)
5627              {
5628              if (oc->number == recno)
5629                {
5630                oc->flag = TRUE;
5631                break;
5632                }
5633              }
5634          }          }
5635    
5636        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
# Line 5648  uschar *code = *codeptr; Line 5813  uschar *code = *codeptr;
5813  uschar *last_branch = code;  uschar *last_branch = code;
5814  uschar *start_bracket = code;  uschar *start_bracket = code;
5815  uschar *reverse_count = NULL;  uschar *reverse_count = NULL;
5816    open_capitem capitem;
5817    int capnumber = 0;
5818  int firstbyte, reqbyte;  int firstbyte, reqbyte;
5819  int branchfirstbyte, branchreqbyte;  int branchfirstbyte, branchreqbyte;
5820  int length;  int length;
5821  int orig_bracount;  int orig_bracount;
5822  int max_bracount;  int max_bracount;
5823    int old_external_options = cd->external_options;
5824  branch_chain bc;  branch_chain bc;
5825    
5826  bc.outer = bcptr;  bc.outer = bcptr;
5827  bc.current = code;  bc.current_branch = code;
5828    
5829  firstbyte = reqbyte = REQ_UNSET;  firstbyte = reqbyte = REQ_UNSET;
5830    
# Line 5674  the code that abstracts option settings Line 5842  the code that abstracts option settings
5842  them global. It tests the value of length for (2 + 2*LINK_SIZE) in the  them global. It tests the value of length for (2 + 2*LINK_SIZE) in the
5843  pre-compile phase to find out whether anything has yet been compiled or not. */  pre-compile phase to find out whether anything has yet been compiled or not. */
5844    
5845    /* If this is a capturing subpattern, add to the chain of open capturing items
5846    so that we can detect them if (*ACCEPT) is encountered. This is also used to
5847    detect groups that contain recursive back references to themselves. */
5848    
5849    if (*code == OP_CBRA)
5850      {
5851      capnumber = GET2(code, 1 + LINK_SIZE);
5852      capitem.number = capnumber;
5853      capitem.next = cd->open_caps;
5854      capitem.flag = FALSE;
5855      cd->open_caps = &capitem;
5856      }
5857    
5858  /* Offset is set zero to mark that this bracket is still open */  /* Offset is set zero to mark that this bracket is still open */
5859    
5860  PUT(code, 1, 0);  PUT(code, 1, 0);
# Line 5718  for (;;) Line 5899  for (;;)
5899      return FALSE;      return FALSE;
5900      }      }
5901    
5902      /* If the external options have changed during this branch, it means that we
5903      are at the top level, and a leading option setting has been encountered. We
5904      need to re-set the original option values to take account of this so that,
5905      during the pre-compile phase, we know to allow for a re-set at the start of
5906      subsequent branches. */
5907    
5908      if (old_external_options != cd->external_options)
5909        oldims = cd->external_options & PCRE_IMS;
5910    
5911    /* Keep the highest bracket count in case (?| was used and some branch    /* Keep the highest bracket count in case (?| was used and some branch
5912    has fewer than the rest. */    has fewer than the rest. */
5913    
# Line 5768  for (;;) Line 5958  for (;;)
5958    
5959      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
5960      put the length into the OP_REVERSE item. Temporarily mark the end of the      put the length into the OP_REVERSE item. Temporarily mark the end of the
5961      branch with OP_END. */      branch with OP_END. If the branch contains OP_RECURSE, the result is -3
5962        because there may be forward references that we can't check here. Set a
5963        flag to cause another lookbehind check at the end. Why not do it all at the
5964        end? Because common, erroneous checks are picked up here and the offset of
5965        the problem can be shown. */
5966    
5967      if (lookbehind)      if (lookbehind)
5968        {        {
5969        int fixed_length;        int fixed_length;
5970        *code = OP_END;        *code = OP_END;
5971        fixed_length = find_fixedlength(last_branch, options);        fixed_length = find_fixedlength(last_branch, options, FALSE, cd);
5972        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
5973        if (fixed_length < 0)        if (fixed_length == -3)
5974            {
5975            cd->check_lookbehind = TRUE;
5976            }
5977          else if (fixed_length < 0)
5978          {          {
5979          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;
5980          *ptrptr = ptr;          *ptrptr = ptr;
5981          return FALSE;          return FALSE;
5982          }          }
5983        PUT(reverse_count, 0, fixed_length);        else { PUT(reverse_count, 0, fixed_length); }
5984        }        }
5985      }      }
5986    
# Line 5816  for (;;) Line 6014  for (;;)
6014      PUT(code, 1, code - start_bracket);      PUT(code, 1, code - start_bracket);
6015      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6016    
6017      /* Resetting option if needed */      /* If it was a capturing subpattern, check to see if it contained any
6018        recursive back references. If so, we must wrap it in atomic brackets.
6019        In any event, remove the block from the chain. */
6020    
6021        if (capnumber > 0)
6022          {
6023          if (cd->open_caps->flag)
6024            {
6025            memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
6026              code - start_bracket);
6027            *start_bracket = OP_ONCE;
6028            code += 1 + LINK_SIZE;
6029            PUT(start_bracket, 1, code - start_bracket);
6030            *code = OP_KET;
6031            PUT(code, 1, code - start_bracket);
6032            code += 1 + LINK_SIZE;
6033            length += 2 + 2*LINK_SIZE;
6034            }
6035          cd->open_caps = cd->open_caps->next;
6036          }
6037    
6038        /* Reset options if needed. */
6039    
6040      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)
6041        {        {
# Line 5865  for (;;) Line 6084  for (;;)
6084      {      {
6085      *code = OP_ALT;      *code = OP_ALT;
6086      PUT(code, 1, code - last_branch);      PUT(code, 1, code - last_branch);
6087      bc.current = last_branch = code;      bc.current_branch = last_branch = code;
6088      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6089      }      }
6090    
# Line 6012  do { Line 6231  do {
6231       switch (*scode)       switch (*scode)
6232         {         {
6233         case OP_CREF:         case OP_CREF:
6234           case OP_NCREF:
6235         case OP_RREF:         case OP_RREF:
6236           case OP_NRREF:
6237         case OP_DEF:         case OP_DEF:
6238         return FALSE;         return FALSE;
6239    
# Line 6181  int length = 1;  /* For final END opcode Line 6402  int length = 1;  /* For final END opcode
6402  int firstbyte, reqbyte, newline;  int firstbyte, reqbyte, newline;
6403  int errorcode = 0;  int errorcode = 0;
6404  int skipatstart = 0;  int skipatstart = 0;
6405  #ifdef SUPPORT_UTF8  BOOL utf8 = (options & PCRE_UTF8) != 0;
 BOOL utf8;  
 #endif  
6406  size_t size;  size_t size;
6407  uschar *code;  uschar *code;
6408  const uschar *codestart;  const uschar *codestart;
# Line 6226  if (erroroffset == NULL) Line 6445  if (erroroffset == NULL)
6445    
6446  *erroroffset = 0;  *erroroffset = 0;
6447    
 /* Can't support UTF8 unless PCRE has been compiled to include the code. */  
   
 #ifdef SUPPORT_UTF8  
 utf8 = (options & PCRE_UTF8) != 0;  
 if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  
      (*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0)  
   {  
   errorcode = ERR44;  
   goto PCRE_EARLY_ERROR_RETURN2;  
   }  
 #else  
 if ((options & PCRE_UTF8) != 0)  
   {  
   errorcode = ERR32;  
   goto PCRE_EARLY_ERROR_RETURN;  
   }  
 #endif  
   
 if ((options & ~PUBLIC_COMPILE_OPTIONS) != 0)  
   {  
   errorcode = ERR17;  
   goto PCRE_EARLY_ERROR_RETURN;  
   }  
   
6448  /* Set up pointers to the individual character tables */  /* Set up pointers to the individual character tables */
6449    
6450  if (tables == NULL) tables = _pcre_default_tables;  if (tables == NULL) tables = _pcre_default_tables;
# Line 6258  cd->fcc = tables + fcc_offset; Line 6453  cd->fcc = tables + fcc_offset;
6453  cd->cbits = tables + cbits_offset;  cd->cbits = tables + cbits_offset;
6454  cd->ctypes = tables + ctypes_offset;  cd->ctypes = tables + ctypes_offset;
6455    
6456    /* Check that all undefined public option bits are zero */
6457    
6458    if ((options & ~PUBLIC_COMPILE_OPTIONS) != 0)
6459      {
6460      errorcode = ERR17;
6461      goto PCRE_EARLY_ERROR_RETURN;
6462      }
6463    
6464  /* Check for global one-time settings at the start of the pattern, and remember  /* Check for global one-time settings at the start of the pattern, and remember
6465  the offset for later. */  the offset for later. */
6466    
# Line 6267  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 6470  while (ptr[skipatstart] == CHAR_LEFT_PAR
6470    int newnl = 0;    int newnl = 0;
6471    int newbsr = 0;    int newbsr = 0;
6472    
6473      if (strncmp((char *)(ptr+skipatstart+2), STRING_UTF8_RIGHTPAR, 5) == 0)
6474        { skipatstart += 7; options |= PCRE_UTF8; continue; }
6475    
6476    if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)    if (strncmp((char *)(ptr+skipatstart+2), STRING_CR_RIGHTPAR, 3) == 0)
6477      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }      { skipatstart += 5; newnl = PCRE_NEWLINE_CR; }
6478    else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)    else if (strncmp((char *)(ptr+skipatstart+2), STRING_LF_RIGHTPAR, 3)  == 0)
# Line 6290  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 6496  while (ptr[skipatstart] == CHAR_LEFT_PAR
6496    else break;    else break;
6497    }    }
6498    
6499    /* Can't support UTF8 unless PCRE has been compiled to include the code. */
6500    
6501    #ifdef SUPPORT_UTF8
6502    if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
6503         (*erroroffset = _pcre_valid_utf8((USPTR)pattern, -1)) >= 0)
6504      {
6505      errorcode = ERR44;
6506      goto PCRE_EARLY_ERROR_RETURN2;
6507      }
6508    #else
6509    if (utf8)
6510      {
6511      errorcode = ERR32;
6512      goto PCRE_EARLY_ERROR_RETURN;
6513      }
6514    #endif
6515    
6516  /* Check validity of \R options. */  /* Check validity of \R options. */
6517    
6518  switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))  switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
# Line 6372  cd->end_pattern = (const uschar *)(patte Line 6595  cd->end_pattern = (const uschar *)(patte
6595  cd->req_varyopt = 0;  cd->req_varyopt = 0;
6596  cd->external_options = options;  cd->external_options = options;
6597  cd->external_flags = 0;  cd->external_flags = 0;
6598    cd->open_caps = NULL;
6599    
6600  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we  /* Now do the pre-compile. On error, errorcode will be set non-zero, so we
6601  don't need to look at the result of the function here. The initial options have  don't need to look at the result of the function here. The initial options have
# Line 6446  cd->start_code = codestart; Line 6670  cd->start_code = codestart;
6670  cd->hwm = cworkspace;  cd->hwm = cworkspace;
6671  cd->req_varyopt = 0;  cd->req_varyopt = 0;
6672  cd->had_accept = FALSE;  cd->had_accept = FALSE;
6673    cd->check_lookbehind = FALSE;
6674    cd->open_caps = NULL;
6675    
6676  /* Set up a starting, non-extracting bracket, then compile the expression. On  /* Set up a starting, non-extracting bracket, then compile the expression. On
6677  error, errorcode will be set non-zero, so we don't need to look at the result  error, errorcode will be set non-zero, so we don't need to look at the result
# Line 6471  if debugging, leave the test till after Line 6697  if debugging, leave the test till after
6697    
6698  *code++ = OP_END;  *code++ = OP_END;
6699    
6700  #ifndef DEBUG  #ifndef PCRE_DEBUG
6701  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
6702  #endif  #endif
6703    
# Line 6484  while (errorcode == 0 && cd->hwm > cwork Line 6710  while (errorcode == 0 && cd->hwm > cwork
6710    cd->hwm -= LINK_SIZE;    cd->hwm -= LINK_SIZE;
6711    offset = GET(cd->hwm, 0);    offset = GET(cd->hwm, 0);
6712    recno = GET(codestart, offset);    recno = GET(codestart, offset);
6713    groupptr = find_bracket(codestart, (re->options & PCRE_UTF8) != 0, recno);    groupptr = _pcre_find_bracket(codestart, utf8, recno);
6714    if (groupptr == NULL) errorcode = ERR53;    if (groupptr == NULL) errorcode = ERR53;
6715      else PUT(((uschar *)codestart), offset, groupptr - codestart);      else PUT(((uschar *)codestart), offset, groupptr - codestart);
6716    }    }
# Line 6494  subpattern. */ Line 6720  subpattern. */
6720    
6721  if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;  if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;
6722    
6723    /* If there were any lookbehind assertions that contained OP_RECURSE
6724    (recursions or subroutine calls), a flag is set for them to be checked here,
6725    because they may contain forward references. Actual recursions can't be fixed
6726    length, but subroutine calls can. It is done like this so that those without
6727    OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The
6728    exceptional ones forgo this. We scan the pattern to check that they are fixed
6729    length, and set their lengths. */
6730    
6731    if (cd->check_lookbehind)
6732      {
6733      uschar *cc = (uschar *)codestart;
6734    
6735      /* Loop, searching for OP_REVERSE items, and process those that do not have
6736      their length set. (Actually, it will also re-process any that have a length
6737      of zero, but that is a pathological case, and it does no harm.) When we find
6738      one, we temporarily terminate the branch it is in while we scan it. */
6739    
6740      for (cc = (uschar *)_pcre_find_bracket(codestart, utf8, -1);
6741           cc != NULL;
6742           cc = (uschar *)_pcre_find_bracket(cc, utf8, -1))
6743        {
6744        if (GET(cc, 1) == 0)
6745          {
6746          int fixed_length;
6747          uschar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE);
6748          int end_op = *be;
6749          *be = OP_END;
6750          fixed_length = find_fixedlength(cc, re->options, TRUE, cd);
6751          *be = end_op;
6752          DPRINTF(("fixed length = %d\n", fixed_length));
6753          if (fixed_length < 0)
6754            {
6755            errorcode = (fixed_length == -2)? ERR36 : ERR25;
6756            break;
6757            }
6758          PUT(cc, 1, fixed_length);
6759          }
6760        cc += 1 + LINK_SIZE;
6761        }
6762      }
6763    
6764  /* Failed to compile, or error while post-processing */  /* Failed to compile, or error while post-processing */
6765    
6766  if (errorcode != 0)  if (errorcode != 0)
# Line 6554  if (reqbyte >= 0 && Line 6821  if (reqbyte >= 0 &&
6821  /* Print out the compiled data if debugging is enabled. This is never the  /* Print out the compiled data if debugging is enabled. This is never the
6822  case when building a production library. */  case when building a production library. */
6823    
6824  #ifdef DEBUG  #ifdef PCRE_DEBUG
   
6825  printf("Length = %d top_bracket = %d top_backref = %d\n",  printf("Length = %d top_bracket = %d top_backref = %d\n",
6826    length, re->top_bracket, re->top_backref);    length, re->top_bracket, re->top_backref);
6827    
# Line 6592  if (code - codestart > length) Line 6858  if (code - codestart > length)
6858    if (errorcodeptr != NULL) *errorcodeptr = ERR23;    if (errorcodeptr != NULL) *errorcodeptr = ERR23;
6859    return NULL;    return NULL;
6860    }    }
6861  #endif   /* DEBUG */  #endif   /* PCRE_DEBUG */
6862    
6863  return (pcre *)re;  return (pcre *)re;
6864  }  }

Legend:
Removed from v.408  
changed lines
  Added in v.500

  ViewVC Help
Powered by ViewVC 1.1.5