/[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 1360 by ph10, Tue Sep 3 10:25:39 2013 UTC revision 1361 by ph10, Fri Sep 6 17:47:32 2013 UTC
# Line 1722  for (;;) Line 1722  for (;;)
1722      case OP_QUERYI:      case OP_QUERYI:
1723      case OP_REF:      case OP_REF:
1724      case OP_REFI:      case OP_REFI:
1725        case OP_DNREF:
1726        case OP_DNREFI:
1727      case OP_SBRA:      case OP_SBRA:
1728      case OP_SBRAPOS:      case OP_SBRAPOS:
1729      case OP_SCBRA:      case OP_SCBRA:
# Line 4826  for (;; ptr++) Line 4828  for (;; ptr++)
4828      /* If previous was a character class or a back reference, we put the repeat      /* If previous was a character class or a back reference, we put the repeat
4829      stuff after it, but just skip the item if the repeat was {0,0}. */      stuff after it, but just skip the item if the repeat was {0,0}. */
4830    
4831      else if (*previous == OP_CLASS ||      else if (*previous == OP_CLASS || *previous == OP_NCLASS ||
              *previous == OP_NCLASS ||  
4832  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
4833               *previous == OP_XCLASS ||               *previous == OP_XCLASS ||
4834  #endif  #endif
4835               *previous == OP_REF ||               *previous == OP_REF   || *previous == OP_REFI ||
4836               *previous == OP_REFI)               *previous == OP_DNREF || *previous == OP_DNREFI)
4837        {        {
4838        if (repeat_max == 0)        if (repeat_max == 0)
4839          {          {
# Line 5886  for (;; ptr++) Line 5887  for (;; ptr++)
5887                  {                  {
5888                  *errorcodeptr = ERR43;                  *errorcodeptr = ERR43;
5889                  goto FAILED;                  goto FAILED;
5890                  }                  }
5891                  cd->dupnames = TRUE;  /* Duplicate names exist */
5892                }                }
5893              else if (ng->number == number)              else if (ng->number == number)
5894                {                {
# Line 5987  for (;; ptr++) Line 5989  for (;; ptr++)
5989                break;                break;
5990              }              }
5991            recno = (i < cd->names_found)? ng->number : 0;            recno = (i < cd->names_found)? ng->number : 0;
5992    
5993              /* Count named back references. */
5994    
5995              if (!is_recurse) cd->namedrefcount++;
5996            }            }
5997    
5998          /* In the real compile, search the name table. We check the name          /* In the real compile, search the name table. We check the name
# Line 6016  for (;; ptr++) Line 6022  for (;; ptr++)
6022              }              }
6023            }            }
6024    
6025          /* In both phases, we can now go to the code than handles numerical          /* In both phases, for recursions, we can now go to the code than
6026          recursion or backreferences. */          handles numerical recursion. */
6027    
6028          if (is_recurse) goto HANDLE_RECURSION;          if (is_recurse) goto HANDLE_RECURSION;
6029            else goto HANDLE_REFERENCE;  
6030            /* In the second pass we must see if the name is duplicated. If so, we
6031            generate a different opcode. */
6032    
6033            if (lengthptr == NULL && cd->dupnames)
6034              {
6035              int count = 1;
6036              unsigned int index = i;
6037              pcre_uchar *cslot = slot + cd->name_entry_size;
6038    
6039              for (i++; i < cd->names_found; i++)
6040                {
6041                if (STRCMP_UC_UC(slot + IMM2_SIZE, cslot + IMM2_SIZE) != 0) break;
6042                count++;
6043                cslot += cd->name_entry_size;
6044                }
6045    
6046              if (count > 1)
6047                {
6048                if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6049                previous = code;
6050                *code++ = ((options & PCRE_CASELESS) != 0)? OP_DNREFI : OP_DNREF;
6051                PUT2INC(code, 0, index);
6052                PUT2INC(code, 0, count);
6053    
6054                /* Process each potentially referenced group. */
6055    
6056                for (; slot < cslot; slot += cd->name_entry_size)
6057                  {
6058                  open_capitem *oc;
6059                  recno = GET2(slot, 0);
6060                  cd->backref_map |= (recno < 32)? (1 << recno) : 1;
6061                  if (recno > cd->top_backref) cd->top_backref = recno;
6062    
6063                  /* Check to see if this back reference is recursive, that it, it
6064                  is inside the group that it references. A flag is set so that the
6065                  group can be made atomic. */
6066    
6067                  for (oc = cd->open_caps; oc != NULL; oc = oc->next)
6068                    {
6069                    if (oc->number == recno)
6070                      {
6071                      oc->flag = TRUE;
6072                      break;
6073                      }
6074                    }
6075                  }
6076    
6077                continue;  /* End of back ref handling */
6078                }
6079              }
6080    
6081            /* First pass, or a non-duplicated name. */
6082    
6083            goto HANDLE_REFERENCE;
6084    
6085    
6086          /* ------------------------------------------------------------ */          /* ------------------------------------------------------------ */
6087          case CHAR_R:              /* Recursion */          case CHAR_R:              /* Recursion */
# Line 6602  for (;; ptr++) Line 6662  for (;; ptr++)
6662          {          {
6663          open_capitem *oc;          open_capitem *oc;
6664          recno = -escape;          recno = -escape;
6665    
6666            /* Come here from named backref handling when the reference is to a
6667            single group (i.e. not to a duplicated name. */
6668    
6669          HANDLE_REFERENCE:    /* Come here from named backref handling */          HANDLE_REFERENCE:
6670          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;          if (firstcharflags == REQ_UNSET) firstcharflags = REQ_NONE;
6671          previous = code;          previous = code;
6672          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;          *code++ = ((options & PCRE_CASELESS) != 0)? OP_REFI : OP_REF;
# Line 7872  cd->bracount = cd->final_bracount = 0; Line 7935  cd->bracount = cd->final_bracount = 0;
7935  cd->names_found = 0;  cd->names_found = 0;
7936  cd->name_entry_size = 0;  cd->name_entry_size = 0;
7937  cd->name_table = NULL;  cd->name_table = NULL;
7938    cd->dupnames = FALSE;
7939    cd->namedrefcount = 0;
7940  cd->start_code = cworkspace;  cd->start_code = cworkspace;
7941  cd->hwm = cworkspace;  cd->hwm = cworkspace;
7942  cd->start_workspace = cworkspace;  cd->start_workspace = cworkspace;
# Line 7909  if (length > MAX_PATTERN_SIZE) Line 7974  if (length > MAX_PATTERN_SIZE)
7974    goto PCRE_EARLY_ERROR_RETURN;    goto PCRE_EARLY_ERROR_RETURN;
7975    }    }
7976    
7977  /* Compute the size of data block needed and get it, either from malloc or  /* If there are groups with duplicate names and there are also references by
7978  externally provided function. Integer overflow should no longer be possible  name, we must allow for the possibility of named references to duplicated
7979  because nowadays we limit the maximum value of cd->names_found and  groups. These require an extra data item each. */
7980  cd->name_entry_size. */  
7981    if (cd->dupnames && cd->namedrefcount > 0)
7982      length += cd->namedrefcount * IMM2_SIZE * sizeof(pcre_uchar);
7983    
7984    /* Compute the size of the data block for storing the compiled pattern. Integer
7985    overflow should no longer be possible because nowadays we limit the maximum
7986    value of cd->names_found and cd->name_entry_size. */
7987    
7988    size = sizeof(REAL_PCRE) +
7989      (length + cd->names_found * cd->name_entry_size) * sizeof(pcre_uchar);
7990    
7991    /* Get the memory. */
7992    
 size = sizeof(REAL_PCRE) + (length + cd->names_found * cd->name_entry_size) * sizeof(pcre_uchar);  
7993  re = (REAL_PCRE *)(PUBL(malloc))(size);  re = (REAL_PCRE *)(PUBL(malloc))(size);
   
7994  if (re == NULL)  if (re == NULL)
7995    {    {
7996    errorcode = ERR21;    errorcode = ERR21;

Legend:
Removed from v.1360  
changed lines
  Added in v.1361

  ViewVC Help
Powered by ViewVC 1.1.5