/[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 1538 by ph10, Sun Mar 29 11:22:24 2015 UTC revision 1547 by ph10, Mon Apr 13 09:31:55 2015 UTC
# Line 1704  Arguments: Line 1704  Arguments:
1704    utf      TRUE in UTF-8 / UTF-16 / UTF-32 mode    utf      TRUE in UTF-8 / UTF-16 / UTF-32 mode
1705    atend    TRUE if called when the pattern is complete    atend    TRUE if called when the pattern is complete
1706    cd       the "compile data" structure    cd       the "compile data" structure
1707      recurses    chain of recurse_check to catch mutual recursion
1708    
1709  Returns:   the fixed length,  Returns:   the fixed length,
1710               or -1 if there is no fixed length,               or -1 if there is no fixed length,
# Line 1713  Returns:   the fixed length, Line 1714  Returns:   the fixed length,
1714  */  */
1715    
1716  static int  static int
1717  find_fixedlength(pcre_uchar *code, BOOL utf, BOOL atend, compile_data *cd)  find_fixedlength(pcre_uchar *code, BOOL utf, BOOL atend, compile_data *cd,
1718      recurse_check *recurses)
1719  {  {
1720  int length = -1;  int length = -1;
1721    recurse_check this_recurse;
1722  register int branchlength = 0;  register int branchlength = 0;
1723  register pcre_uchar *cc = code + 1 + LINK_SIZE;  register pcre_uchar *cc = code + 1 + LINK_SIZE;
1724    
# Line 1741  for (;;) Line 1743  for (;;)
1743      case OP_ONCE:      case OP_ONCE:
1744      case OP_ONCE_NC:      case OP_ONCE_NC:
1745      case OP_COND:      case OP_COND:
1746      d = find_fixedlength(cc + ((op == OP_CBRA)? IMM2_SIZE : 0), utf, atend, cd);      d = find_fixedlength(cc + ((op == OP_CBRA)? IMM2_SIZE : 0), utf, atend, cd,
1747          recurses);
1748      if (d < 0) return d;      if (d < 0) return d;
1749      branchlength += d;      branchlength += d;
1750      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 1775  for (;;) Line 1778  for (;;)
1778      cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */      cs = ce = (pcre_uchar *)cd->start_code + GET(cc, 1);  /* Start subpattern */
1779      do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */      do ce += GET(ce, 1); while (*ce == OP_ALT);           /* End subpattern */
1780      if (cc > cs && cc < ce) return -1;                    /* Recursion */      if (cc > cs && cc < ce) return -1;                    /* Recursion */
1781      d = find_fixedlength(cs + IMM2_SIZE, utf, atend, cd);      else   /* Check for mutual recursion */
1782          {
1783          recurse_check *r = recurses;
1784          for (r = recurses; r != NULL; r = r->prev) if (r->group == cs) break;
1785          if (r != NULL) return -1;   /* Mutual recursion */
1786          }
1787        this_recurse.prev = recurses;
1788        this_recurse.group = cs;
1789        d = find_fixedlength(cs + IMM2_SIZE, utf, atend, cd, &this_recurse);
1790      if (d < 0) return d;      if (d < 0) return d;
1791      branchlength += d;      branchlength += d;
1792      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
# Line 2362  Arguments: Line 2373  Arguments:
2373  Returns:      TRUE if what is matched could be empty  Returns:      TRUE if what is matched could be empty
2374  */  */
2375    
 typedef struct recurse_check {  
   struct recurse_check *prev;  
   const pcre_uchar *group;  
 } recurse_check;  
   
2376  static BOOL  static BOOL
2377  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,  could_be_empty_branch(const pcre_uchar *code, const pcre_uchar *endcode,
2378    BOOL utf, compile_data *cd, recurse_check *recurses)    BOOL utf, compile_data *cd, recurse_check *recurses)
# Line 2497  for (code = first_significant_code(code Line 2503  for (code = first_significant_code(code
2503        empty_branch = FALSE;        empty_branch = FALSE;
2504        do        do
2505          {          {
2506          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd,          if (!empty_branch && could_be_empty_branch(code, endcode, utf, cd,
2507            recurses)) empty_branch = TRUE;            recurses)) empty_branch = TRUE;
2508          code += GET(code, 1);          code += GET(code, 1);
2509          }          }
# Line 3658  for (;;) Line 3664  for (;;)
3664        get_chr_property_list(code, utf, cd->fcc, list) : NULL;        get_chr_property_list(code, utf, cd->fcc, list) : NULL;
3665      list[1] = c == OP_STAR || c == OP_PLUS || c == OP_QUERY || c == OP_UPTO;      list[1] = c == OP_STAR || c == OP_PLUS || c == OP_QUERY || c == OP_UPTO;
3666    
3667      rec_limit = 10000;      rec_limit = 1000;
3668      if (end != NULL && compare_opcodes(end, utf, cd, list, end, &rec_limit))      if (end != NULL && compare_opcodes(end, utf, cd, list, end, &rec_limit))
3669        {        {
3670        switch(c)        switch(c)
# Line 3715  for (;;) Line 3721  for (;;)
3721    
3722        list[1] = (c & 1) == 0;        list[1] = (c & 1) == 0;
3723    
3724        rec_limit = 10000;        rec_limit = 1000;
3725        if (compare_opcodes(end, utf, cd, list, end, &rec_limit))        if (compare_opcodes(end, utf, cd, list, end, &rec_limit))
3726          {          {
3727          switch (c)          switch (c)
# Line 5924  for (;; ptr++) Line 5930  for (;; ptr++)
5930        {        {
5931        register int i;        register int i;
5932        int len = (int)(code - previous);        int len = (int)(code - previous);
5933          size_t base_hwm_offset = save_hwm_offset;
5934        pcre_uchar *bralink = NULL;        pcre_uchar *bralink = NULL;
5935        pcre_uchar *brazeroptr = NULL;        pcre_uchar *brazeroptr = NULL;
5936    
# Line 6070  for (;; ptr++) Line 6077  for (;; ptr++)
6077    
6078                while (cd->hwm > cd->start_workspace + cd->workspace_size -                while (cd->hwm > cd->start_workspace + cd->workspace_size -
6079                       WORK_SIZE_SAFETY_MARGIN -                       WORK_SIZE_SAFETY_MARGIN -
6080                       (this_hwm_offset - save_hwm_offset))                       (this_hwm_offset - base_hwm_offset))
6081                  {                  {
6082                  *errorcodeptr = expand_workspace(cd);                  *errorcodeptr = expand_workspace(cd);
6083                  if (*errorcodeptr != 0) goto FAILED;                  if (*errorcodeptr != 0) goto FAILED;
6084                  }                  }
6085    
6086                for (hc = (pcre_uchar *)cd->start_workspace + save_hwm_offset;                for (hc = (pcre_uchar *)cd->start_workspace + base_hwm_offset;
6087                     hc < (pcre_uchar *)cd->start_workspace + this_hwm_offset;                     hc < (pcre_uchar *)cd->start_workspace + this_hwm_offset;
6088                     hc += LINK_SIZE)                     hc += LINK_SIZE)
6089                  {                  {
6090                  PUT(cd->hwm, 0, GET(hc, 0) + len);                  PUT(cd->hwm, 0, GET(hc, 0) + len);
6091                  cd->hwm += LINK_SIZE;                  cd->hwm += LINK_SIZE;
6092                  }                  }
6093                save_hwm_offset = this_hwm_offset;                base_hwm_offset = this_hwm_offset;
6094                code += len;                code += len;
6095                }                }
6096              }              }
# Line 6151  for (;; ptr++) Line 6158  for (;; ptr++)
6158    
6159            while (cd->hwm > cd->start_workspace + cd->workspace_size -            while (cd->hwm > cd->start_workspace + cd->workspace_size -
6160                   WORK_SIZE_SAFETY_MARGIN -                   WORK_SIZE_SAFETY_MARGIN -
6161                   (this_hwm_offset - save_hwm_offset))                   (this_hwm_offset - base_hwm_offset))
6162              {              {
6163              *errorcodeptr = expand_workspace(cd);              *errorcodeptr = expand_workspace(cd);
6164              if (*errorcodeptr != 0) goto FAILED;              if (*errorcodeptr != 0) goto FAILED;
6165              }              }
6166    
6167            for (hc = (pcre_uchar *)cd->start_workspace + save_hwm_offset;            for (hc = (pcre_uchar *)cd->start_workspace + base_hwm_offset;
6168                 hc < (pcre_uchar *)cd->start_workspace + this_hwm_offset;                 hc < (pcre_uchar *)cd->start_workspace + this_hwm_offset;
6169                 hc += LINK_SIZE)                 hc += LINK_SIZE)
6170              {              {
6171              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));              PUT(cd->hwm, 0, GET(hc, 0) + len + ((i != 0)? 2+LINK_SIZE : 1));
6172              cd->hwm += LINK_SIZE;              cd->hwm += LINK_SIZE;
6173              }              }
6174            save_hwm_offset = this_hwm_offset;            base_hwm_offset = this_hwm_offset;
6175            code += len;            code += len;
6176            }            }
6177    
# Line 6476  for (;; ptr++) Line 6483  for (;; ptr++)
6483    
6484      /* First deal with comments. Putting this code right at the start ensures      /* First deal with comments. Putting this code right at the start ensures
6485      that comments have no bad side effects. */      that comments have no bad side effects. */
6486    
6487      if (ptr[0] == CHAR_QUESTION_MARK && ptr[1] == CHAR_NUMBER_SIGN)      if (ptr[0] == CHAR_QUESTION_MARK && ptr[1] == CHAR_NUMBER_SIGN)
6488        {        {
6489        ptr += 2;        ptr += 2;
6490        while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;        while (*ptr != CHAR_NULL && *ptr != CHAR_RIGHT_PARENTHESIS) ptr++;
6491        if (*ptr == CHAR_NULL)        if (*ptr == CHAR_NULL)
6492          {          {
6493          *errorcodeptr = ERR18;          *errorcodeptr = ERR18;
6494          goto FAILED;          goto FAILED;
6495          }          }
6496        continue;        continue;
6497        }        }
6498    
6499      /* Now deal with various "verbs" that can be introduced by '*'. */      /* Now deal with various "verbs" that can be introduced by '*'. */
6500    
# Line 6679  for (;; ptr++) Line 6686  for (;; ptr++)
6686          if (tempptr[1] == CHAR_QUESTION_MARK &&          if (tempptr[1] == CHAR_QUESTION_MARK &&
6687                (tempptr[2] == CHAR_EQUALS_SIGN ||                (tempptr[2] == CHAR_EQUALS_SIGN ||
6688                 tempptr[2] == CHAR_EXCLAMATION_MARK ||                 tempptr[2] == CHAR_EXCLAMATION_MARK ||
6689                 tempptr[2] == CHAR_LESS_THAN_SIGN))                   (tempptr[2] == CHAR_LESS_THAN_SIGN &&
6690                       (tempptr[3] == CHAR_EQUALS_SIGN ||
6691                        tempptr[3] == CHAR_EXCLAMATION_MARK))))
6692            {            {
6693            cd->iscondassert = TRUE;            cd->iscondassert = TRUE;
6694            break;            break;
# Line 8288  for (;;) Line 8297  for (;;)
8297        int fixed_length;        int fixed_length;
8298        *code = OP_END;        *code = OP_END;
8299        fixed_length = find_fixedlength(last_branch,  (options & PCRE_UTF8) != 0,        fixed_length = find_fixedlength(last_branch,  (options & PCRE_UTF8) != 0,
8300          FALSE, cd);          FALSE, cd, NULL);
8301        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
8302        if (fixed_length == -3)        if (fixed_length == -3)
8303          {          {
# Line 9391  if (cd->check_lookbehind) Line 9400  if (cd->check_lookbehind)
9400        int end_op = *be;        int end_op = *be;
9401        *be = OP_END;        *be = OP_END;
9402        fixed_length = find_fixedlength(cc, (re->options & PCRE_UTF8) != 0, TRUE,        fixed_length = find_fixedlength(cc, (re->options & PCRE_UTF8) != 0, TRUE,
9403          cd);          cd, NULL);
9404        *be = end_op;        *be = end_op;
9405        DPRINTF(("fixed length = %d\n", fixed_length));        DPRINTF(("fixed length = %d\n", fixed_length));
9406        if (fixed_length < 0)        if (fixed_length < 0)

Legend:
Removed from v.1538  
changed lines
  Added in v.1547

  ViewVC Help
Powered by ViewVC 1.1.5