/[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 500 by ph10, Sat Mar 6 19:00:29 2010 UTC revision 503 by ph10, Sun Mar 7 17:35:52 2010 UTC
# Line 1785  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 1800  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 1820  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        const uschar *scode = cd->start_code + GET(code, 1);
1832        if (GET(scode, 1) == 0) return TRUE;    /* Unclosed */
1833        do
1834          {
1835          if (!could_be_empty_branch(scode, endcode, utf8, cd)) return FALSE;
1836          scode += GET(scode, 1);
1837          }
1838        while (*scode == OP_ALT);
1839        continue;
1840        }
1841    
1842    /* For other groups, scan the branches. */    /* For other groups, scan the branches. */
1843    
# Line 1839  for (code = first_significant_code(code Line 1857  for (code = first_significant_code(code
1857        empty_branch = FALSE;        empty_branch = FALSE;
1858        do        do
1859          {          {
1860          if (!empty_branch && could_be_empty_branch(code, endcode, utf8))          if (!empty_branch && could_be_empty_branch(code, endcode, utf8, cd))
1861            empty_branch = TRUE;            empty_branch = TRUE;
1862          code += GET(code, 1);          code += GET(code, 1);
1863          }          }
# Line 1973  for (code = first_significant_code(code Line 1991  for (code = first_significant_code(code
1991      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];      if (utf8 && code[3] >= 0xc0) code += _pcre_utf8_table4[code[3] & 0x3f];
1992      break;      break;
1993  #endif  #endif
1994    
1995        /* None of the remaining opcodes are required to match a character. */
1996    
1997        default:
1998        break;
1999      }      }
2000    }    }
2001    
# Line 1995  Arguments: Line 2018  Arguments:
2018    endcode     points to where to stop (current RECURSE item)    endcode     points to where to stop (current RECURSE item)
2019    bcptr       points to the chain of current (unclosed) branch starts    bcptr       points to the chain of current (unclosed) branch starts
2020    utf8        TRUE if in UTF-8 mode    utf8        TRUE if in UTF-8 mode
2021      cd          pointers to tables etc
2022    
2023  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2024  */  */
2025    
2026  static BOOL  static BOOL
2027  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,  could_be_empty(const uschar *code, const uschar *endcode, branch_chain *bcptr,
2028    BOOL utf8)    BOOL utf8, compile_data *cd)
2029  {  {
2030  while (bcptr != NULL && bcptr->current_branch >= code)  while (bcptr != NULL && bcptr->current_branch >= code)
2031    {    {
2032    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8))    if (!could_be_empty_branch(bcptr->current_branch, endcode, utf8, cd))
2033      return FALSE;      return FALSE;
2034    bcptr = bcptr->outer;    bcptr = bcptr->outer;
2035    }    }
# Line 4363  we set the flag only if there is a liter Line 4387  we set the flag only if there is a liter
4387            uschar *scode = bracode;            uschar *scode = bracode;
4388            do            do
4389              {              {
4390              if (could_be_empty_branch(scode, ketcode, utf8))              if (could_be_empty_branch(scode, ketcode, utf8, cd))
4391                {                {
4392                *bracode += OP_SBRA - OP_BRA;                *bracode += OP_SBRA - OP_BRA;
4393                break;                break;
# Line 5176  we set the flag only if there is a liter Line 5200  we set the flag only if there is a liter
5200              recursion that could loop for ever, and diagnose that case. */              recursion that could loop for ever, and diagnose that case. */
5201    
5202              else if (GET(called, 1) == 0 &&              else if (GET(called, 1) == 0 &&
5203                       could_be_empty(called, code, bcptr, utf8))                       could_be_empty(called, code, bcptr, utf8, cd))
5204                {                {
5205                *errorcodeptr = ERR40;                *errorcodeptr = ERR40;
5206                goto FAILED;                goto FAILED;

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

  ViewVC Help
Powered by ViewVC 1.1.5