/[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 472 by ph10, Fri Dec 11 16:42:50 2009 UTC revision 513 by ph10, Mon May 3 11:13:37 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 91  is 4 there is plenty of room. */ Line 92  is 4 there is plenty of room. */
92    
93  #define COMPILE_WORK_SIZE (4096)  #define COMPILE_WORK_SIZE (4096)
94    
95    /* The overrun tests check for a slightly smaller size so that they detect the
96    overrun before it actually does run off the end of the data block. */
97    
98    #define WORK_SIZE_CHECK (COMPILE_WORK_SIZE - 100)
99    
100    
101  /* Table for handling escaped characters in the range '0'-'z'. Positive returns  /* Table for handling escaped characters in the range '0'-'z'. Positive returns
102  are simple data values; negative values are for special things like \d and so  are simple data values; negative values are for special things like \d and so
# Line 182  string is built from string macros so th Line 188  string is built from string macros so th
188  platforms. */  platforms. */
189    
190  typedef struct verbitem {  typedef struct verbitem {
191    int   len;    int   len;                 /* Length of verb name */
192    int   op;    int   op;                  /* Op when no arg, or -1 if arg mandatory */
193      int   op_arg;              /* Op when arg present, or -1 if not allowed */
194  } verbitem;  } verbitem;
195    
196  static const char verbnames[] =  static const char verbnames[] =
197      "\0"                       /* Empty name is a shorthand for MARK */
198      STRING_MARK0
199    STRING_ACCEPT0    STRING_ACCEPT0
200    STRING_COMMIT0    STRING_COMMIT0
201    STRING_F0    STRING_F0
# Line 196  static const char verbnames[] = Line 205  static const char verbnames[] =
205    STRING_THEN;    STRING_THEN;
206    
207  static const verbitem verbs[] = {  static const verbitem verbs[] = {
208    { 6, OP_ACCEPT },    { 0, -1,        OP_MARK },
209    { 6, OP_COMMIT },    { 4, -1,        OP_MARK },
210    { 1, OP_FAIL },    { 6, OP_ACCEPT, -1 },
211    { 4, OP_FAIL },    { 6, OP_COMMIT, -1 },
212    { 5, OP_PRUNE },    { 1, OP_FAIL,   -1 },
213    { 4, OP_SKIP  },    { 4, OP_FAIL,   -1 },
214    { 4, OP_THEN  }    { 5, OP_PRUNE,  OP_PRUNE_ARG },
215      { 4, OP_SKIP,   OP_SKIP_ARG  },
216      { 4, OP_THEN,   OP_THEN_ARG  }
217  };  };
218    
219  static const int verbcount = sizeof(verbs)/sizeof(verbitem);  static const int verbcount = sizeof(verbs)/sizeof(verbitem);
# Line 262  the number of relocations needed when a Line 273  the number of relocations needed when a
273  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
274  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
275  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
276  because these strings are used only when there is a compilation error. */  because these strings are used only when there is a compilation error.
277    
278    Each substring ends with \0 to insert a null character. This includes the final
279    substring, so that the whole string ends with \0\0, which can be detected when
280    counting through. */
281    
282  static const char error_texts[] =  static const char error_texts[] =
283    "no error\0"    "no error\0"
# Line 335  static const char error_texts[] = Line 350  static const char error_texts[] =
350    "inconsistent NEWLINE options\0"    "inconsistent NEWLINE options\0"
351    "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"    "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"
352    "a numbered reference must not be zero\0"    "a numbered reference must not be zero\0"
353    "(*VERB) with an argument is not supported\0"    "an argument is not allowed for (*ACCEPT), (*FAIL), or (*COMMIT)\0"
354    /* 60 */    /* 60 */
355    "(*VERB) not recognized\0"    "(*VERB) not recognized\0"
356    "number is too big\0"    "number is too big\0"
# Line 343  static const char error_texts[] = Line 358  static const char error_texts[] =
358    "digit expected after (?+\0"    "digit expected after (?+\0"
359    "] is an invalid data character in JavaScript compatibility mode\0"    "] is an invalid data character in JavaScript compatibility mode\0"
360    /* 65 */    /* 65 */
361    "different names for subpatterns of the same number are not allowed";    "different names for subpatterns of the same number are not allowed\0"
362      "(*MARK) must have an argument\0"
363      ;
364    
365  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
366  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 502  static const char * Line 518  static const char *
518  find_error_text(int n)  find_error_text(int n)
519  {  {
520  const char *s = error_texts;  const char *s = error_texts;
521  for (; n > 0; n--) while (*s++ != 0) {};  for (; n > 0; n--)
522      {
523      while (*s++ != 0) {};
524      if (*s == 0) return "Error text not found (please report)";
525      }
526  return s;  return s;
527  }  }
528    
# Line 1442  for (;;) Line 1462  for (;;)
1462      case OP_CALLOUT:      case OP_CALLOUT:
1463      case OP_SOD:      case OP_SOD:
1464      case OP_SOM:      case OP_SOM:
1465        case OP_SET_SOM:
1466      case OP_EOD:      case OP_EOD:
1467      case OP_EODN:      case OP_EODN:
1468      case OP_CIRC:      case OP_CIRC:
# Line 1601  for (;;) Line 1622  for (;;)
1622    
1623    /* Otherwise, we can get the item's length from the table, except that for    /* Otherwise, we can get the item's length from the table, except that for
1624    repeated character types, we have to test for \p and \P, which have an extra    repeated character types, we have to test for \p and \P, which have an extra
1625    two bytes of parameters. */    two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we
1626      must add in its length. */
1627    
1628    else    else
1629      {      {
# Line 1625  for (;;) Line 1647  for (;;)
1647        case OP_TYPEPOSUPTO:        case OP_TYPEPOSUPTO:
1648        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1649        break;        break;
1650    
1651          case OP_MARK:
1652          case OP_PRUNE_ARG:
1653          case OP_SKIP_ARG:
1654          case OP_THEN_ARG:
1655          code += code[1];
1656          break;
1657        }        }
1658    
1659      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
# Line 1696  for (;;) Line 1725  for (;;)
1725    
1726    /* Otherwise, we can get the item's length from the table, except that for    /* Otherwise, we can get the item's length from the table, except that for
1727    repeated character types, we have to test for \p and \P, which have an extra    repeated character types, we have to test for \p and \P, which have an extra
1728    two bytes of parameters. */    two bytes of parameters, and for MARK/PRUNE/SKIP/THEN with an argument, we
1729      must add in its length. */
1730    
1731    else    else
1732      {      {
# Line 1720  for (;;) Line 1750  for (;;)
1750        case OP_TYPEEXACT:        case OP_TYPEEXACT:
1751        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;        if (code[3] == OP_PROP || code[3] == OP_NOTPROP) code += 2;
1752        break;        break;
1753    
1754          case OP_MARK:
1755          case OP_PRUNE_ARG:
1756          case OP_SKIP_ARG:
1757          case OP_THEN_ARG:
1758          code += code[1];
1759          break;
1760        }        }
1761    
1762      /* Add in the fixed length from the table */      /* Add in the fixed length from the table */
# Line 1776  Arguments: Line 1813  Arguments:
1813    code        points to start of search    code        points to start of search
1814    endcode     points to where to stop    endcode     points to where to stop
1815    utf8        TRUE if in UTF8 mode    utf8        TRUE if in UTF8 mode
1816      cd          contains pointers to tables etc.
1817    
1818  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
1819  */  */
1820    
1821  static BOOL  static BOOL
1822  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8)  could_be_empty_branch(const uschar *code, const uschar *endcode, BOOL utf8,
1823      compile_data *cd)
1824  {  {
1825  register int c;  register int c;
1826  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 1812  for (code = first_significant_code(code Line 1851  for (code = first_significant_code(code
1851      continue;      continue;
1852      }      }
1853    
1854      /* For a recursion/subroutine call, if its end has been reached, which
1855      implies a subroutine call, we can scan it. */
1856    
1857      if (c == OP_RECURSE)
1858        {
1859        BOOL empty_branch = FALSE;
1860        const uschar *scode = cd->start_code + GET(code, 1);
1861        if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */
1862        do
1863          {
1864          if (could_be_empty_branch(scode, endcode, utf8, cd))
1865            {
1866            empty_branch = TRUE;
1867            break;
1868            }
1869          scode += GET(scode, 1);
1870          }
1871        while (*scode == OP_ALT);
1872        if (!empty_branch) return FALSE;  /* All branches are non-empty */
1873        continue;
1874        }
1875    
1876    /* For other groups, scan the branches. */    /* For other groups, scan the branches. */
1877    
1878    if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND)    if (c == OP_BRA || c == OP_CBRA || c == OP_ONCE || c == OP_COND)
# Line 1830  for (code = first_significant_code(code Line 1891  for (code = first_significant_code(code
1891        empty_branch = FALSE;        empty_branch = FALSE;
1892        do        do
1893          {          {
1894          if (!empty_branch && could_be_empty_branch(code, endcode, utf8))          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))
1895            empty_branch = TRUE;            empty_branch = TRUE;
1896          code += GET(code, 1);          code += GET(code, 1);
1897          }          }
# Line 1964  for (code = first_significant_code(code Line 2025  for (code = first_significant_code(code
2025      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];
2026      break;      break;
2027  #endif  #endif
2028    
2029        /* MARK, and PRUNE/SKIP/THEN with an argument must skip over the argument
2030        string. */
2031    
2032        case OP_MARK:
2033        case OP_PRUNE_ARG:
2034        case OP_SKIP_ARG:
2035        case OP_THEN_ARG:
2036        code += code[1];
2037        break;
2038    
2039        /* None of the remaining opcodes are required to match a character. */
2040    
2041        default:
2042        break;
2043      }      }
2044    }    }
2045    
# Line 1986  Arguments: Line 2062  Arguments:
2062    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2063    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2064    utf8        TRUE if in UTF-8 mode    utf8        TRUE if in UTF-8 mode
2065      cd          pointers to tables etc
2066    
2067  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2068  */  */
2069    
2070  static BOOL  static BOOL
2071  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,
2072    BOOL utf8)    BOOL utf8, compile_data *cd)
2073  {  {
2074  while (bcptr != NULL && bcptr->current >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2075    {    {
2076    if (!could_be_empty_branch(bcptr->current, endcode, utf8)) return FALSE;    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))
2077        return FALSE;
2078    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2079    }    }
2080  return TRUE;  return TRUE;
# Line 2658  BOOL utf8 = FALSE; Line 2736  BOOL utf8 = FALSE;
2736  uschar *utf8_char = NULL;  uschar *utf8_char = NULL;
2737  #endif  #endif
2738    
2739  #ifdef DEBUG  #ifdef PCRE_DEBUG
2740  if (lengthptr != NULL) DPRINTF((">> start branch\n"));  if (lengthptr != NULL) DPRINTF((">> start branch\n"));
2741  #endif  #endif
2742    
# Line 2717  for (;; ptr++) Line 2795  for (;; ptr++)
2795    
2796    if (lengthptr != NULL)    if (lengthptr != NULL)
2797      {      {
2798  #ifdef DEBUG  #ifdef PCRE_DEBUG
2799      if (code > cd->hwm) cd->hwm = code;                 /* High water info */      if (code > cd->hwm) cd->hwm = code;                 /* High water info */
2800  #endif  #endif
2801      if (code > cd->start_workspace + COMPILE_WORK_SIZE) /* Check for overrun */      if (code > cd->start_workspace + WORK_SIZE_CHECK)   /* Check for overrun */
2802        {        {
2803        *errorcodeptr = ERR52;        *errorcodeptr = ERR52;
2804        goto FAILED;        goto FAILED;
# Line 2769  for (;; ptr++) Line 2847  for (;; ptr++)
2847    /* In the real compile phase, just check the workspace used by the forward    /* In the real compile phase, just check the workspace used by the forward
2848    reference list. */    reference list. */
2849    
2850    else if (cd->hwm > cd->start_workspace + COMPILE_WORK_SIZE)    else if (cd->hwm > cd->start_workspace + WORK_SIZE_CHECK)
2851      {      {
2852      *errorcodeptr = ERR52;      *errorcodeptr = ERR52;
2853      goto FAILED;      goto FAILED;
# Line 3126  for (;; ptr++) Line 3204  for (;; ptr++)
3204    
3205        /* Backslash may introduce a single character, or it may introduce one        /* Backslash may introduce a single character, or it may introduce one
3206        of the specials, which just set a flag. The sequence \b is a special        of the specials, which just set a flag. The sequence \b is a special
3207        case. Inside a class (and only there) it is treated as backspace.        case. Inside a class (and only there) it is treated as backspace. We
3208        Elsewhere it marks a word boundary. Other escapes have preset maps ready        assume that other escapes have more than one character in them, so set
3209        to 'or' into the one we are building. We assume they have more than one        class_charcount bigger than one. Unrecognized escapes fall through and
3210        character in them, so set class_charcount bigger than one. */        are either treated as literal characters (by default), or are faulted if
3211          PCRE_EXTRA is set. */
3212    
3213        if (c == CHAR_BACKSLASH)        if (c == CHAR_BACKSLASH)
3214          {          {
3215          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);          c = check_escape(&ptr, errorcodeptr, cd->bracount, options, TRUE);
3216          if (*errorcodeptr != 0) goto FAILED;          if (*errorcodeptr != 0) goto FAILED;
3217    
3218          if (-c == ESC_b) c = CHAR_BS;       /* \b is backspace in a class */          if (-c == ESC_b) c = CHAR_BS;    /* \b is backspace in a class */
         else if (-c == ESC_X) c = CHAR_X;   /* \X is literal X in a class */  
         else if (-c == ESC_R) c = CHAR_R;   /* \R is literal R in a class */  
3219          else if (-c == ESC_Q)            /* Handle start of quoted string */          else if (-c == ESC_Q)            /* Handle start of quoted string */
3220            {            {
3221            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)            if (ptr[1] == CHAR_BACKSLASH && ptr[2] == CHAR_E)
# Line 4213  we set the flag only if there is a liter Line 4290  we set the flag only if there is a liter
4290            {            {
4291            /* 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
4292            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
4293            potential integer overflow. */            potential integer overflow. The INT64_OR_DOUBLE type is a 64-bit
4294              integer type when available, otherwise double. */
4295    
4296            if (lengthptr != NULL)            if (lengthptr != NULL)
4297              {              {
4298              int delta = (repeat_min - 1)*length_prevgroup;              int delta = (repeat_min - 1)*length_prevgroup;
4299              if ((double)(repeat_min - 1)*(double)length_prevgroup >              if ((INT64_OR_DOUBLE)(repeat_min - 1)*
4300                                                              (double)INT_MAX ||                    (INT64_OR_DOUBLE)length_prevgroup >
4301                        (INT64_OR_DOUBLE)INT_MAX ||
4302                  OFLOW_MAX - *lengthptr < delta)                  OFLOW_MAX - *lengthptr < delta)
4303                {                {
4304                *errorcodeptr = ERR20;                *errorcodeptr = ERR20;
# Line 4265  we set the flag only if there is a liter Line 4344  we set the flag only if there is a liter
4344          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
4345          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
4346          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
4347          paranoid checks to avoid integer overflow. */          paranoid checks to avoid integer overflow. The INT64_OR_DOUBLE type is
4348            a 64-bit integer type when available, otherwise double. */
4349    
4350          if (lengthptr != NULL && repeat_max > 0)          if (lengthptr != NULL && repeat_max > 0)
4351            {            {
4352            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -            int delta = repeat_max * (length_prevgroup + 1 + 2 + 2*LINK_SIZE) -
4353                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */                        2 - 2*LINK_SIZE;   /* Last one doesn't nest */
4354            if ((double)repeat_max *            if ((INT64_OR_DOUBLE)repeat_max *
4355                  (double)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)                  (INT64_OR_DOUBLE)(length_prevgroup + 1 + 2 + 2*LINK_SIZE)
4356                    > (double)INT_MAX ||                    > (INT64_OR_DOUBLE)INT_MAX ||
4357                OFLOW_MAX - *lengthptr < delta)                OFLOW_MAX - *lengthptr < delta)
4358              {              {
4359              *errorcodeptr = ERR20;              *errorcodeptr = ERR20;
# Line 4350  we set the flag only if there is a liter Line 4430  we set the flag only if there is a liter
4430            uschar *scode = bracode;            uschar *scode = bracode;
4431            do            do
4432              {              {
4433              if (could_be_empty_branch(scode, ketcode, utf8))              if (could_be_empty_branch(scode, ketcode, utf8, cd))
4434                {                {
4435                *bracode += OP_SBRA - OP_BRA;                *bracode += OP_SBRA - OP_BRA;
4436                break;                break;
# Line 4425  we set the flag only if there is a liter Line 4505  we set the flag only if there is a liter
4505          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;          case OP_NOTQUERY: *tempcode = OP_NOTPOSQUERY; break;
4506          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;          case OP_NOTUPTO:  *tempcode = OP_NOTPOSUPTO; break;
4507    
4508            /* Because we are moving code along, we must ensure that any
4509            pending recursive references are updated. */
4510    
4511          default:          default:
4512            *code = OP_END;
4513            adjust_recurse(tempcode, 1 + LINK_SIZE, utf8, cd, save_hwm);
4514          memmove(tempcode + 1+LINK_SIZE, tempcode, len);          memmove(tempcode + 1+LINK_SIZE, tempcode, len);
4515          code += 1 + LINK_SIZE;          code += 1 + LINK_SIZE;
4516          len += 1 + LINK_SIZE;          len += 1 + LINK_SIZE;
# Line 4461  we set the flag only if there is a liter Line 4546  we set the flag only if there is a liter
4546    
4547      /* First deal with various "verbs" that can be introduced by '*'. */      /* First deal with various "verbs" that can be introduced by '*'. */
4548    
4549      if (*(++ptr) == CHAR_ASTERISK && (cd->ctypes[ptr[1]] & ctype_letter) != 0)      if (*(++ptr) == CHAR_ASTERISK &&
4550             ((cd->ctypes[ptr[1]] & ctype_letter) != 0 || ptr[1] == ':'))
4551        {        {
4552        int i, namelen;        int i, namelen;
4553          int arglen = 0;
4554        const char *vn = verbnames;        const char *vn = verbnames;
4555        const uschar *name = ++ptr;        const uschar *name = ptr + 1;
4556          const uschar *arg = NULL;
4557        previous = NULL;        previous = NULL;
4558        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};        while ((cd->ctypes[*++ptr] & ctype_letter) != 0) {};
4559          namelen = ptr - name;
4560    
4561        if (*ptr == CHAR_COLON)        if (*ptr == CHAR_COLON)
4562          {          {
4563          *errorcodeptr = ERR59;   /* Not supported */          arg = ++ptr;
4564          goto FAILED;          while ((cd->ctypes[*ptr] & (ctype_letter|ctype_digit)) != 0
4565              || *ptr == '_') ptr++;
4566            arglen = ptr - arg;
4567          }          }
4568    
4569        if (*ptr != CHAR_RIGHT_PARENTHESIS)        if (*ptr != CHAR_RIGHT_PARENTHESIS)
4570          {          {
4571          *errorcodeptr = ERR60;          *errorcodeptr = ERR60;
4572          goto FAILED;          goto FAILED;
4573          }          }
4574        namelen = ptr - name;  
4575          /* Scan the table of verb names */
4576    
4577        for (i = 0; i < verbcount; i++)        for (i = 0; i < verbcount; i++)
4578          {          {
4579          if (namelen == verbs[i].len &&          if (namelen == verbs[i].len &&
# Line 4496  we set the flag only if there is a liter Line 4591  we set the flag only if there is a liter
4591                PUT2INC(code, 0, oc->number);                PUT2INC(code, 0, oc->number);
4592                }                }
4593              }              }
4594            *code++ = verbs[i].op;  
4595            break;            /* Handle the cases with/without an argument */
4596    
4597              if (arglen == 0)
4598                {
4599                if (verbs[i].op < 0)   /* Argument is mandatory */
4600                  {
4601                  *errorcodeptr = ERR66;
4602                  goto FAILED;
4603                  }
4604                *code++ = verbs[i].op;
4605                }
4606    
4607              else
4608                {
4609                if (verbs[i].op_arg < 0)   /* Argument is forbidden */
4610                  {
4611                  *errorcodeptr = ERR59;
4612                  goto FAILED;
4613                  }
4614                *code++ = verbs[i].op_arg;
4615                *code++ = arglen;
4616                memcpy(code, arg, arglen);
4617                code += arglen;
4618                *code++ = 0;
4619                }
4620    
4621              break;  /* Found verb, exit loop */
4622            }            }
4623    
4624          vn += verbs[i].len + 1;          vn += verbs[i].len + 1;
4625          }          }
4626        if (i < verbcount) continue;  
4627        *errorcodeptr = ERR60;        if (i < verbcount) continue;    /* Successfully handled a verb */
4628          *errorcodeptr = ERR60;          /* Verb not recognized */
4629        goto FAILED;        goto FAILED;
4630        }        }
4631    
# Line 5144  we set the flag only if there is a liter Line 5267  we set the flag only if there is a liter
5267                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
5268                  goto FAILED;                  goto FAILED;
5269                  }                  }
5270    
5271                  /* Fudge the value of "called" so that when it is inserted as an
5272                  offset below, what it actually inserted is the reference number
5273                  of the group. */
5274    
5275                called = cd->start_code + recno;                called = cd->start_code + recno;
5276                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);                PUTINC(cd->hwm, 0, code + 2 + LINK_SIZE - cd->start_code);
5277                }                }
# Line 5153  we set the flag only if there is a liter Line 5281  we set the flag only if there is a liter
5281              recursion that could loop for ever, and diagnose that case. */              recursion that could loop for ever, and diagnose that case. */
5282    
5283              else if (GET(called, 1) == 0 &&              else if (GET(called, 1) == 0 &&
5284                       could_be_empty(called, code, bcptr, utf8))                       could_be_empty(called, code, bcptr, utf8, cd))
5285                {                {
5286                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
5287                goto FAILED;                goto FAILED;
# Line 5280  we set the flag only if there is a liter Line 5408  we set the flag only if there is a liter
5408          }     /* End of switch for character following (? */          }     /* End of switch for character following (? */
5409        }       /* End of (? handling */        }       /* End of (? handling */
5410    
5411      /* Opening parenthesis not followed by '?'. If PCRE_NO_AUTO_CAPTURE is set,      /* Opening parenthesis not followed by '*' or '?'. If PCRE_NO_AUTO_CAPTURE
5412      all unadorned brackets become non-capturing and behave like (?:...)      is set, all unadorned brackets become non-capturing and behave like (?:...)
5413      brackets. */      brackets. */
5414    
5415      else if ((options & PCRE_NO_AUTO_CAPTURE) != 0)      else if ((options & PCRE_NO_AUTO_CAPTURE) != 0)
# Line 5585  we set the flag only if there is a liter Line 5713  we set the flag only if there is a liter
5713    
5714        if (-c >= ESC_REF)        if (-c >= ESC_REF)
5715          {          {
5716            open_capitem *oc;
5717          recno = -c - ESC_REF;          recno = -c - ESC_REF;
5718    
5719          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:    /* Come here from named backref handling */
# Line 5594  we set the flag only if there is a liter Line 5723  we set the flag only if there is a liter
5723          PUT2INC(code, 0, recno);          PUT2INC(code, 0, recno);
5724          cd->backref_map |= (recno < 32)? (1 << recno) : 1;          cd->backref_map |= (recno < 32)? (1 << recno) : 1;
5725          if (recno > cd->top_backref) cd->top_backref = recno;          if (recno > cd->top_backref) cd->top_backref = recno;
5726    
5727            /* Check to see if this back reference is recursive, that it, it
5728            is inside the group that it references. A flag is set so that the
5729            group can be made atomic. */
5730    
5731            for (oc = cd->open_caps; oc != NULL; oc = oc->next)
5732              {
5733              if (oc->number == recno)
5734                {
5735                oc->flag = TRUE;
5736                break;
5737                }
5738              }
5739          }          }
5740    
5741        /* So are Unicode property matches, if supported. */        /* So are Unicode property matches, if supported. */
# Line 5787  int old_external_options = cd->external_ Line 5929  int old_external_options = cd->external_
5929  branch_chain bc;  branch_chain bc;
5930    
5931  bc.outer = bcptr;  bc.outer = bcptr;
5932  bc.current = code;  bc.current_branch = code;
5933    
5934  firstbyte = reqbyte = REQ_UNSET;  firstbyte = reqbyte = REQ_UNSET;
5935    
# Line 5806  them global. It tests the value of lengt Line 5948  them global. It tests the value of lengt
5948  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. */
5949    
5950  /* If this is a capturing subpattern, add to the chain of open capturing items  /* If this is a capturing subpattern, add to the chain of open capturing items
5951  so that we can detect them if (*ACCEPT) is encountered. */  so that we can detect them if (*ACCEPT) is encountered. This is also used to
5952    detect groups that contain recursive back references to themselves. */
5953    
5954  if (*code == OP_CBRA)  if (*code == OP_CBRA)
5955    {    {
5956    capnumber = GET2(code, 1 + LINK_SIZE);    capnumber = GET2(code, 1 + LINK_SIZE);
5957    capitem.number = capnumber;    capitem.number = capnumber;
5958    capitem.next = cd->open_caps;    capitem.next = cd->open_caps;
5959      capitem.flag = FALSE;
5960    cd->open_caps = &capitem;    cd->open_caps = &capitem;
5961    }    }
5962    
# Line 5969  for (;;) Line 6113  for (;;)
6113        while (branch_length > 0);        while (branch_length > 0);
6114        }        }
6115    
     /* If it was a capturing subpattern, remove it from the chain. */  
   
     if (capnumber > 0) cd->open_caps = cd->open_caps->next;  
   
6116      /* Fill in the ket */      /* Fill in the ket */
6117    
6118      *code = OP_KET;      *code = OP_KET;
6119      PUT(code, 1, code - start_bracket);      PUT(code, 1, code - start_bracket);
6120      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6121    
6122        /* If it was a capturing subpattern, check to see if it contained any
6123        recursive back references. If so, we must wrap it in atomic brackets.
6124        In any event, remove the block from the chain. */
6125    
6126        if (capnumber > 0)
6127          {
6128          if (cd->open_caps->flag)
6129            {
6130            memmove(start_bracket + 1 + LINK_SIZE, start_bracket,
6131              code - start_bracket);
6132            *start_bracket = OP_ONCE;
6133            code += 1 + LINK_SIZE;
6134            PUT(start_bracket, 1, code - start_bracket);
6135            *code = OP_KET;
6136            PUT(code, 1, code - start_bracket);
6137            code += 1 + LINK_SIZE;
6138            length += 2 + 2*LINK_SIZE;
6139            }
6140          cd->open_caps = cd->open_caps->next;
6141          }
6142    
6143      /* Reset options if needed. */      /* Reset options if needed. */
6144    
6145      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)      if ((options & PCRE_IMS) != oldims && *ptr == CHAR_RIGHT_PARENTHESIS)
# Line 6028  for (;;) Line 6189  for (;;)
6189      {      {
6190      *code = OP_ALT;      *code = OP_ALT;
6191      PUT(code, 1, code - last_branch);      PUT(code, 1, code - last_branch);
6192      bc.current = last_branch = code;      bc.current_branch = last_branch = code;
6193      code += 1 + LINK_SIZE;      code += 1 + LINK_SIZE;
6194      }      }
6195    
# Line 6444  while (ptr[skipatstart] == CHAR_LEFT_PAR Line 6605  while (ptr[skipatstart] == CHAR_LEFT_PAR
6605    
6606  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
6607  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0 &&
6608       (*erroroffset = _pcre_valid_utf8((uschar *)pattern, -1)) >= 0)       (*erroroffset = _pcre_valid_utf8((USPTR)pattern, -1)) >= 0)
6609    {    {
6610    errorcode = ERR44;    errorcode = ERR44;
6611    goto PCRE_EARLY_ERROR_RETURN2;    goto PCRE_EARLY_ERROR_RETURN2;
# Line 6641  if debugging, leave the test till after Line 6802  if debugging, leave the test till after
6802    
6803  *code++ = OP_END;  *code++ = OP_END;
6804    
6805  #ifndef DEBUG  #ifndef PCRE_DEBUG
6806  if (code - codestart > length) errorcode = ERR23;  if (code - codestart > length) errorcode = ERR23;
6807  #endif  #endif
6808    
# Line 6765  if (reqbyte >= 0 && Line 6926  if (reqbyte >= 0 &&
6926  /* 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
6927  case when building a production library. */  case when building a production library. */
6928    
6929  #ifdef DEBUG  #ifdef PCRE_DEBUG
   
6930  printf("Length = %d top_bracket = %d top_backref = %d\n",  printf("Length = %d top_bracket = %d top_backref = %d\n",
6931    length, re->top_bracket, re->top_backref);    length, re->top_bracket, re->top_backref);
6932    
# Line 6803  if (code - codestart > length) Line 6963  if (code - codestart > length)
6963    if (errorcodeptr != NULL) *errorcodeptr = ERR23;    if (errorcodeptr != NULL) *errorcodeptr = ERR23;
6964    return NULL;    return NULL;
6965    }    }
6966  #endif   /* DEBUG */  #endif   /* PCRE_DEBUG */
6967    
6968  return (pcre *)re;  return (pcre *)re;
6969  }  }

Legend:
Removed from v.472  
changed lines
  Added in v.513

  ViewVC Help
Powered by ViewVC 1.1.5