/[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 79 by nigel, Sat Feb 24 21:40:52 2007 UTC revision 85 by nigel, Sat Feb 24 21:41:13 2007 UTC
# Line 45  supporting internal functions that are n Line 45  supporting internal functions that are n
45  #include "pcre_internal.h"  #include "pcre_internal.h"
46    
47    
48    /* When DEBUG is defined, we need the pcre_printint() function, which is also
49    used by pcretest. DEBUG is not defined when building a production library. */
50    
51    #ifdef DEBUG
52    #include "pcre_printint.src"
53    #endif
54    
55    
56    
57  /*************************************************  /*************************************************
58  *      Code parameters and static tables         *  *      Code parameters and static tables         *
59  *************************************************/  *************************************************/
# Line 698  read_repeat_counts(const uschar *p, int Line 707  read_repeat_counts(const uschar *p, int
707  int min = 0;  int min = 0;
708  int max = -1;  int max = -1;
709    
710    /* Read the minimum value and do a paranoid check: a negative value indicates
711    an integer overflow. */
712    
713  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - '0';  while ((digitab[*p] & ctype_digit) != 0) min = min * 10 + *p++ - '0';
714    if (min < 0 || min > 65535)
715      {
716      *errorcodeptr = ERR5;
717      return p;
718      }
719    
720    /* Read the maximum value if there is one, and again do a paranoid on its size.
721    Also, max must not be less than min. */
722    
723  if (*p == '}') max = min; else  if (*p == '}') max = min; else
724    {    {
# Line 706  if (*p == '}') max = min; else Line 726  if (*p == '}') max = min; else
726      {      {
727      max = 0;      max = 0;
728      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - '0';      while((digitab[*p] & ctype_digit) != 0) max = max * 10 + *p++ - '0';
729        if (max < 0 || max > 65535)
730          {
731          *errorcodeptr = ERR5;
732          return p;
733          }
734      if (max < min)      if (max < min)
735        {        {
736        *errorcodeptr = ERR4;        *errorcodeptr = ERR4;
# Line 714  if (*p == '}') max = min; else Line 739  if (*p == '}') max = min; else
739      }      }
740    }    }
741    
742  /* Do paranoid checks, then fill in the required variables, and pass back the  /* Fill in the required variables, and pass back the pointer to the terminating
743  pointer to the terminating '}'. */  '}'. */
744    
745  if (min > 65535 || max > 65535)  *minp = min;
746    *errorcodeptr = ERR5;  *maxp = max;
 else  
   {  
   *minp = min;  
   *maxp = max;  
   }  
747  return p;  return p;
748  }  }
749    
# Line 3828  Returns:        pointer to compiled data Line 3848  Returns:        pointer to compiled data
3848                  with errorptr and erroroffset set                  with errorptr and erroroffset set
3849  */  */
3850    
3851  EXPORT pcre *  PCRE_EXPORT pcre *
3852  pcre_compile(const char *pattern, int options, const char **errorptr,  pcre_compile(const char *pattern, int options, const char **errorptr,
3853    int *erroroffset, const unsigned char *tables)    int *erroroffset, const unsigned char *tables)
3854  {  {
# Line 3836  return pcre_compile2(pattern, options, N Line 3856  return pcre_compile2(pattern, options, N
3856  }  }
3857    
3858    
3859  EXPORT pcre *  PCRE_EXPORT pcre *
3860  pcre_compile2(const char *pattern, int options, int *errorcodeptr,  pcre_compile2(const char *pattern, int options, int *errorcodeptr,
3861    const char **errorptr, int *erroroffset, const unsigned char *tables)    const char **errorptr, int *erroroffset, const unsigned char *tables)
3862  {  {
# Line 3856  BOOL utf8; Line 3876  BOOL utf8;
3876  BOOL class_utf8;  BOOL class_utf8;
3877  #endif  #endif
3878  BOOL inescq = FALSE;  BOOL inescq = FALSE;
3879    BOOL capturing;
3880  unsigned int brastackptr = 0;  unsigned int brastackptr = 0;
3881  size_t size;  size_t size;
3882  uschar *code;  uschar *code;
# Line 4410  while ((c = *(++ptr)) != 0) Line 4431  while ((c = *(++ptr)) != 0)
4431      case '(':      case '(':
4432      branch_newextra = 0;      branch_newextra = 0;
4433      bracket_length = 1 + LINK_SIZE;      bracket_length = 1 + LINK_SIZE;
4434        capturing = FALSE;
4435    
4436      /* Handle special forms of bracket, which all start (? */      /* Handle special forms of bracket, which all start (? */
4437    
# Line 4497  while ((c = *(++ptr)) != 0) Line 4519  while ((c = *(++ptr)) != 0)
4519    
4520          case 'P':          case 'P':
4521          ptr += 3;          ptr += 3;
4522    
4523            /* Handle the definition of a named subpattern */
4524    
4525          if (*ptr == '<')          if (*ptr == '<')
4526            {            {
4527            const uschar *p;    /* Don't amalgamate; some compilers */            const uschar *p;    /* Don't amalgamate; some compilers */
# Line 4509  while ((c = *(++ptr)) != 0) Line 4534  while ((c = *(++ptr)) != 0)
4534              }              }
4535            name_count++;            name_count++;
4536            if (ptr - p > max_name_size) max_name_size = (ptr - p);            if (ptr - p > max_name_size) max_name_size = (ptr - p);
4537              capturing = TRUE;   /* Named parentheses are always capturing */
4538            break;            break;
4539            }            }
4540    
4541            /* Handle back references and recursive calls to named subpatterns */
4542    
4543          if (*ptr == '=' || *ptr == '>')          if (*ptr == '=' || *ptr == '>')
4544            {            {
4545            while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0);            while ((compile_block.ctypes[*(++ptr)] & ctype_word) != 0);
# Line 4695  while ((c = *(++ptr)) != 0) Line 4723  while ((c = *(++ptr)) != 0)
4723            continue;            continue;
4724            }            }
4725    
4726          /* If options were terminated by ':' control comes here. Fall through          /* If options were terminated by ':' control comes here. This is a
4727          to handle the group below. */          non-capturing group with an options change. There is nothing more that
4728            needs to be done because "capturing" is already set FALSE by default;
4729            we can just fall through. */
4730    
4731          }          }
4732        }        }
4733    
4734      /* Extracting brackets must be counted so we can process escapes in a      /* Ordinary parentheses, not followed by '?', are capturing unless
4735      Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to      PCRE_NO_AUTO_CAPTURE is set. */
4736      need an additional 3 bytes of store per extracting bracket. However, if  
4737      PCRE_NO_AUTO)CAPTURE is set, unadorned brackets become non-capturing, so we      else capturing = (options & PCRE_NO_AUTO_CAPTURE) == 0;
4738      must leave the count alone (it will aways be zero). */  
4739        /* Capturing brackets must be counted so we can process escapes in a
4740        Perlish way. If the number exceeds EXTRACT_BASIC_MAX we are going to need
4741        an additional 3 bytes of memory per capturing bracket. */
4742    
4743      else if ((options & PCRE_NO_AUTO_CAPTURE) == 0)      if (capturing)
4744        {        {
4745        bracount++;        bracount++;
4746        if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;        if (bracount > EXTRACT_BASIC_MAX) bracket_length += 3;
# Line 4975  if (reqbyte >= 0 && Line 5009  if (reqbyte >= 0 &&
5009    re->options |= PCRE_REQCHSET;    re->options |= PCRE_REQCHSET;
5010    }    }
5011    
5012  /* Print out the compiled data for debugging */  /* Print out the compiled data if debugging is enabled. This is never the
5013    case when building a production library. */
5014    
5015  #ifdef DEBUG  #ifdef DEBUG
5016    
# Line 5013  if ((re->options & PCRE_REQCHSET) != 0) Line 5048  if ((re->options & PCRE_REQCHSET) != 0)
5048      else printf("Req char = \\x%02x%s\n", ch, caseless);      else printf("Req char = \\x%02x%s\n", ch, caseless);
5049    }    }
5050    
5051  _pcre_printint(re, stdout);  pcre_printint(re, stdout);
5052    
5053  /* This check is done here in the debugging case so that the code that  /* This check is done here in the debugging case so that the code that
5054  was compiled can be seen. */  was compiled can be seen. */

Legend:
Removed from v.79  
changed lines
  Added in v.85

  ViewVC Help
Powered by ViewVC 1.1.5