/[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 438 by ph10, Sun Sep 6 20:00:47 2009 UTC revision 504 by ph10, Mon Mar 8 08:57:04 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 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++;        term++;
1114        }        }
1115      }      }
1116    }    }
# Line 1146  for (; *ptr != 0; ptr++) Line 1156  for (; *ptr != 0; ptr++)
1156            break;            break;
1157          }          }
1158        else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT)        else if (!negate_class && ptr[1] == CHAR_CIRCUMFLEX_ACCENT)
1159          {          {
1160          negate_class = TRUE;          negate_class = TRUE;
1161          ptr++;          ptr++;
1162          }          }
1163        else break;        else break;
1164        }        }
1165    
# Line 1315  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 1331  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 1360  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 1367  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 1390  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 1403  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 1426  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 && cc[-1] >= 0xc0)      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)
1472        cc += _pcre_utf8_table4[cc[-1] & 0x3f];        cc += _pcre_utf8_table4[cc[-1] & 0x3f];
1473  #endif  #endif
1474      break;      break;
# Line 1438  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 && cc[-1] >= 0xc0)      if ((options & PCRE_UTF8) != 0 && cc[-1] >= 0xc0)
1484        cc += _pcre_utf8_table4[cc[-1] & 0x3f];        cc += _pcre_utf8_table4[cc[-1] & 0x3f];
1485  #endif  #endif
1486      break;      break;
# Line 1518  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 1546  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 1732  Arguments: Line 1785  Arguments:
1785    code        points to start of search    code        points to start of search
1786    endcode     points to where to stop    endcode     points to where to stop
1787    utf8        TRUE if in UTF8 mode    utf8        TRUE if in UTF8 mode
1788      cd          contains pointers to tables etc.
1789    
1790  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
1791  */  */
1792    
1793  static BOOL  static BOOL
1794  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8)  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8,
1795      compile_data *cd)
1796  {  {
1797  register int c;  register int c;
1798  for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE);  for (code = first_significant_code(code + _pcre_OP_lengths[*code], NULL, 0, TRUE);
# Line 1747  for (code = first_significant_code(code Line 1802  for (code = first_significant_code(code
1802    const uschar *ccode;    const uschar *ccode;
1803    
1804    c = *code;    c = *code;
1805    
1806    /* Skip over forward assertions; the other assertions are skipped by    /* Skip over forward assertions; the other assertions are skipped by
1807    first_significant_code() with a TRUE final argument. */    first_significant_code() with a TRUE final argument. */
1808    
# Line 1767  for (code = first_significant_code(code Line 1822  for (code = first_significant_code(code
1822      c = *code;      c = *code;
1823      continue;      continue;
1824      }      }
1825    
1826      /* For a recursion/subroutine call, if its end has been reached, which
1827      implies a subroutine call, we can scan it. */
1828    
1829      if (c == OP_RECURSE)
1830        {
1831        BOOL empty_branch = FALSE;
1832        const uschar *scode = cd->start_code + GET(code, 1);
1833        if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */
1834        do
1835          {
1836          if (could_be_empty_branch(scode, endcode, utf8, cd))
1837            {
1838            empty_branch = TRUE;
1839            break;
1840            }
1841          scode += GET(scode, 1);
1842          }
1843        while (*scode == OP_ALT);
1844        if (!empty_branch) return FALSE;  /* All branches are non-empty */
1845        continue;
1846        }
1847    
1848    /* For other groups, scan the branches. */    /* For other groups, scan the branches. */
1849    
# Line 1786  for (code = first_significant_code(code Line 1863  for (code = first_significant_code(code
1863        empty_branch = FALSE;        empty_branch = FALSE;
1864        do        do
1865          {          {
1866          if (!empty_branch && could_be_empty_branch(code, endcode, utf8))          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))
1867            empty_branch = TRUE;            empty_branch = TRUE;
1868          code += GET(code, 1);          code += GET(code, 1);
1869          }          }
# Line 1913  for (code = first_significant_code(code Line 1990  for (code = first_significant_code(code
1990      case OP_POSQUERY:      case OP_POSQUERY:
1991      if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];      if (utf8 && code[1] >= 0xc0) code += _pcre_utf8_table4[code[1] & 0x3f];
1992      break;      break;
1993    
1994      case OP_UPTO:      case OP_UPTO:
1995      case OP_MINUPTO:      case OP_MINUPTO:
1996      case OP_POSUPTO:      case OP_POSUPTO:
1997      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];
1998      break;      break;
1999  #endif  #endif
2000    
2001        /* None of the remaining opcodes are required to match a character. */
2002    
2003        default:
2004        break;
2005      }      }
2006    }    }
2007    
# Line 1942  Arguments: Line 2024  Arguments:
2024    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2025    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2026    utf8        TRUE if in UTF-8 mode    utf8        TRUE if in UTF-8 mode
2027      cd          pointers to tables etc
2028    
2029  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2030  */  */
2031    
2032  static BOOL  static BOOL
2033  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,
2034    BOOL utf8)    BOOL utf8, compile_data *cd)
2035  {  {
2036  while (bcptr != NULL && bcptr->current >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2037    {    {
2038    if (!could_be_empty_branch(bcptr->current, endcode, utf8)) return FALSE;    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))
2039        return FALSE;
2040    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2041    }    }
2042  return TRUE;  return TRUE;
# Line 2614  BOOL utf8 = FALSE; Line 2698  BOOL utf8 = FALSE;
2698  uschar *utf8_char = NULL;  uschar *utf8_char = NULL;
2699  #endif  #endif
2700    
2701  #ifdef DEBUG  #ifdef PCRE_DEBUG
2702  if (lengthptr != NULL) DPRINTF((">> start branch\n"));  if (lengthptr != NULL) DPRINTF((">> start branch\n"));
2703  #endif  #endif
2704    
# Line 2673  for (;; ptr++) Line 2757  for (;; ptr++)
2757    
2758    if (lengthptr != NULL)    if (lengthptr != NULL)
2759      {      {
2760  #ifdef DEBUG  #ifdef PCRE_DEBUG
2761      if (code > cd->hwm) cd->hwm = code;                 /* High water info */      if (code > cd->hwm) cd->hwm = code;                 /* High water info */
2762  #endif  #endif
2763      if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */      if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */
# Line 3871  we set the flag only if there is a liter Line 3955  we set the flag only if there is a liter
3955    
3956        if (repeat_max == 0) goto END_REPEAT;        if (repeat_max == 0) goto END_REPEAT;
3957    
3958        /*--------------------------------------------------------------------*/        /*--------------------------------------------------------------------*/
3959        /* This code is obsolete from release 8.00; the restriction was finally        /* This code is obsolete from release 8.00; the restriction was finally
3960        removed: */        removed: */
3961    
3962        /* All real repeats make it impossible to handle partial matching (maybe        /* All real repeats make it impossible to handle partial matching (maybe
3963        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
3964    
3965        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */
3966        /*--------------------------------------------------------------------*/        /*--------------------------------------------------------------------*/
3967    
3968        /* Combine the op_type with the repeat_type */        /* Combine the op_type with the repeat_type */
3969    
# Line 4026  we set the flag only if there is a liter Line 4110  we set the flag only if there is a liter
4110          goto END_REPEAT;          goto END_REPEAT;
4111          }          }
4112    
4113        /*--------------------------------------------------------------------*/        /*--------------------------------------------------------------------*/
4114        /* This code is obsolete from release 8.00; the restriction was finally        /* This code is obsolete from release 8.00; the restriction was finally
4115        removed: */        removed: */
4116    
# Line 4034  we set the flag only if there is a liter Line 4118  we set the flag only if there is a liter
4118        one day we will be able to remove this restriction). */        one day we will be able to remove this restriction). */
4119    
4120        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */        /* if (repeat_max != 1) cd->external_flags |= PCRE_NOPARTIAL; */
4121        /*--------------------------------------------------------------------*/        /*--------------------------------------------------------------------*/
4122    
4123        if (repeat_min == 0 && repeat_max == -1)        if (repeat_min == 0 && repeat_max == -1)
4124          *code++ = OP_CRSTAR + repeat_type;          *code++ = OP_CRSTAR + repeat_type;
# Line 4169  we set the flag only if there is a liter Line 4253  we set the flag only if there is a liter
4253            {            {
4254            /* 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
4255            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
4256            potential integer overflow. */            potential integer overflow. The INT64_OR_DOUBLE type is a 64-bit
4257              integer type when available, otherwise double. */
4258    
4259            if (lengthptr != NULL)            if (lengthptr != NULL)
4260              {              {
4261              int delta = (repeat_min - 1)*length_prevgroup;              int delta = (repeat_min - 1)*length_prevgroup;
4262              if ((double)(repeat_min - 1)*(double)length_prevgroup >              if ((INT64_OR_DOUBLE)(repeat_min - 1)*
4263                                                              (double)INT_MAX ||                    (INT64_OR_DOUBLE)length_prevgroup >
4264                        (INT64_OR_DOUBLE)INT_MAX ||
4265                  OFLOW_MAX - *lengthptr < delta)                  OFLOW_MAX - *lengthptr < delta)
4266                {                {
4267                *errorcodeptr = ERR20;                *errorcodeptr = ERR20;
# Line 4221  we set the flag only if there is a liter Line 4307  we set the flag only if there is a liter
4307          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
4308          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
4309          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
4310          paranoid checks to avoid integer overflow. */          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is
4311            a 64-bit integer type when available, otherwise double. */
4312    
4313          if (lengthptr != NULL && repeat_max > 0)          if (lengthptr != NULL && repeat_max > 0)
4314            {            {
4315            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
4316                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */
4317            if ((double)repeat_max *            if ((INT64_OR_DOUBLE)repeat_max *
4318                  (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)                  (INT64_OR_DOUBLE)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)
4319                    > (double)INT_MAX ||                    > (INT64_OR_DOUBLE)INT_MAX ||
4320                OFLOW_MAX - *lengthptr < delta)                OFLOW_MAX - *lengthptr < delta)
4321              {              {
4322              *errorcodeptr = ERR20;              *errorcodeptr = ERR20;
# Line 4306  we set the flag only if there is a liter Line 4393  we set the flag only if there is a liter
4393            uschar *scode = bracode;            uschar *scode = bracode;
4394            do            do
4395              {              {
4396              if (could_be_empty_branch(scode, ketcode, utf8))              if (could_be_empty_branch(scode, ketcode, utf8, cd))
4397                {                {
4398                *bracode += OP_SBRA - OP_BRA;                *bracode += OP_SBRA - OP_BRA;
4399                break;                break;
# Line 4349  we set the flag only if there is a liter Line 4436  we set the flag only if there is a liter
4436      if (possessive_quantifier)      if (possessive_quantifier)
4437        {        {
4438        int len;        int len;
4439    
4440        if (*tempcode == OP_TYPEEXACT)        if (*tempcode == OP_TYPEEXACT)
4441          tempcode += _pcre_OP_lengths[*tempcode] +          tempcode += _pcre_OP_lengths[*tempcode] +
4442            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);            ((tempcode[3] == OP_PROP || tempcode[3] == OP_NOTPROP)? 2 : 0);
4443    
4444        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)        else if (*tempcode == OP_EXACT || *tempcode == OP_NOTEXACT)
4445          {          {
4446          tempcode += _pcre_OP_lengths[*tempcode];          tempcode += _pcre_OP_lengths[*tempcode];
# Line 4361  we set the flag only if there is a liter Line 4448  we set the flag only if there is a liter
4448          if (utf8 && tempcode[-1] >= 0xc0)          if (utf8 && tempcode[-1] >= 0xc0)
4449            tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];            tempcode += _pcre_utf8_table4[tempcode[-1] & 0x3f];
4450  #endif  #endif
4451          }          }
4452    
4453        len = code - tempcode;        len = code - tempcode;
4454        if (len > 0) switch (*tempcode)        if (len > 0) switch (*tempcode)
4455          {          {
# Line 4381  we set the flag only if there is a liter Line 4468  we set the flag only if there is a liter
4468          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;
4469          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;
4470    
4471            /* Because we are moving code along, we must ensure that any
4472            pending recursive references are updated. */
4473    
4474          default:          default:
4475            *code = OP_END;
4476            adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);
4477          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1+LINK_SIZE, tempcode, len);
4478          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
4479          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
# Line 4440  we set the flag only if there is a liter Line 4532  we set the flag only if there is a liter
4532          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
4533              strncmp((char *)name, vn, namelen) == 0)              strncmp((char *)name, vn, namelen) == 0)
4534            {            {
4535            *code = verbs[i].op;            /* Check for open captures before ACCEPT */
4536            if (*code++ == OP_ACCEPT) cd->had_accept = TRUE;  
4537              if (verbs[i].op == OP_ACCEPT)
4538                {
4539                open_capitem *oc;
4540                cd->had_accept = TRUE;
4541                for (oc = cd->open_caps; oc != NULL; oc = oc->next)
4542                  {
4543                  *code++ = OP_CLOSE;
4544                  PUT2INC(code, 0, oc->number);
4545                  }
4546                }
4547              *code++ = verbs[i].op;
4548            break;            break;
4549            }            }
4550          vn += verbs[i].len + 1;          vn += verbs[i].len + 1;
# Line 4603  we set the flag only if there is a liter Line 4706  we set the flag only if there is a liter
4706            }            }
4707    
4708          /* Otherwise (did not start with "+" or "-"), start by looking for the          /* Otherwise (did not start with "+" or "-"), start by looking for the
4709          name. */          name. If we find a name, add one to the opcode to change OP_CREF or
4710            OP_RREF into OP_NCREF or OP_NRREF. These behave exactly the same,
4711            except they record that the reference was originally to a name. The
4712            information is used to check duplicate names. */
4713    
4714          slot = cd->name_table;          slot = cd->name_table;
4715          for (i = 0; i < cd->names_found; i++)          for (i = 0; i < cd->names_found; i++)
# Line 4618  we set the flag only if there is a liter Line 4724  we set the flag only if there is a liter
4724            {            {
4725            recno = GET2(slot, 0);            recno = GET2(slot, 0);
4726            PUT2(code, 2+LINK_SIZE, recno);            PUT2(code, 2+LINK_SIZE, recno);
4727              code[1+LINK_SIZE]++;
4728            }            }
4729    
4730          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
# Line 4626  we set the flag only if there is a liter Line 4733  we set the flag only if there is a liter
4733                          (options & PCRE_EXTENDED) != 0)) > 0)                          (options & PCRE_EXTENDED) != 0)) > 0)
4734            {            {
4735            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
4736              code[1+LINK_SIZE]++;
4737            }            }
4738    
4739          /* If terminator == 0 it means that the name followed directly after          /* If terminator == 0 it means that the name followed directly after
# Line 4818  we set the flag only if there is a liter Line 4926  we set the flag only if there is a liter
4926                }                }
4927              }              }
4928    
4929            /* In the real compile, create the entry in the table */            /* In the real compile, create the entry in the table, maintaining
4930              alphabetical order. Duplicate names for different numbers are
4931              permitted only if PCRE_DUPNAMES is set. Duplicate names for the same
4932              number are always OK. (An existing number can be re-used if (?|
4933              appears in the pattern.) In either event, a duplicate name results in
4934              a duplicate entry in the table, even if the number is the same. This
4935              is because the number of names, and hence the table size, is computed
4936              in the pre-compile, and it affects various numbers and pointers which
4937              would all have to be modified, and the compiled code moved down, if
4938              duplicates with the same number were omitted from the table. This
4939              doesn't seem worth the hassle. However, *different* names for the
4940              same number are not permitted. */
4941    
4942            else            else
4943              {              {
4944                BOOL dupname = FALSE;
4945              slot = cd->name_table;              slot = cd->name_table;
4946    
4947              for (i = 0; i < cd->names_found; i++)              for (i = 0; i < cd->names_found; i++)
4948                {                {
4949                int crc = memcmp(name, slot+2, namelen);                int crc = memcmp(name, slot+2, namelen);
# Line 4830  we set the flag only if there is a liter Line 4951  we set the flag only if there is a liter
4951                  {                  {
4952                  if (slot[2+namelen] == 0)                  if (slot[2+namelen] == 0)
4953                    {                    {
4954                    if ((options & PCRE_DUPNAMES) == 0)                    if (GET2(slot, 0) != cd->bracount + 1 &&
4955                          (options & PCRE_DUPNAMES) == 0)
4956                      {                      {
4957                      *errorcodeptr = ERR43;                      *errorcodeptr = ERR43;
4958                      goto FAILED;                      goto FAILED;
4959                      }                      }
4960                      else dupname = TRUE;
4961                    }                    }
4962                  else crc = -1;      /* Current name is substring */                  else crc = -1;      /* Current name is a substring */
4963                  }                  }
4964    
4965                  /* Make space in the table and break the loop for an earlier
4966                  name. For a duplicate or later name, carry on. We do this for
4967                  duplicates so that in the simple case (when ?(| is not used) they
4968                  are in order of their numbers. */
4969    
4970                if (crc < 0)                if (crc < 0)
4971                  {                  {
4972                  memmove(slot + cd->name_entry_size, slot,                  memmove(slot + cd->name_entry_size, slot,
4973                    (cd->names_found - i) * cd->name_entry_size);                    (cd->names_found - i) * cd->name_entry_size);
4974                  break;                  break;
4975                  }                  }
4976    
4977                  /* Continue the loop for a later or duplicate name */
4978    
4979                slot += cd->name_entry_size;                slot += cd->name_entry_size;
4980                }                }
4981    
4982                /* For non-duplicate names, check for a duplicate number before
4983                adding the new name. */
4984    
4985                if (!dupname)
4986                  {
4987                  uschar *cslot = cd->name_table;
4988                  for (i = 0; i < cd->names_found; i++)
4989                    {
4990                    if (cslot != slot)
4991                      {
4992                      if (GET2(cslot, 0) == cd->bracount + 1)
4993                        {
4994                        *errorcodeptr = ERR65;
4995                        goto FAILED;
4996                        }
4997                      }
4998                    else i--;
4999                    cslot += cd->name_entry_size;
5000                    }
5001                  }
5002    
5003              PUT2(slot, 0, cd->bracount + 1);              PUT2(slot, 0, cd->bracount + 1);
5004              memcpy(slot + 2, name, namelen);              memcpy(slot + 2, name, namelen);
5005              slot[2+namelen] = 0;              slot[2+namelen] = 0;
5006              }              }
5007            }            }
5008    
5009          /* In both cases, count the number of names we've encountered. */          /* In both pre-compile and compile, count the number of names we've
5010            encountered. */
5011    
         ptr++;                    /* Move past > or ' */  
5012          cd->names_found++;          cd->names_found++;
5013            ptr++;                    /* Move past > or ' */
5014          goto NUMBERED_GROUP;          goto NUMBERED_GROUP;
5015    
5016    
# Line 5025  we set the flag only if there is a liter Line 5179  we set the flag only if there is a liter
5179            if (lengthptr == NULL)            if (lengthptr == NULL)
5180              {              {
5181              *code = OP_END;              *code = OP_END;
5182              if (recno != 0) called = find_bracket(cd->start_code, utf8, recno);              if (recno != 0)
5183                  called = _pcre_find_bracket(cd->start_code, utf8, recno);
5184    
5185              /* Forward reference */              /* Forward reference */
5186    
# Line 5037  we set the flag only if there is a liter Line 5192  we set the flag only if there is a liter
5192                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
5193                  goto FAILED;                  goto FAILED;
5194                  }                  }
5195    
5196                  /* Fudge the value of "called" so that when it is inserted as an
5197                  offset below, what it actually inserted is the reference number
5198                  of the group. */
5199    
5200                called = cd->start_code + recno;                called = cd->start_code + recno;
5201                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);
5202                }                }
# Line 5046  we set the flag only if there is a liter Line 5206  we set the flag only if there is a liter
5206              recursion that could loop for ever, and diagnose that case. */              recursion that could loop for ever, and diagnose that case. */
5207    
5208              else if (GET(called, 1) == 0 &&              else if (GET(called, 1) == 0 &&
5209                       could_be_empty(called, code, bcptr, utf8))                       could_be_empty(called, code, bcptr, utf8, cd))
5210                {                {
5211                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
5212                goto FAILED;                goto FAILED;
# Line 5141  we set the flag only if there is a liter Line 5301  we set the flag only if there is a liter
5301              {              {
5302              cd->external_options = newoptions;              cd->external_options = newoptions;
5303              }              }
5304           else            else
5305              {              {
5306              if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))              if ((options & PCRE_IMS) != (newoptions & PCRE_IMS))
5307                {                {
# Line 5478  we set the flag only if there is a liter Line 5638  we set the flag only if there is a liter
5638    
5639        if (-c >= ESC_REF)        if (-c >= ESC_REF)
5640          {          {
5641            open_capitem *oc;
5642          recno = -c - ESC_REF;          recno = -c - ESC_REF;
5643    
5644          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
# Line 5487  we set the flag only if there is a liter Line 5648  we set the flag only if there is a liter
5648          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
5649          cd->backref_map |= (recno < 32)? (1 << recno) : 1;          cd->backref_map |= (recno < 32)? (1 << recno) : 1;
5650          if (recno > cd->top_backref) cd->top_backref = recno;          if (recno > cd->top_backref) cd->top_backref = recno;
5651    
5652            /* Check to see if this back reference is recursive, that it, it
5653            is inside the group that it references. A flag is set so that the
5654            group can be made atomic. */
5655    
5656            for (oc = cd->open_caps; oc != NULL; oc = oc->next)
5657              {
5658              if (oc->number == recno)
5659                {
5660                oc->flag = TRUE;
5661                break;
5662                }
5663              }
5664          }          }
5665    
5666        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
# Line 5669  uschar *code = *codeptr; Line 5843  uschar *code = *codeptr;
5843  uschar *last_branch = code;  uschar *last_branch = code;
5844  uschar *start_bracket = code;  uschar *start_bracket = code;
5845  uschar *reverse_count = NULL;  uschar *reverse_count = NULL;
5846    open_capitem capitem;
5847    int capnumber = 0;
5848  int firstbyte, reqbyte;  int firstbyte, reqbyte;
5849  int branchfirstbyte, branchreqbyte;  int branchfirstbyte, branchreqbyte;
5850  int length;  int length;
5851  int orig_bracount;  int orig_bracount;
5852  int max_bracount;  int max_bracount;
5853    int old_external_options = cd->external_options;
5854  branch_chain bc;  branch_chain bc;
5855    
5856  bc.outer = bcptr;  bc.outer = bcptr;
5857  bc.current = code;  bc.current_branch = code;
5858    
5859  firstbyte = reqbyte = REQ_UNSET;  firstbyte = reqbyte = REQ_UNSET;
5860    
# Line 5695  the code that abstracts option settings Line 5872  the code that abstracts option settings
5872  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
5873  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. */
5874    
5875    /* If this is a capturing subpattern, add to the chain of open capturing items
5876    so that we can detect them if (*ACCEPT) is encountered. This is also used to
5877    detect groups that contain recursive back references to themselves. */
5878    
5879    if (*code == OP_CBRA)
5880      {
5881      capnumber = GET2(code, 1 + LINK_SIZE);
5882      capitem.number = capnumber;
5883      capitem.next = cd->open_caps;
5884      capitem.flag = FALSE;
5885      cd->open_caps = &capitem;
5886      }
5887    
5888  /* Offset is set zero to mark that this bracket is still open */  /* Offset is set zero to mark that this bracket is still open */
5889    
5890  PUT(code, 1, 0);  PUT(code, 1, 0);
# Line 5739  for (;;) Line 5929  for (;;)
5929      return FALSE;      return FALSE;
5930      }      }
5931    
5932      /* If the external options have changed during this branch, it means that we
5933      are at the top level, and a leading option setting has been encountered. We
5934      need to re-set the original option values to take account of this so that,
5935      during the pre-compile phase, we know to allow for a re-set at the start of
5936      subsequent branches. */
5937    
5938      if (old_external_options != cd->external_options)
5939        oldims = cd->external_options & PCRE_IMS;
5940    
5941    /* Keep the highest bracket count in case (?| was used and some branch    /* Keep the highest bracket count in case (?| was used and some branch
5942    has fewer than the rest. */    has fewer than the rest. */
5943    
# Line 5789  for (;;) Line 5988  for (;;)
5988    
5989      /* If lookbehind, check that this branch matches a fixed-length string, and      /* If lookbehind, check that this branch matches a fixed-length string, and
5990      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
5991      branch with OP_END. */      branch with OP_END. If the branch contains OP_RECURSE, the result is -3
5992        because there may be forward references that we can't check here. Set a
5993        flag to cause another lookbehind check at the end. Why not do it all at the
5994        end? Because common, erroneous checks are picked up here and the offset of
5995        the problem can be shown. */
5996    
5997      if (lookbehind)      if (lookbehind)
5998        {        {
5999        int fixed_length;        int fixed_length;
6000        *code = OP_END;        *code = OP_END;
6001        fixed_length = find_fixedlength(last_branch, options);        fixed_length = find_fixedlength(last_branch, options, FALSE, cd);
6002        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
6003        if (fixed_length < 0)        if (fixed_length == -3)
6004            {
6005            cd->check_lookbehind = TRUE;
6006            }
6007          else if (fixed_length < 0)
6008          {          {
6009          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;          *errorcodeptr = (fixed_length == -2)? ERR36 : ERR25;
6010          *ptrptr = ptr;          *ptrptr = ptr;
6011          return FALSE;          return FALSE;
6012          }          }
6013        PUT(reverse_count, 0, fixed_length);        else { PUT(reverse_count, 0, fixed_length); }
6014        }        }
6015      }      }
6016    
# Line 5837  for (;;) Line 6044  for (;;)
6044      PUT(code, 1, code - start_bracket);      PUT(code, 1, code - start_bracket);
6045      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6046    
6047      /* Resetting option if needed */      /* If it was a capturing subpattern, check to see if it contained any
6048        recursive back references. If so, we must wrap it in atomic brackets.
6049        In any event, remove the block from the chain. */
6050    
6051        if (capnumber > 0)
6052          {
6053          if (cd->open_caps->flag)
6054            {
6055            memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
6056              code - start_bracket);
6057            *start_bracket = OP_ONCE;
6058            code += 1 + LINK_SIZE;
6059            PUT(start_bracket, 1, code - start_bracket);
6060            *code = OP_KET;
6061            PUT(code, 1, code - start_bracket);
6062            code += 1 + LINK_SIZE;
6063            length += 2 + 2*LINK_SIZE;
6064            }
6065          cd->open_caps = cd->open_caps->next;
6066          }
6067    
6068        /* Reset options if needed. */
6069    
6070      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)
6071        {        {
# Line 5886  for (;;) Line 6114  for (;;)
6114      {      {
6115      *code = OP_ALT;      *code = OP_ALT;
6116      PUT(code, 1, code - last_branch);      PUT(code, 1, code - last_branch);
6117      bc.current = last_branch = code;      bc.current_branch = last_branch = code;
6118      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6119      }      }
6120    
# Line 6033  do { Line 6261  do {
6261       switch (*scode)       switch (*scode)
6262         {         {
6263         case OP_CREF:         case OP_CREF:
6264           case OP_NCREF:
6265         case OP_RREF:         case OP_RREF:
6266           case OP_NRREF:
6267         case OP_DEF:         case OP_DEF:
6268         return FALSE;         return FALSE;
6269    
# Line 6202  int length = 1;  /* For final END opcode Line 6432  int length = 1;  /* For final END opcode
6432  int firstbyte, reqbyte, newline;  int firstbyte, reqbyte, newline;
6433  int errorcode = 0;  int errorcode = 0;
6434  int skipatstart = 0;  int skipatstart = 0;
6435  #ifdef SUPPORT_UTF8  BOOL utf8 = (options & PCRE_UTF8) != 0;
 BOOL utf8;  
 #endif  
6436  size_t size;  size_t size;
6437  uschar *code;  uschar *code;
6438  const uschar *codestart;  const uschar *codestart;
# Line 6301  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 6529  while (ptr[skipatstart] == CHAR_LEFT_PAR
6529  /* Can't support UTF8 unless PCRE has been compiled to include the code. */  /* Can't support UTF8 unless PCRE has been compiled to include the code. */
6530    
6531  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
 utf8 = (options & PCRE_UTF8) != 0;  
6532  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
6533       (*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0)       (*erroroffset = _pcre_valid_utf8((USPTR)pattern, -1)) >= 0)
6534    {    {
6535    errorcode = ERR44;    errorcode = ERR44;
6536    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
6537    }    }
6538  #else  #else
6539  if ((options & PCRE_UTF8) != 0)  if (utf8)
6540    {    {
6541    errorcode = ERR32;    errorcode = ERR32;
6542    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
# Line 6398  cd->end_pattern = (const uschar *)(patte Line 6625  cd->end_pattern = (const uschar *)(patte
6625  cd->req_varyopt = 0;  cd->req_varyopt = 0;
6626  cd->external_options = options;  cd->external_options = options;
6627  cd->external_flags = 0;  cd->external_flags = 0;
6628    cd->open_caps = NULL;
6629    
6630  /* 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
6631  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 6472  cd->start_code = codestart; Line 6700  cd->start_code = codestart;
6700  cd->hwm = cworkspace;  cd->hwm = cworkspace;
6701  cd->req_varyopt = 0;  cd->req_varyopt = 0;
6702  cd->had_accept = FALSE;  cd->had_accept = FALSE;
6703    cd->check_lookbehind = FALSE;
6704    cd->open_caps = NULL;
6705    
6706  /* Set up a starting, non-extracting bracket, then compile the expression. On  /* Set up a starting, non-extracting bracket, then compile the expression. On
6707  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 6497  if debugging, leave the test till after Line 6727  if debugging, leave the test till after
6727    
6728  *code++ = OP_END;  *code++ = OP_END;
6729    
6730  #ifndef DEBUG  #ifndef PCRE_DEBUG
6731  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
6732  #endif  #endif
6733    
# Line 6510  while (errorcode == 0 && cd->hwm > cwork Line 6740  while (errorcode == 0 && cd->hwm > cwork
6740    cd->hwm -= LINK_SIZE;    cd->hwm -= LINK_SIZE;
6741    offset = GET(cd->hwm, 0);    offset = GET(cd->hwm, 0);
6742    recno = GET(codestart, offset);    recno = GET(codestart, offset);
6743    groupptr = find_bracket(codestart, (re->options & PCRE_UTF8) != 0, recno);    groupptr = _pcre_find_bracket(codestart, utf8, recno);
6744    if (groupptr == NULL) errorcode = ERR53;    if (groupptr == NULL) errorcode = ERR53;
6745      else PUT(((uschar *)codestart), offset, groupptr - codestart);      else PUT(((uschar *)codestart), offset, groupptr - codestart);
6746    }    }
# Line 6520  subpattern. */ Line 6750  subpattern. */
6750    
6751  if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;  if (errorcode == 0 && re->top_backref > re->top_bracket) errorcode = ERR15;
6752    
6753    /* If there were any lookbehind assertions that contained OP_RECURSE
6754    (recursions or subroutine calls), a flag is set for them to be checked here,
6755    because they may contain forward references. Actual recursions can't be fixed
6756    length, but subroutine calls can. It is done like this so that those without
6757    OP_RECURSE that are not fixed length get a diagnosic with a useful offset. The
6758    exceptional ones forgo this. We scan the pattern to check that they are fixed
6759    length, and set their lengths. */
6760    
6761    if (cd->check_lookbehind)
6762      {
6763      uschar *cc = (uschar *)codestart;
6764    
6765      /* Loop, searching for OP_REVERSE items, and process those that do not have
6766      their length set. (Actually, it will also re-process any that have a length
6767      of zero, but that is a pathological case, and it does no harm.) When we find
6768      one, we temporarily terminate the branch it is in while we scan it. */
6769    
6770      for (cc = (uschar *)_pcre_find_bracket(codestart, utf8, -1);
6771           cc != NULL;
6772           cc = (uschar *)_pcre_find_bracket(cc, utf8, -1))
6773        {
6774        if (GET(cc, 1) == 0)
6775          {
6776          int fixed_length;
6777          uschar *be = cc - 1 - LINK_SIZE + GET(cc, -LINK_SIZE);
6778          int end_op = *be;
6779          *be = OP_END;
6780          fixed_length = find_fixedlength(cc, re->options, TRUE, cd);
6781          *be = end_op;
6782          DPRINTF(("fixed length = %d\n", fixed_length));
6783          if (fixed_length < 0)
6784            {
6785            errorcode = (fixed_length == -2)? ERR36 : ERR25;
6786            break;
6787            }
6788          PUT(cc, 1, fixed_length);
6789          }
6790        cc += 1 + LINK_SIZE;
6791        }
6792      }
6793    
6794  /* Failed to compile, or error while post-processing */  /* Failed to compile, or error while post-processing */
6795    
6796  if (errorcode != 0)  if (errorcode != 0)
# Line 6580  if (reqbyte >= 0 && Line 6851  if (reqbyte >= 0 &&
6851  /* 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
6852  case when building a production library. */  case when building a production library. */
6853    
6854  #ifdef DEBUG  #ifdef PCRE_DEBUG
   
6855  printf("Length = %d top_bracket = %d top_backref = %d\n",  printf("Length = %d top_bracket = %d top_backref = %d\n",
6856    length, re->top_bracket, re->top_backref);    length, re->top_bracket, re->top_backref);
6857    
# Line 6618  if (code - codestart > length) Line 6888  if (code - codestart > length)
6888    if (errorcodeptr != NULL) *errorcodeptr = ERR23;    if (errorcodeptr != NULL) *errorcodeptr = ERR23;
6889    return NULL;    return NULL;
6890    }    }
6891  #endif   /* DEBUG */  #endif   /* PCRE_DEBUG */
6892    
6893  return (pcre *)re;  return (pcre *)re;
6894  }  }

Legend:
Removed from v.438  
changed lines
  Added in v.504

  ViewVC Help
Powered by ViewVC 1.1.5