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

Diff of /code/trunk/pcre_study.c

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

revision 1522 by ph10, Sun Feb 8 17:02:05 2015 UTC revision 1547 by ph10, Mon Apr 13 09:31:55 2015 UTC
# Line 70  Arguments: Line 70  Arguments:
70    code            pointer to start of group (the bracket)    code            pointer to start of group (the bracket)
71    startcode       pointer to start of the whole pattern's code    startcode       pointer to start of the whole pattern's code
72    options         the compiling options    options         the compiling options
73    int             RECURSE depth    recurses        chain of recurse_check to catch mutual recursion
74    
75  Returns:   the minimum length  Returns:   the minimum length
76             -1 if \C in UTF-8 mode or (*ACCEPT) was encountered             -1 if \C in UTF-8 mode or (*ACCEPT) was encountered
# Line 80  Returns:   the minimum length Line 80  Returns:   the minimum length
80    
81  static int  static int
82  find_minlength(const REAL_PCRE *re, const pcre_uchar *code,  find_minlength(const REAL_PCRE *re, const pcre_uchar *code,
83    const pcre_uchar *startcode, int options, int recurse_depth)    const pcre_uchar *startcode, int options, recurse_check *recurses)
84  {  {
85  int length = -1;  int length = -1;
86  /* PCRE_UTF16 has the same value as PCRE_UTF8. */  /* PCRE_UTF16 has the same value as PCRE_UTF8. */
87  BOOL utf = (options & PCRE_UTF8) != 0;  BOOL utf = (options & PCRE_UTF8) != 0;
88  BOOL had_recurse = FALSE;  BOOL had_recurse = FALSE;
89    recurse_check this_recurse;
90  register int branchlength = 0;  register int branchlength = 0;
91  register pcre_uchar *cc = (pcre_uchar *)code + 1 + LINK_SIZE;  register pcre_uchar *cc = (pcre_uchar *)code + 1 + LINK_SIZE;
92    
# Line 130  for (;;) Line 131  for (;;)
131      case OP_SBRAPOS:      case OP_SBRAPOS:
132      case OP_ONCE:      case OP_ONCE:
133      case OP_ONCE_NC:      case OP_ONCE_NC:
134      d = find_minlength(re, cc, startcode, options, recurse_depth);      d = find_minlength(re, cc, startcode, options, recurses);
135      if (d < 0) return d;      if (d < 0) return d;
136      branchlength += d;      branchlength += d;
137      do cc += GET(cc, 1); while (*cc == OP_ALT);      do cc += GET(cc, 1); while (*cc == OP_ALT);
# Line 393  for (;;) Line 394  for (;;)
394          ce = cs = (pcre_uchar *)PRIV(find_bracket)(startcode, utf, GET2(slot, 0));          ce = cs = (pcre_uchar *)PRIV(find_bracket)(startcode, utf, GET2(slot, 0));
395          if (cs == NULL) return -2;          if (cs == NULL) return -2;
396          do ce += GET(ce, 1); while (*ce == OP_ALT);          do ce += GET(ce, 1); while (*ce == OP_ALT);
397          if ((cc > cs && cc < ce) || recurse_depth > 10)          if (cc > cs && cc < ce)     /* Simple recursion */
398            {            {
399            d = 0;            d = 0;
400            had_recurse = TRUE;            had_recurse = TRUE;
401            break;            break;
402            }            }
403          else          else
404            {            {
405            int dd = find_minlength(re, cs, startcode, options, recurse_depth+1);            recurse_check *r = recurses;
406            if (dd < d) d = dd;            for (r = recurses; r != NULL; r = r->prev) if (r->group == cs) break;
407            }            if (r != NULL)           /* Mutual recursion */
408                {
409                d = 0;
410                had_recurse = TRUE;
411                break;
412                }
413              else
414                {
415                int dd;
416                this_recurse.prev = recurses;
417                this_recurse.group = cs;
418                dd = find_minlength(re, cs, startcode, options, &this_recurse);
419                if (dd < d) d = dd;
420                }
421              }
422          slot += re->name_entry_size;          slot += re->name_entry_size;
423          }          }
424        }        }
# Line 418  for (;;) Line 433  for (;;)
433        ce = cs = (pcre_uchar *)PRIV(find_bracket)(startcode, utf, GET2(cc, 1));        ce = cs = (pcre_uchar *)PRIV(find_bracket)(startcode, utf, GET2(cc, 1));
434        if (cs == NULL) return -2;        if (cs == NULL) return -2;
435        do ce += GET(ce, 1); while (*ce == OP_ALT);        do ce += GET(ce, 1); while (*ce == OP_ALT);
436        if ((cc > cs && cc < ce) || recurse_depth > 10)        if (cc > cs && cc < ce)    /* Simple recursion */
437          {          {
438          d = 0;          d = 0;
439          had_recurse = TRUE;          had_recurse = TRUE;
440          }          }
441        else        else
442          {          {
443          d = find_minlength(re, cs, startcode, options, recurse_depth + 1);          recurse_check *r = recurses;
444            for (r = recurses; r != NULL; r = r->prev) if (r->group == cs) break;
445            if (r != NULL)           /* Mutual recursion */
446              {
447              d = 0;
448              had_recurse = TRUE;
449              }
450            else
451              {
452              this_recurse.prev = recurses;
453              this_recurse.group = cs;
454              d = find_minlength(re, cs, startcode, options, &this_recurse);
455              }
456          }          }
457        }        }
458      else d = 0;      else d = 0;
# Line 474  for (;;) Line 501  for (;;)
501      case OP_RECURSE:      case OP_RECURSE:
502      cs = ce = (pcre_uchar *)startcode + GET(cc, 1);      cs = ce = (pcre_uchar *)startcode + GET(cc, 1);
503      do ce += GET(ce, 1); while (*ce == OP_ALT);      do ce += GET(ce, 1); while (*ce == OP_ALT);
504      if ((cc > cs && cc < ce) || recurse_depth > 10)      if (cc > cs && cc < ce)    /* Simple recursion */
505        had_recurse = TRUE;        had_recurse = TRUE;
506      else      else
507        {        {
508        branchlength += find_minlength(re, cs, startcode, options,        recurse_check *r = recurses;
509          recurse_depth + 1);        for (r = recurses; r != NULL; r = r->prev) if (r->group == cs) break;
510          if (r != NULL)           /* Mutual recursion */
511            had_recurse = TRUE;
512          else
513            {
514            this_recurse.prev = recurses;
515            this_recurse.group = cs;
516            branchlength += find_minlength(re, cs, startcode, options,
517              &this_recurse);
518            }
519        }        }
520      cc += 1 + LINK_SIZE;      cc += 1 + LINK_SIZE;
521      break;      break;
# Line 1503  if ((re->options & PCRE_ANCHORED) == 0 & Line 1539  if ((re->options & PCRE_ANCHORED) == 0 &
1539    
1540  /* Find the minimum length of subject string. */  /* Find the minimum length of subject string. */
1541    
1542  switch(min = find_minlength(re, code, code, re->options, 0))  switch(min = find_minlength(re, code, code, re->options, NULL))
1543    {    {
1544    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;    case -2: *errorptr = "internal error: missing capturing bracket"; return NULL;
1545    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;    case -3: *errorptr = "internal error: opcode not recognized"; return NULL;

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

  ViewVC Help
Powered by ViewVC 1.1.5