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

Diff of /code/trunk/pcre_exec.c

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

revision 882 by ph10, Sun Jan 15 18:45:27 2012 UTC revision 922 by ph10, Mon Feb 20 18:44:42 2012 UTC
# Line 140  Arguments: Line 140  Arguments:
140    md          points to match data block    md          points to match data block
141    caseless    TRUE if caseless    caseless    TRUE if caseless
142    
143  Returns:      < 0 if not matched, otherwise the number of subject bytes matched  Returns:      >= 0 the number of subject bytes matched
144                  -1 no match
145                  -2 partial match; always given if at end subject
146  */  */
147    
148  static int  static int
# Line 163  pchars(p, length, FALSE, md); Line 165  pchars(p, length, FALSE, md);
165  printf("\n");  printf("\n");
166  #endif  #endif
167    
168  /* Always fail if reference not set (and not JavaScript compatible). */  /* Always fail if reference not set (and not JavaScript compatible - in that
169    case the length is passed as zero). */
170    
171  if (length < 0) return -1;  if (length < 0) return -1;
172    
# Line 189  if (caseless) Line 192  if (caseless)
192      while (p < endptr)      while (p < endptr)
193        {        {
194        int c, d;        int c, d;
195        if (eptr >= md->end_subject) return -1;        if (eptr >= md->end_subject) return -2;   /* Partial match */
196        GETCHARINC(c, eptr);        GETCHARINC(c, eptr);
197        GETCHARINC(d, p);        GETCHARINC(d, p);
198        if (c != d && c != UCD_OTHERCASE(d)) return -1;        if (c != d && c != UCD_OTHERCASE(d)) return -1;
# Line 202  if (caseless) Line 205  if (caseless)
205    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
206    is no UCP support. */    is no UCP support. */
207      {      {
     if (eptr + length > md->end_subject) return -1;  
208      while (length-- > 0)      while (length-- > 0)
209        {        {
210          if (eptr >= md->end_subject) return -2;   /* Partial match */
211        if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;        if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;
212        p++;        p++;
213        eptr++;        eptr++;
# Line 217  are in UTF-8 mode. */ Line 220  are in UTF-8 mode. */
220    
221  else  else
222    {    {
223    if (eptr + length > md->end_subject) return -1;    while (length-- > 0)
224    while (length-- > 0) if (*p++ != *eptr++) return -1;      {
225        if (eptr >= md->end_subject) return -2;   /* Partial match */
226        if (*p++ != *eptr++) return -1;
227        }
228    }    }
229    
230  return (int)(eptr - eptr_start);  return (int)(eptr - eptr_start);
# Line 332  argument of match(), which never changes Line 338  argument of match(), which never changes
338    {\    {\
339    heapframe *oldframe = frame;\    heapframe *oldframe = frame;\
340    frame = oldframe->Xprevframe;\    frame = oldframe->Xprevframe;\
341    (PUBL(stack_free))(oldframe);\    if (oldframe != &frame_zero) (PUBL(stack_free))(oldframe);\
342    if (frame != NULL)\    if (frame != NULL)\
343      {\      {\
344      rrc = ra;\      rrc = ra;\
# Line 485  BOOL caseless; Line 491  BOOL caseless;
491  int condcode;  int condcode;
492    
493  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
494  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame". We set up the top-level
495  heap storage. Set up the top-level frame here; others are obtained from the  frame on the stack here; subsequent instantiations are obtained from the heap
496  heap whenever RMATCH() does a "recursion". See the macro definitions above. */  whenever RMATCH() does a "recursion". See the macro definitions above. Putting
497    the top-level on the stack rather than malloc-ing them all gives a performance
498    boost in many cases where there is not much "recursion". */
499    
500  #ifdef NO_RECURSE  #ifdef NO_RECURSE
501  heapframe *frame = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));  heapframe frame_zero;
502  if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);  heapframe *frame = &frame_zero;
503  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
504    
505  /* Copy in the original argument variables */  /* Copy in the original argument variables */
# Line 613  int save_offset1, save_offset2, save_off Line 621  int save_offset1, save_offset2, save_off
621  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
622    
623  eptrblock newptrb;  eptrblock newptrb;
624    
625    /* There is a special fudge for calling match() in a way that causes it to
626    measure the size of its basic stack frame when the stack is being used for
627    recursion. The second argument (ecode) being NULL triggers this behaviour. It
628    cannot normally ever be NULL. The return is the negated value of the frame
629    size. */
630    
631    if (ecode == NULL)
632      {
633      if (rdepth == 0)
634        return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1);
635      else
636        {
637        int len = (char *)&rdepth - (char *)eptr;
638        return (len > 0)? -len : len;
639        }
640      }
641  #endif     /* NO_RECURSE */  #endif     /* NO_RECURSE */
642    
643  /* To save space on the stack and in the heap frame, I have doubled up on some  /* To save space on the stack and in the heap frame, I have doubled up on some
# Line 819  for (;;) Line 844  for (;;)
844      case OP_ONCE_NC:      case OP_ONCE_NC:
845      prev = ecode;      prev = ecode;
846      saved_eptr = eptr;      saved_eptr = eptr;
847      save_mark = md->mark;      save_mark = md->mark;
848      do      do
849        {        {
850        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
# Line 838  for (;;) Line 863  for (;;)
863    
864        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
865        ecode += GET(ecode,1);        ecode += GET(ecode,1);
866        md->mark = save_mark;        md->mark = save_mark;
867        }        }
868      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
869    
# Line 918  for (;;) Line 943  for (;;)
943        save_offset2 = md->offset_vector[offset+1];        save_offset2 = md->offset_vector[offset+1];
944        save_offset3 = md->offset_vector[md->offset_end - number];        save_offset3 = md->offset_vector[md->offset_end - number];
945        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
946        save_mark = md->mark;        save_mark = md->mark;
947    
948        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
949        md->offset_vector[md->offset_end - number] =        md->offset_vector[md->offset_end - number] =
# Line 1024  for (;;) Line 1049  for (;;)
1049        save_mark = md->mark;        save_mark = md->mark;
1050        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,
1051          RM2);          RM2);
1052    
1053        /* See comment in the code for capturing groups above about handling        /* See comment in the code for capturing groups above about handling
1054        THEN. */        THEN. */
1055    
# Line 1051  for (;;) Line 1076  for (;;)
1076          RRETURN(rrc);          RRETURN(rrc);
1077          }          }
1078        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1079        md->mark = save_mark;        md->mark = save_mark;
1080        if (*ecode != OP_ALT) break;        if (*ecode != OP_ALT) break;
1081        }        }
1082    
# Line 1530  for (;;) Line 1555  for (;;)
1555    
1556      case OP_ASSERT:      case OP_ASSERT:
1557      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1558        save_mark = md->mark;
1559      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1560        {        {
1561        condassert = TRUE;        condassert = TRUE;
# Line 1551  for (;;) Line 1577  for (;;)
1577    
1578        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1579        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1580          md->mark = save_mark;
1581        }        }
1582      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1583    
# Line 1574  for (;;) Line 1601  for (;;)
1601    
1602      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1603      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1604        save_mark = md->mark;
1605      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1606        {        {
1607        condassert = TRUE;        condassert = TRUE;
# Line 1584  for (;;) Line 1612  for (;;)
1612      do      do
1613        {        {
1614        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1615          md->mark = save_mark;
1616        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1617        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1618          {          {
# Line 2036  for (;;) Line 2065  for (;;)
2065    
2066      case OP_DOLLM:      case OP_DOLLM:
2067      if (eptr < md->end_subject)      if (eptr < md->end_subject)
2068        { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }        {
2069          if (!IS_NEWLINE(eptr))
2070            {
2071            if (md->partial != 0 &&
2072                eptr + 1 >= md->end_subject &&
2073                NLBLOCK->nltype == NLTYPE_FIXED &&
2074                NLBLOCK->nllen == 2 &&
2075                *eptr == NLBLOCK->nl[0])
2076              {
2077              md->hitend = TRUE;
2078              if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2079              }
2080            RRETURN(MATCH_NOMATCH);
2081            }
2082          }
2083      else      else
2084        {        {
2085        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
# Line 2068  for (;;) Line 2111  for (;;)
2111      ASSERT_NL_OR_EOS:      ASSERT_NL_OR_EOS:
2112      if (eptr < md->end_subject &&      if (eptr < md->end_subject &&
2113          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
2114          {
2115          if (md->partial != 0 &&
2116              eptr + 1 >= md->end_subject &&
2117              NLBLOCK->nltype == NLTYPE_FIXED &&
2118              NLBLOCK->nllen == 2 &&
2119              *eptr == NLBLOCK->nl[0])
2120            {
2121            md->hitend = TRUE;
2122            if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2123            }
2124        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2125          }
2126    
2127      /* Either at end of string or \n before end. */      /* Either at end of string or \n before end. */
2128    
# Line 2196  for (;;) Line 2250  for (;;)
2250        }        }
2251      break;      break;
2252    
2253      /* Match a single character type; inline for speed */      /* Match any single character type except newline; have to take care with
2254        CRLF newlines and partial matching. */
2255    
2256      case OP_ANY:      case OP_ANY:
2257      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
2258        if (md->partial != 0 &&
2259            eptr + 1 >= md->end_subject &&
2260            NLBLOCK->nltype == NLTYPE_FIXED &&
2261            NLBLOCK->nllen == 2 &&
2262            *eptr == NLBLOCK->nl[0])
2263          {
2264          md->hitend = TRUE;
2265          if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2266          }
2267    
2268      /* Fall through */      /* Fall through */
2269    
2270        /* Match any single character whatsoever. */
2271    
2272      case OP_ALLANY:      case OP_ALLANY:
2273      if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */      if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */
2274        {                            /* not be updated before SCHECK_PARTIAL. */        {                            /* not be updated before SCHECK_PARTIAL. */
# Line 2342  for (;;) Line 2409  for (;;)
2409        default: RRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2410    
2411        case 0x000d:        case 0x000d:
2412        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr >= md->end_subject)
2413            {
2414            SCHECK_PARTIAL();
2415            }
2416          else if (*eptr == 0x0a) eptr++;
2417        break;        break;
2418    
2419        case 0x000a:        case 0x000a:
# Line 2572  for (;;) Line 2643  for (;;)
2643        if (UCD_CATEGORY(c) != ucp_M) break;        if (UCD_CATEGORY(c) != ucp_M) break;
2644        eptr += len;        eptr += len;
2645        }        }
2646        CHECK_PARTIAL();
2647      ecode++;      ecode++;
2648      break;      break;
2649  #endif  #endif
# Line 2637  for (;;) Line 2709  for (;;)
2709        default:               /* No repeat follows */        default:               /* No repeat follows */
2710        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2711          {          {
2712            if (length == -2) eptr = md->end_subject;   /* Partial match */
2713          CHECK_PARTIAL();          CHECK_PARTIAL();
2714          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2715          }          }
# Line 2662  for (;;) Line 2735  for (;;)
2735        int slength;        int slength;
2736        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2737          {          {
2738            if (slength == -2) eptr = md->end_subject;   /* Partial match */
2739          CHECK_PARTIAL();          CHECK_PARTIAL();
2740          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2741          }          }
# Line 2685  for (;;) Line 2759  for (;;)
2759          if (fi >= max) RRETURN(MATCH_NOMATCH);          if (fi >= max) RRETURN(MATCH_NOMATCH);
2760          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2761            {            {
2762              if (slength == -2) eptr = md->end_subject;   /* Partial match */
2763            CHECK_PARTIAL();            CHECK_PARTIAL();
2764            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2765            }            }
# Line 2703  for (;;) Line 2778  for (;;)
2778          int slength;          int slength;
2779          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2780            {            {
2781            CHECK_PARTIAL();            /* Can't use CHECK_PARTIAL because we don't want to update eptr in
2782              the soft partial matching case. */
2783    
2784              if (slength == -2 && md->partial != 0 &&
2785                  md->end_subject > md->start_used_ptr)
2786                {
2787                md->hitend = TRUE;
2788                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2789                }
2790            break;            break;
2791            }            }
2792          eptr += slength;          eptr += slength;
2793          }          }
2794    
2795        while (eptr >= pp)        while (eptr >= pp)
2796          {          {
2797          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
# Line 3485  for (;;) Line 3569  for (;;)
3569      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3570      if (op == OP_NOTI)         /* The caseless case */      if (op == OP_NOTI)         /* The caseless case */
3571        {        {
3572        register int ch, och;        register unsigned int ch, och;
3573        ch = *ecode++;        ch = *ecode++;
3574  #ifdef COMPILE_PCRE8  #ifdef COMPILE_PCRE8
3575        /* ch must be < 128 if UTF is enabled. */        /* ch must be < 128 if UTF is enabled. */
# Line 3631  for (;;) Line 3715  for (;;)
3715              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3716              }              }
3717            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3718            if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);            if (fc == d || (unsigned int) foc == d) RRETURN(MATCH_NOMATCH);
3719            }            }
3720          }          }
3721        else        else
# Line 3669  for (;;) Line 3753  for (;;)
3753                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3754                }                }
3755              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3756              if (fc == d || foc == d) RRETURN(MATCH_NOMATCH);              if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
3757              }              }
3758            }            }
3759          else          else
# Line 3712  for (;;) Line 3796  for (;;)
3796                break;                break;
3797                }                }
3798              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3799              if (fc == d || foc == d) break;              if (fc == d || (unsigned int)foc == d) break;
3800              eptr += len;              eptr += len;
3801              }              }
3802          if (possessive) continue;            if (possessive) continue;
3803          for(;;)            for(;;)
3804              {              {
3805              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3806              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
# Line 4141  for (;;) Line 4225  for (;;)
4225              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4226              eptr += len;              eptr += len;
4227              }              }
4228              CHECK_PARTIAL();
4229            }            }
4230          }          }
4231    
# Line 4161  for (;;) Line 4246  for (;;)
4246              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4247              }              }
4248            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4249              if (md->partial != 0 &&
4250                  eptr + 1 >= md->end_subject &&
4251                  NLBLOCK->nltype == NLTYPE_FIXED &&
4252                  NLBLOCK->nllen == 2 &&
4253                  *eptr == NLBLOCK->nl[0])
4254                {
4255                md->hitend = TRUE;
4256                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4257                }
4258            eptr++;            eptr++;
4259            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4260            }            }
# Line 4445  for (;;) Line 4539  for (;;)
4539              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4540              }              }
4541            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4542              if (md->partial != 0 &&
4543                  eptr + 1 >= md->end_subject &&
4544                  NLBLOCK->nltype == NLTYPE_FIXED &&
4545                  NLBLOCK->nllen == 2 &&
4546                  *eptr == NLBLOCK->nl[0])
4547                {
4548                md->hitend = TRUE;
4549                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4550                }
4551            eptr++;            eptr++;
4552            }            }
4553          break;          break;
# Line 4925  for (;;) Line 5028  for (;;)
5028              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5029              eptr += len;              eptr += len;
5030              }              }
5031              CHECK_PARTIAL();
5032            }            }
5033          }          }
5034        else        else
# Line 4948  for (;;) Line 5052  for (;;)
5052            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
5053            switch(ctype)            switch(ctype)
5054              {              {
5055              case OP_ANY:        /* This is the non-NL case */              case OP_ANY:               /* This is the non-NL case */
5056                if (md->partial != 0 &&    /* Take care with CRLF partial */
5057                    eptr >= md->end_subject &&
5058                    NLBLOCK->nltype == NLTYPE_FIXED &&
5059                    NLBLOCK->nllen == 2 &&
5060                    c == NLBLOCK->nl[0])
5061                  {
5062                  md->hitend = TRUE;
5063                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5064                  }
5065                break;
5066    
5067              case OP_ALLANY:              case OP_ALLANY:
5068              case OP_ANYBYTE:              case OP_ANYBYTE:
5069              break;              break;
# Line 5111  for (;;) Line 5226  for (;;)
5226            c = *eptr++;            c = *eptr++;
5227            switch(ctype)            switch(ctype)
5228              {              {
5229              case OP_ANY:     /* This is the non-NL case */              case OP_ANY:               /* This is the non-NL case */
5230                if (md->partial != 0 &&    /* Take care with CRLF partial */
5231                    eptr >= md->end_subject &&
5232                    NLBLOCK->nltype == NLTYPE_FIXED &&
5233                    NLBLOCK->nllen == 2 &&
5234                    c == NLBLOCK->nl[0])
5235                  {
5236                  md->hitend = TRUE;
5237                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5238                  }
5239                break;
5240    
5241              case OP_ALLANY:              case OP_ALLANY:
5242              case OP_ANYBYTE:              case OP_ANYBYTE:
5243              break;              break;
# Line 5468  for (;;) Line 5594  for (;;)
5594              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
5595              eptr += len;              eptr += len;
5596              }              }
5597              CHECK_PARTIAL();
5598            }            }
5599    
5600          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
# Line 5511  for (;;) Line 5638  for (;;)
5638                  break;                  break;
5639                  }                  }
5640                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5641                  if (md->partial != 0 &&    /* Take care with CRLF partial */
5642                      eptr + 1 >= md->end_subject &&
5643                      NLBLOCK->nltype == NLTYPE_FIXED &&
5644                      NLBLOCK->nllen == 2 &&
5645                      *eptr == NLBLOCK->nl[0])
5646                    {
5647                    md->hitend = TRUE;
5648                    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5649                    }
5650                eptr++;                eptr++;
5651                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5652                }                }
# Line 5528  for (;;) Line 5664  for (;;)
5664                  break;                  break;
5665                  }                  }
5666                if (IS_NEWLINE(eptr)) break;                if (IS_NEWLINE(eptr)) break;
5667                  if (md->partial != 0 &&    /* Take care with CRLF partial */
5668                      eptr + 1 >= md->end_subject &&
5669                      NLBLOCK->nltype == NLTYPE_FIXED &&
5670                      NLBLOCK->nllen == 2 &&
5671                      *eptr == NLBLOCK->nl[0])
5672                    {
5673                    md->hitend = TRUE;
5674                    if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5675                    }
5676                eptr++;                eptr++;
5677                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);                ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
5678                }                }
# Line 5792  for (;;) Line 5937  for (;;)
5937                break;                break;
5938                }                }
5939              if (IS_NEWLINE(eptr)) break;              if (IS_NEWLINE(eptr)) break;
5940                if (md->partial != 0 &&    /* Take care with CRLF partial */
5941                    eptr + 1 >= md->end_subject &&
5942                    NLBLOCK->nltype == NLTYPE_FIXED &&
5943                    NLBLOCK->nllen == 2 &&
5944                    *eptr == NLBLOCK->nl[0])
5945                  {
5946                  md->hitend = TRUE;
5947                  if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
5948                  }
5949              eptr++;              eptr++;
5950              }              }
5951            break;            break;
# Line 6184  PCRE_PUCHAR req_char_ptr = start_match - Line 6338  PCRE_PUCHAR req_char_ptr = start_match -
6338  const pcre_study_data *study;  const pcre_study_data *study;
6339  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;  const REAL_PCRE *re = (const REAL_PCRE *)argument_re;
6340    
6341    /* Check for the special magic call that measures the size of the stack used
6342    per recursive call of match(). Without the funny casting for sizeof, a Windows
6343    compiler gave this error: "unary minus operator applied to unsigned type,
6344    result still unsigned". Hopefully the cast fixes that. */
6345    
6346    if (re == NULL && extra_data == NULL && subject == NULL && length == -999 &&
6347        start_offset == -999)
6348    #ifdef NO_RECURSE
6349      return -((int)sizeof(heapframe));
6350    #else
6351      return match(NULL, NULL, NULL, 0, NULL, NULL, 0);
6352    #endif
6353    
6354  /* Plausibility checks */  /* Plausibility checks */
6355    
6356  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;  if ((options & ~PUBLIC_EXEC_OPTIONS) != 0) return PCRE_ERROR_BADOPTION;
6357  if (re == NULL || subject == NULL ||  if (re == NULL || subject == NULL || (offsets == NULL && offsetcount > 0))
6358     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;    return PCRE_ERROR_NULL;
6359  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
6360  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;  if (start_offset < 0 || start_offset > length) return PCRE_ERROR_BADOFFSET;
6361    
6362    /* Check that the first field in the block is the magic number. If it is not,
6363    return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to
6364    REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which
6365    means that the pattern is likely compiled with different endianness. */
6366    
6367    if (re->magic_number != MAGIC_NUMBER)
6368      return re->magic_number == REVERSED_MAGIC_NUMBER?
6369        PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;
6370    if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
6371    
6372  /* These two settings are used in the code for checking a UTF-8 string that  /* These two settings are used in the code for checking a UTF-8 string that
6373  follows immediately afterwards. Other values in the md block are used only  follows immediately afterwards. Other values in the md block are used only
6374  during "normal" pcre_exec() processing, not when the JIT support is in use,  during "normal" pcre_exec() processing, not when the JIT support is in use,
# Line 6236  if (utf && (options & PCRE_NO_UTF8_CHECK Line 6413  if (utf && (options & PCRE_NO_UTF8_CHECK
6413  /* If the pattern was successfully studied with JIT support, run the JIT  /* If the pattern was successfully studied with JIT support, run the JIT
6414  executable instead of the rest of this function. Most options must be set at  executable instead of the rest of this function. Most options must be set at
6415  compile time for the JIT code to be usable. Fallback to the normal code path if  compile time for the JIT code to be usable. Fallback to the normal code path if
6416  an unsupported flag is set. In particular, JIT does not support partial  an unsupported flag is set. */
 matching. */  
6417    
6418  #ifdef SUPPORT_JIT  #ifdef SUPPORT_JIT
6419  if (extra_data != NULL  if (extra_data != NULL
6420      && (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0      && (extra_data->flags & (PCRE_EXTRA_EXECUTABLE_JIT |
6421                                 PCRE_EXTRA_TABLES)) == PCRE_EXTRA_EXECUTABLE_JIT
6422      && extra_data->executable_jit != NULL      && extra_data->executable_jit != NULL
     && (extra_data->flags & PCRE_EXTRA_TABLES) == 0  
6423      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |      && (options & ~(PCRE_NO_UTF8_CHECK | PCRE_NOTBOL | PCRE_NOTEOL |
6424                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART)) == 0)                      PCRE_NOTEMPTY | PCRE_NOTEMPTY_ATSTART |
6425    return PRIV(jit_exec)(re, extra_data->executable_jit,                      PCRE_PARTIAL_SOFT | PCRE_PARTIAL_HARD)) == 0)
6426      {
6427      rc = PRIV(jit_exec)(re, extra_data->executable_jit,
6428      (const pcre_uchar *)subject, length, start_offset, options,      (const pcre_uchar *)subject, length, start_offset, options,
6429      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)      ((extra_data->flags & PCRE_EXTRA_MATCH_LIMIT) == 0)
6430      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);      ? MATCH_LIMIT : extra_data->match_limit, offsets, offsetcount);
6431    
6432      /* PCRE_ERROR_NULL means that the selected normal or partial matching
6433      mode is not compiled. In this case we simply fallback to interpreter. */
6434    
6435      if (rc != PCRE_ERROR_NULL)     /* JIT was used */
6436        {
6437        ((pcre_extra *)extra_data)->flags |= PCRE_EXTRA_USED_JIT;
6438        return rc;
6439        }
6440      }
6441  #endif  #endif
6442    
6443  /* Carry on with non-JIT matching. This information is for finding all the  /* Carry on with non-JIT matching. This information is for finding all the
# Line 6283  if (extra_data != NULL) Line 6471  if (extra_data != NULL)
6471    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)    if ((flags & PCRE_EXTRA_CALLOUT_DATA) != 0)
6472      md->callout_data = extra_data->callout_data;      md->callout_data = extra_data->callout_data;
6473    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;    if ((flags & PCRE_EXTRA_TABLES) != 0) tables = extra_data->tables;
6474      ((pcre_extra *)extra_data)->flags &= ~PCRE_EXTRA_USED_JIT;   /* JIT not used */
6475    }    }
6476    
6477  /* If the exec call supplied NULL for tables, use the inbuilt ones. This  /* If the exec call supplied NULL for tables, use the inbuilt ones. This
# Line 6291  in other programs later. */ Line 6480  in other programs later. */
6480    
6481  if (tables == NULL) tables = PRIV(default_tables);  if (tables == NULL) tables = PRIV(default_tables);
6482    
 /* Check that the first field in the block is the magic number. If it is not,  
 return with PCRE_ERROR_BADMAGIC. However, if the magic number is equal to  
 REVERSED_MAGIC_NUMBER we return with PCRE_ERROR_BADENDIANNESS, which  
 means that the pattern is likely compiled with different endianness. */  
   
 if (re->magic_number != MAGIC_NUMBER)  
   return re->magic_number == REVERSED_MAGIC_NUMBER?  
     PCRE_ERROR_BADENDIANNESS:PCRE_ERROR_BADMAGIC;  
 if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;  
   
6483  /* Set up other data */  /* Set up other data */
6484    
6485  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
# Line 6462  if (!anchored) Line 6641  if (!anchored)
6641    if ((re->flags & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
6642      {      {
6643      has_first_char = TRUE;      has_first_char = TRUE;
6644      first_char = first_char2 = re->first_char;      first_char = first_char2 = (pcre_uchar)(re->first_char);
6645      if ((re->flags & PCRE_FCH_CASELESS) != 0)      if ((re->flags & PCRE_FCH_CASELESS) != 0)
6646        {        {
6647        first_char2 = TABLE_GET(first_char, md->fcc, first_char);        first_char2 = TABLE_GET(first_char, md->fcc, first_char);
# Line 6484  character" set. */ Line 6663  character" set. */
6663  if ((re->flags & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
6664    {    {
6665    has_req_char = TRUE;    has_req_char = TRUE;
6666    req_char = req_char2 = re->req_char;    req_char = req_char2 = (pcre_uchar)(re->req_char);
6667    if ((re->flags & PCRE_RCH_CASELESS) != 0)    if ((re->flags & PCRE_RCH_CASELESS) != 0)
6668      {      {
6669      req_char2 = TABLE_GET(req_char, md->fcc, req_char);      req_char2 = TABLE_GET(req_char, md->fcc, req_char);

Legend:
Removed from v.882  
changed lines
  Added in v.922

  ViewVC Help
Powered by ViewVC 1.1.5