/[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 227 by ph10, Tue Aug 21 15:00:15 2007 UTC revision 426 by ph10, Wed Aug 26 15:38:32 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 43  pattern matching using an NFA algorithm, Line 43  pattern matching using an NFA algorithm,
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
46  #include <config.h>  #include "config.h"
47  #endif  #endif
48    
49  #define NLBLOCK md             /* Block containing newline information */  #define NLBLOCK md             /* Block containing newline information */
# Line 158  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 296  typedef struct heapframe { Line 322  typedef struct heapframe {
322    
323    /* Function arguments that may change */    /* Function arguments that may change */
324    
325    const uschar *Xeptr;    USPTR Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327    const uschar *Xmstart;    USPTR Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 307  typedef struct heapframe { Line 333  typedef struct heapframe {
333    
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    USPTR Xcallpat;
337    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
338    const uschar *Xdata;    USPTR Xcharptr;
339    const uschar *Xnext;  #endif
340    const uschar *Xpp;    USPTR Xdata;
341    const uschar *Xprev;    USPTR Xnext;
342    const uschar *Xsaved_eptr;    USPTR Xpp;
343      USPTR Xprev;
344      USPTR Xsaved_eptr;
345    
346    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
347    
# Line 334  typedef struct heapframe { Line 362  typedef struct heapframe {
362    uschar Xocchars[8];    uschar Xocchars[8];
363  #endif  #endif
364    
365      int Xcodelink;
366    int Xctype;    int Xctype;
367    unsigned int Xfc;    unsigned int Xfc;
368    int Xfi;    int Xfi;
# Line 369  typedef struct heapframe { Line 398  typedef struct heapframe {
398    
399  /* This function is called recursively in many circumstances. Whenever it  /* This function is called recursively in many circumstances. Whenever it
400  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
401  same response.  same response. */
402    
403    /* These macros pack up tests that are used for partial matching, and which
404    appears several times in the code. We set the "hit end" flag if the pointer is
405    at the end of the subject and also past the start of the subject (i.e.
406    something has been matched). The second one is used when we already know we are
407    past the end of the subject. */
408    
409    #define CHECK_PARTIAL()\
410      if (md->partial && eptr >= md->end_subject && eptr > mstart)\
411        md->hitend = TRUE
412    
413    #define SCHECK_PARTIAL()\
414      if (md->partial && eptr > mstart) md->hitend = TRUE
415    
416  Performance note: It might be tempting to extract commonly used fields from the  /* Performance note: It might be tempting to extract commonly used fields from
417  md structure (e.g. utf8, end_subject) into individual variables to improve  the md structure (e.g. utf8, end_subject) into individual variables to improve
418  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
419  made performance worse.  made performance worse.
420    
# Line 399  Returns:       MATCH_MATCH if matched Line 441  Returns:       MATCH_MATCH if matched
441  */  */
442    
443  static int  static int
444  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
445    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
446    int flags, unsigned int rdepth)    int flags, unsigned int rdepth)
447  {  {
# Line 413  register unsigned int c;   /* Character Line 455  register unsigned int c;   /* Character
455  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
456    
457  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
458    int condcode;
459    
460  /* 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
461  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
# Line 455  HEAP_RECURSE: Line 498  HEAP_RECURSE:
498  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
499  #endif  #endif
500  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
501    #define codelink           frame->Xcodelink
502  #define data               frame->Xdata  #define data               frame->Xdata
503  #define next               frame->Xnext  #define next               frame->Xnext
504  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 535  int oclength; Line 579  int oclength;
579  uschar occhars[8];  uschar occhars[8];
580  #endif  #endif
581    
582    int codelink;
583  int ctype;  int ctype;
584  int length;  int length;
585  int max;  int max;
# Line 611  for (;;) Line 656  for (;;)
656    op = *ecode;    op = *ecode;
657    
658    /* For partial matching, remember if we ever hit the end of the subject after    /* For partial matching, remember if we ever hit the end of the subject after
659    matching at least one subject character. */    matching at least one subject character. This code is now wrapped in a macro
660      because it appears several times below. */
661    
662    if (md->partial &&    CHECK_PARTIAL();
       eptr >= md->end_subject &&  
       eptr > mstart)  
     md->hitend = TRUE;  
663    
664    switch(op)    switch(op)
665      {      {
# Line 761  for (;;) Line 804  for (;;)
804    
805      case OP_COND:      case OP_COND:
806      case OP_SCOND:      case OP_SCOND:
807      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
808    
809        /* Because of the way auto-callout works during compile, a callout item is
810        inserted between OP_COND and an assertion condition. */
811    
812        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
813          {
814          if (pcre_callout != NULL)
815            {
816            pcre_callout_block cb;
817            cb.version          = 1;   /* Version 1 of the callout block */
818            cb.callout_number   = ecode[LINK_SIZE+2];
819            cb.offset_vector    = md->offset_vector;
820            cb.subject          = (PCRE_SPTR)md->start_subject;
821            cb.subject_length   = md->end_subject - md->start_subject;
822            cb.start_match      = mstart - md->start_subject;
823            cb.current_position = eptr - md->start_subject;
824            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
825            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
826            cb.capture_top      = offset_top/2;
827            cb.capture_last     = md->capture_last;
828            cb.callout_data     = md->callout_data;
829            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
830            if (rrc < 0) RRETURN(rrc);
831            }
832          ecode += _pcre_OP_lengths[OP_CALLOUT];
833          }
834    
835        condcode = ecode[LINK_SIZE+1];
836    
837        /* Now see what the actual condition is */
838    
839        if (condcode == OP_RREF)         /* Recursion test */
840        {        {
841        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
842        condition = md->recursive != NULL &&        condition = md->recursive != NULL &&
# Line 769  for (;;) Line 844  for (;;)
844        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
845        }        }
846    
847      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF)    /* Group used test */
848        {        {
849        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
850        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
851        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
852        }        }
853    
854      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
855        {        {
856        condition = FALSE;        condition = FALSE;
857        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 803  for (;;) Line 878  for (;;)
878        else        else
879          {          {
880          condition = FALSE;          condition = FALSE;
881          ecode += GET(ecode, 1);          ecode += codelink;
882          }          }
883        }        }
884    
# Line 826  for (;;) Line 901  for (;;)
901          goto TAIL_RECURSE;          goto TAIL_RECURSE;
902          }          }
903        }        }
904      else                         /* Condition false & no 2nd alternative */      else                         /* Condition false & no alternative */
905        {        {
906        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
907        }        }
# Line 1049  for (;;) Line 1124  for (;;)
1124          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1125            {            {
1126            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1127              if (new_recursive.offset_save != stacksave)
1128                (pcre_free)(new_recursive.offset_save);
1129            RRETURN(rrc);            RRETURN(rrc);
1130            }            }
1131    
# Line 1148  for (;;) Line 1225  for (;;)
1225      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1226      break;      break;
1227    
1228      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1229      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1230      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1231      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1232      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1233    
1234      case OP_BRAZERO:      case OP_BRAZERO:
1235        {        {
# Line 1174  for (;;) Line 1251  for (;;)
1251        }        }
1252      break;      break;
1253    
1254        case OP_SKIPZERO:
1255          {
1256          next = ecode+1;
1257          do next += GET(next,1); while (*next == OP_ALT);
1258          ecode = next + 1 + LINK_SIZE;
1259          }
1260        break;
1261    
1262      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1263    
1264      case OP_KET:      case OP_KET:
# Line 1387  for (;;) Line 1472  for (;;)
1472          {          {
1473          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1474            {            {
1475            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1476            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1477            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1478            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1421  for (;;) Line 1506  for (;;)
1506      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1507    
1508      case OP_ANY:      case OP_ANY:
1509      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1510        {      /* Fall through */
1511        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);  
1512        }      case OP_ALLANY:
1513      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);
1514      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1515      ecode++;      ecode++;
1516      break;      break;
1517    
# Line 1526  for (;;) Line 1610  for (;;)
1610        case 0x000d:        case 0x000d:
1611        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1612        break;        break;
1613    
1614        case 0x000a:        case 0x000a:
1615          break;
1616    
1617        case 0x000b:        case 0x000b:
1618        case 0x000c:        case 0x000c:
1619        case 0x0085:        case 0x0085:
1620        case 0x2028:        case 0x2028:
1621        case 0x2029:        case 0x2029:
1622          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1623        break;        break;
1624        }        }
1625      ecode++;      ecode++;
# Line 1642  for (;;) Line 1730  for (;;)
1730      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1731      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1732        {        {
1733        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1734    
1735        switch(ecode[1])        switch(ecode[1])
1736          {          {
# Line 1652  for (;;) Line 1739  for (;;)
1739          break;          break;
1740    
1741          case PT_LAMP:          case PT_LAMP:
1742          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1743               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1744               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1745            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1746           break;           break;
1747    
1748          case PT_GC:          case PT_GC:
1749          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1750            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1751          break;          break;
1752    
1753          case PT_PC:          case PT_PC:
1754          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1755            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1756          break;          break;
1757    
1758          case PT_SC:          case PT_SC:
1759          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1760            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1761          break;          break;
1762    
# Line 1688  for (;;) Line 1775  for (;;)
1775      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);
1776      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1777        {        {
1778        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1779        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1780        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1781          {          {
# Line 1698  for (;;) Line 1784  for (;;)
1784            {            {
1785            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1786            }            }
1787          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1788          if (category != ucp_M) break;          if (category != ucp_M) break;
1789          eptr += len;          eptr += len;
1790          }          }
# Line 1719  for (;;) Line 1805  for (;;)
1805      case OP_REF:      case OP_REF:
1806        {        {
1807        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1808        ecode += 3;                                 /* Advance past item */        ecode += 3;
1809    
1810          /* If the reference is unset, there are two possibilities:
1811    
1812          (a) In the default, Perl-compatible state, set the length to be longer
1813          than the amount of subject left; this ensures that every attempt at a
1814          match fails. We can't just fail here, because of the possibility of
1815          quantifiers with zero minima.
1816    
1817        /* If the reference is unset, set the length to be longer than the amount        (b) If the JavaScript compatibility flag is set, set the length to zero
1818        of subject left; this ensures that every attempt at a match fails. We        so that the back reference matches an empty string.
1819        can't just fail here, because of the possibility of quantifiers with zero  
1820        minima. */        Otherwise, set the length to the length of what was matched by the
1821          referenced subpattern. */
1822        length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
1823          md->end_subject - eptr + 1 :        if (offset >= offset_top || md->offset_vector[offset] < 0)
1824          md->offset_vector[offset+1] - md->offset_vector[offset];          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1825          else
1826            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1827    
1828        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1829    
# Line 1773  for (;;) Line 1868  for (;;)
1868    
1869        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
1870          {          {
1871          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1872              {
1873              CHECK_PARTIAL();
1874              RRETURN(MATCH_NOMATCH);
1875              }
1876          eptr += length;          eptr += length;
1877          }          }
1878    
# Line 1791  for (;;) Line 1890  for (;;)
1890            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1891            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1892            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max || !match_ref(offset, eptr, length, md, ims))
1893                {
1894                CHECK_PARTIAL();
1895              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
1896                }
1897            eptr += length;            eptr += length;
1898            }            }
1899          /* Control never gets here */          /* Control never gets here */
# Line 1807  for (;;) Line 1909  for (;;)
1909            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims)) break;
1910            eptr += length;            eptr += length;
1911            }            }
1912            CHECK_PARTIAL();
1913          while (eptr >= pp)          while (eptr >= pp)
1914            {            {
1915            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
# Line 1874  for (;;) Line 1977  for (;;)
1977          {          {
1978          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
1979            {            {
1980            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
1981                {
1982                CHECK_PARTIAL();
1983                RRETURN(MATCH_NOMATCH);
1984                }
1985            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
1986            if (c > 255)            if (c > 255)
1987              {              {
# Line 1892  for (;;) Line 1999  for (;;)
1999          {          {
2000          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2001            {            {
2002            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2003                {
2004                CHECK_PARTIAL();
2005                RRETURN(MATCH_NOMATCH);
2006                }
2007            c = *eptr++;            c = *eptr++;
2008            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2009            }            }
# Line 1916  for (;;) Line 2027  for (;;)
2027              {              {
2028              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2029              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2030              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
2031                  {
2032                  CHECK_PARTIAL();
2033                  RRETURN(MATCH_NOMATCH);
2034                  }
2035                if (eptr >= md->end_subject)
2036                  {
2037                  SCHECK_PARTIAL();
2038                  RRETURN(MATCH_NOMATCH);
2039                  }
2040              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2041              if (c > 255)              if (c > 255)
2042                {                {
# Line 1936  for (;;) Line 2056  for (;;)
2056              {              {
2057              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2058              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2059              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
2060                  {
2061                  CHECK_PARTIAL();
2062                  RRETURN(MATCH_NOMATCH);
2063                  }
2064                if (eptr >= md->end_subject)
2065                  {
2066                  SCHECK_PARTIAL();
2067                  RRETURN(MATCH_NOMATCH);
2068                  }
2069              c = *eptr++;              c = *eptr++;
2070              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2071              }              }
# Line 1969  for (;;) Line 2098  for (;;)
2098                }                }
2099              eptr += len;              eptr += len;
2100              }              }
2101              CHECK_PARTIAL();
2102            for (;;)            for (;;)
2103              {              {
2104              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
# Line 1988  for (;;) Line 2118  for (;;)
2118              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2119              eptr++;              eptr++;
2120              }              }
2121              CHECK_PARTIAL();
2122            while (eptr >= pp)            while (eptr >= pp)
2123              {              {
2124              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
# Line 2003  for (;;) Line 2134  for (;;)
2134    
2135    
2136      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2137      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2138        mode, because Unicode properties are supported in non-UTF-8 mode. */
2139    
2140  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2141      case OP_XCLASS:      case OP_XCLASS:
# Line 2044  for (;;) Line 2176  for (;;)
2176    
2177        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2178          {          {
2179          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2180          GETCHARINC(c, eptr);            {
2181              SCHECK_PARTIAL();
2182              RRETURN(MATCH_NOMATCH);
2183              }
2184            GETCHARINCTEST(c, eptr);
2185          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2186          }          }
2187    
# Line 2063  for (;;) Line 2199  for (;;)
2199            {            {
2200            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2201            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2202            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max)
2203            GETCHARINC(c, eptr);              {
2204                CHECK_PARTIAL();
2205                RRETURN(MATCH_NOMATCH);
2206                }
2207              if (eptr >= md->end_subject)
2208                {
2209                SCHECK_PARTIAL();
2210                RRETURN(MATCH_NOMATCH);
2211                }
2212              GETCHARINCTEST(c, eptr);
2213            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2214            }            }
2215          /* Control never gets here */          /* Control never gets here */
# Line 2079  for (;;) Line 2224  for (;;)
2224            {            {
2225            int len = 1;            int len = 1;
2226            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2227            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2228            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2229            eptr += len;            eptr += len;
2230            }            }
2231            CHECK_PARTIAL();
2232          for(;;)          for(;;)
2233            {            {
2234            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
# Line 2154  for (;;) Line 2300  for (;;)
2300          if (fc != dc)          if (fc != dc)
2301            {            {
2302  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2303            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2304  #endif  #endif
2305              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2306            }            }
# Line 2223  for (;;) Line 2369  for (;;)
2369      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2370      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2371    
2372      /* Common code for all repeated single-character matches. We can give      /* Common code for all repeated single-character matches. */
     up quickly if there are fewer than the minimum number of characters left in  
     the subject. */  
2373    
2374      REPEATCHAR:      REPEATCHAR:
2375  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2234  for (;;) Line 2378  for (;;)
2378        length = 1;        length = 1;
2379        charptr = ecode;        charptr = ecode;
2380        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2381        ecode += length;        ecode += length;
2382    
2383        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2245  for (;;) Line 2388  for (;;)
2388  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2389          unsigned int othercase;          unsigned int othercase;
2390          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2391              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2392            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2393          else oclength = 0;          else oclength = 0;
2394  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2395    
2396          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2397            {            {
2398            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2399                memcmp(eptr, charptr, length) == 0) eptr += length;
2400  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2401            /* Need braces because of following else */            else if (oclength > 0 &&
2402            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                     eptr <= md->end_subject - oclength &&
2403                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2404    #endif  /* SUPPORT_UCP */
2405            else            else
2406              {              {
2407              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2408              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2409              }              }
 #else   /* without SUPPORT_UCP */  
           else { RRETURN(MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2410            }            }
2411    
2412          if (min == max) continue;          if (min == max) continue;
# Line 2274  for (;;) Line 2417  for (;;)
2417              {              {
2418              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2419              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2420              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
2421              if (memcmp(eptr, charptr, length) == 0) eptr += length;                {
2422                  CHECK_PARTIAL();
2423                  RRETURN(MATCH_NOMATCH);
2424                  }
2425                if (eptr <= md->end_subject - length &&
2426                  memcmp(eptr, charptr, length) == 0) eptr += length;
2427  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2428              /* Need braces because of following else */              else if (oclength > 0 &&
2429              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                       eptr <= md->end_subject - oclength &&
2430                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2431    #endif  /* SUPPORT_UCP */
2432              else              else
2433                {                {
2434                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2435                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2436                }                }
 #else   /* without SUPPORT_UCP */  
             else { RRETURN (MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2437              }              }
2438            /* Control never gets here */            /* Control never gets here */
2439            }            }
# Line 2296  for (;;) Line 2443  for (;;)
2443            pp = eptr;            pp = eptr;
2444            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2445              {              {
2446              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2447              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2448  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2449              else if (oclength == 0) break;              else if (oclength > 0 &&
2450              else                       eptr <= md->end_subject - oclength &&
2451                {                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
               if (memcmp(eptr, occhars, oclength) != 0) break;  
               eptr += oclength;  
               }  
 #else   /* without SUPPORT_UCP */  
             else break;  
2452  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2453                else break;
2454              }              }
2455    
2456              CHECK_PARTIAL();
2457            if (possessive) continue;            if (possessive) continue;
2458    
2459            for(;;)            for(;;)
2460             {              {
2461             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2462             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2463             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2464  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2465             eptr--;              eptr--;
2466             BACKCHAR(eptr);              BACKCHAR(eptr);
2467  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2468             eptr -= length;              eptr -= length;
2469  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2470             }              }
2471            }            }
2472          /* Control never gets here */          /* Control never gets here */
2473          }          }
# Line 2335  for (;;) Line 2480  for (;;)
2480  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2481    
2482      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2483        {  
2484        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2485    
2486      /* The value of fc at this point is always less than 256, though we may or      /* The value of fc at this point is always less than 256, though we may or
2487      may not be in UTF-8 mode. The code is duplicated for the caseless and      may not be in UTF-8 mode. The code is duplicated for the caseless and
# Line 2356  for (;;) Line 2499  for (;;)
2499        {        {
2500        fc = md->lcc[fc];        fc = md->lcc[fc];
2501        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2502            {
2503            if (eptr >= md->end_subject)
2504              {
2505              SCHECK_PARTIAL();
2506              RRETURN(MATCH_NOMATCH);
2507              }
2508          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2509            }
2510        if (min == max) continue;        if (min == max) continue;
2511        if (minimize)        if (minimize)
2512          {          {
# Line 2364  for (;;) Line 2514  for (;;)
2514            {            {
2515            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2516            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2517            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max)
2518                fc != md->lcc[*eptr++])              {
2519                CHECK_PARTIAL();
2520                RRETURN(MATCH_NOMATCH);
2521                }
2522              if (eptr >= md->end_subject)
2523                {
2524                SCHECK_PARTIAL();
2525              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2526                }
2527              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2528            }            }
2529          /* Control never gets here */          /* Control never gets here */
2530          }          }
# Line 2378  for (;;) Line 2536  for (;;)
2536            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2537            eptr++;            eptr++;
2538            }            }
2539    
2540            CHECK_PARTIAL();
2541          if (possessive) continue;          if (possessive) continue;
2542    
2543          while (eptr >= pp)          while (eptr >= pp)
2544            {            {
2545            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
# Line 2394  for (;;) Line 2555  for (;;)
2555    
2556      else      else
2557        {        {
2558        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2559            {
2560            if (eptr >= md->end_subject)
2561              {
2562              SCHECK_PARTIAL();
2563              RRETURN(MATCH_NOMATCH);
2564              }
2565            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2566            }
2567        if (min == max) continue;        if (min == max) continue;
2568        if (minimize)        if (minimize)
2569          {          {
# Line 2402  for (;;) Line 2571  for (;;)
2571            {            {
2572            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2573            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2574            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max)
2575                {
2576                CHECK_PARTIAL();
2577              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2578                }
2579              if (eptr >= md->end_subject)
2580                {
2581                SCHECK_PARTIAL();
2582                RRETURN(MATCH_NOMATCH);
2583                }
2584              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2585            }            }
2586          /* Control never gets here */          /* Control never gets here */
2587          }          }
# Line 2415  for (;;) Line 2593  for (;;)
2593            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2594            eptr++;            eptr++;
2595            }            }
2596            CHECK_PARTIAL();
2597          if (possessive) continue;          if (possessive) continue;
2598          while (eptr >= pp)          while (eptr >= pp)
2599            {            {
# Line 2508  for (;;) Line 2687  for (;;)
2687      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2688      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2689    
2690      /* Common code for all repeated single-byte matches. We can give up quickly      /* Common code for all repeated single-byte matches. */
     if there are fewer than the minimum number of bytes left in the  
     subject. */  
2691    
2692      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2693      fc = *ecode++;      fc = *ecode++;
2694    
2695      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
# Line 2538  for (;;) Line 2714  for (;;)
2714          register unsigned int d;          register unsigned int d;
2715          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2716            {            {
2717              if (eptr >= md->end_subject)
2718                {
2719                SCHECK_PARTIAL();
2720                RRETURN(MATCH_NOMATCH);
2721                }
2722            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2723            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2724            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2549  for (;;) Line 2730  for (;;)
2730        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2731          {          {
2732          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2733              {
2734              if (eptr >= md->end_subject)
2735                {
2736                SCHECK_PARTIAL();
2737                RRETURN(MATCH_NOMATCH);
2738                }
2739            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2740              }
2741          }          }
2742    
2743        if (min == max) continue;        if (min == max) continue;
# Line 2565  for (;;) Line 2753  for (;;)
2753              {              {
2754              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2755              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2756                if (fi >= max)
2757                  {
2758                  CHECK_PARTIAL();
2759                  RRETURN(MATCH_NOMATCH);
2760                  }
2761                if (eptr >= md->end_subject)
2762                  {
2763                  SCHECK_PARTIAL();
2764                  RRETURN(MATCH_NOMATCH);
2765                  }
2766              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2767              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2768              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2769              }              }
2770            }            }
2771          else          else
# Line 2579  for (;;) Line 2776  for (;;)
2776              {              {
2777              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2778              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2779              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max)
2780                  {
2781                  CHECK_PARTIAL();
2782                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2783                  }
2784                if (eptr >= md->end_subject)
2785                  {
2786                  SCHECK_PARTIAL();
2787                  RRETURN(MATCH_NOMATCH);
2788                  }
2789                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2790              }              }
2791            }            }
2792          /* Control never gets here */          /* Control never gets here */
# Line 2606  for (;;) Line 2812  for (;;)
2812              if (fc == d) break;              if (fc == d) break;
2813              eptr += len;              eptr += len;
2814              }              }
2815            CHECK_PARTIAL();
2816          if (possessive) continue;          if (possessive) continue;
2817          for(;;)          for(;;)
2818              {              {
# Line 2624  for (;;) Line 2831  for (;;)
2831              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2832              eptr++;              eptr++;
2833              }              }
2834              CHECK_PARTIAL();
2835            if (possessive) continue;            if (possessive) continue;
2836            while (eptr >= pp)            while (eptr >= pp)
2837              {              {
# Line 2649  for (;;) Line 2857  for (;;)
2857          register unsigned int d;          register unsigned int d;
2858          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2859            {            {
2860              if (eptr >= md->end_subject)
2861                {
2862                SCHECK_PARTIAL();
2863                RRETURN(MATCH_NOMATCH);
2864                }
2865            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2866            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
2867            }            }
# Line 2658  for (;;) Line 2871  for (;;)
2871        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2872          {          {
2873          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2874              {
2875              if (eptr >= md->end_subject)
2876                {
2877                SCHECK_PARTIAL();
2878                RRETURN(MATCH_NOMATCH);
2879                }
2880            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2881              }
2882          }          }
2883    
2884        if (min == max) continue;        if (min == max) continue;
# Line 2674  for (;;) Line 2894  for (;;)
2894              {              {
2895              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2896              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2897              GETCHARINC(d, eptr);              if (fi >= max)
2898              if (fi >= max || eptr >= md->end_subject || fc == d)                {
2899                  CHECK_PARTIAL();
2900                  RRETURN(MATCH_NOMATCH);
2901                  }
2902                if (eptr >= md->end_subject)
2903                  {
2904                  SCHECK_PARTIAL();
2905                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2906                  }
2907                GETCHARINC(d, eptr);
2908                if (fc == d) RRETURN(MATCH_NOMATCH);
2909              }              }
2910            }            }
2911          else          else
# Line 2687  for (;;) Line 2916  for (;;)
2916              {              {
2917              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2918              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2919              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max)
2920                  {
2921                  CHECK_PARTIAL();
2922                  RRETURN(MATCH_NOMATCH);
2923                  }
2924                if (eptr >= md->end_subject)
2925                  {
2926                  SCHECK_PARTIAL();
2927                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2928                  }
2929                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2930              }              }
2931            }            }
2932          /* Control never gets here */          /* Control never gets here */
# Line 2713  for (;;) Line 2951  for (;;)
2951              if (fc == d) break;              if (fc == d) break;
2952              eptr += len;              eptr += len;
2953              }              }
2954              CHECK_PARTIAL();
2955            if (possessive) continue;            if (possessive) continue;
2956            for(;;)            for(;;)
2957              {              {
# Line 2731  for (;;) Line 2970  for (;;)
2970              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
2971              eptr++;              eptr++;
2972              }              }
2973              CHECK_PARTIAL();
2974            if (possessive) continue;            if (possessive) continue;
2975            while (eptr >= pp)            while (eptr >= pp)
2976              {              {
# Line 2822  for (;;) Line 3062  for (;;)
3062    
3063      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3064      code for maximizing the speed, and do the type test once at the start      code for maximizing the speed, and do the type test once at the start
3065      (i.e. keep it out of the loop). Also we can test that there are at least      (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
     the minimum number of bytes before we start. This isn't as effective in  
     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that  
3066      is tidier. Also separate the UCP code, which can be the same for both UTF-8      is tidier. Also separate the UCP code, which can be the same for both UTF-8
3067      and single-bytes. */      and single-bytes. */
3068    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3069      if (min > 0)      if (min > 0)
3070        {        {
3071  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2840  for (;;) Line 3077  for (;;)
3077            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3078            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3079              {              {
3080              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3081                  {
3082                  SCHECK_PARTIAL();
3083                  RRETURN(MATCH_NOMATCH);
3084                  }
3085              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3086              }              }
3087            break;            break;
# Line 2848  for (;;) Line 3089  for (;;)
3089            case PT_LAMP:            case PT_LAMP:
3090            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3091              {              {
3092              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3093                  {
3094                  SCHECK_PARTIAL();
3095                  RRETURN(MATCH_NOMATCH);
3096                  }
3097              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3098              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3099              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3100                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3101                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2861  for (;;) Line 3106  for (;;)
3106            case PT_GC:            case PT_GC:
3107            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3108              {              {
3109              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3110                  {
3111                  SCHECK_PARTIAL();
3112                  RRETURN(MATCH_NOMATCH);
3113                  }
3114              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3115              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3116              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3117                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3118              }              }
# Line 2872  for (;;) Line 3121  for (;;)
3121            case PT_PC:            case PT_PC:
3122            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3123              {              {
3124              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3125                  {
3126                  SCHECK_PARTIAL();
3127                  RRETURN(MATCH_NOMATCH);
3128                  }
3129              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3130              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3131              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3132                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3133              }              }
# Line 2883  for (;;) Line 3136  for (;;)
3136            case PT_SC:            case PT_SC:
3137            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3138              {              {
3139              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3140                  {
3141                  SCHECK_PARTIAL();
3142                  RRETURN(MATCH_NOMATCH);
3143                  }
3144              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3145              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3146              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3147                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3148              }              }
# Line 2903  for (;;) Line 3160  for (;;)
3160          {          {
3161          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3162            {            {
3163              if (eptr >= md->end_subject)
3164                {
3165                SCHECK_PARTIAL();
3166                RRETURN(MATCH_NOMATCH);
3167                }
3168            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3169            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3170            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3171            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3172              {              {
3173              int len = 1;              int len = 1;
3174              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3175                {                else { GETCHARLEN(c, eptr, len); }
3176                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3177              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3178              eptr += len;              eptr += len;
3179              }              }
# Line 2931  for (;;) Line 3191  for (;;)
3191          case OP_ANY:          case OP_ANY:
3192          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3193            {            {
3194            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3195                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))              {
3196                SCHECK_PARTIAL();
3197              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3198                }
3199              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3200              eptr++;
3201              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3202              }
3203            break;
3204    
3205            case OP_ALLANY:
3206            for (i = 1; i <= min; i++)
3207              {
3208              if (eptr >= md->end_subject)
3209                {
3210                SCHECK_PARTIAL();
3211                RRETURN(MATCH_NOMATCH);
3212                }
3213            eptr++;            eptr++;
3214            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3215            }            }
3216          break;          break;
3217    
3218          case OP_ANYBYTE:          case OP_ANYBYTE:
3219            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3220          eptr += min;          eptr += min;
3221          break;          break;
3222    
3223          case OP_ANYNL:          case OP_ANYNL:
3224          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3225            {            {
3226            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3227                {
3228                SCHECK_PARTIAL();
3229                RRETURN(MATCH_NOMATCH);
3230                }
3231            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3232            switch(c)            switch(c)
3233              {              {
# Line 2954  for (;;) Line 3235  for (;;)
3235              case 0x000d:              case 0x000d:
3236              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3237              break;              break;
3238    
3239              case 0x000a:              case 0x000a:
3240                break;
3241    
3242              case 0x000b:              case 0x000b:
3243              case 0x000c:              case 0x000c:
3244              case 0x0085:              case 0x0085:
3245              case 0x2028:              case 0x2028:
3246              case 0x2029:              case 0x2029:
3247                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3248              break;              break;
3249              }              }
3250            }            }
# Line 2968  for (;;) Line 3253  for (;;)
3253          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
3254          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3255            {            {
3256            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3257                {
3258                SCHECK_PARTIAL();
3259                RRETURN(MATCH_NOMATCH);
3260                }
3261            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3262            switch(c)            switch(c)
3263              {              {
# Line 3000  for (;;) Line 3289  for (;;)
3289          case OP_HSPACE:          case OP_HSPACE:
3290          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3291            {            {
3292            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3293                {
3294                SCHECK_PARTIAL();
3295                RRETURN(MATCH_NOMATCH);
3296                }
3297            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3298            switch(c)            switch(c)
3299              {              {
# Line 3032  for (;;) Line 3325  for (;;)
3325          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3326          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3327            {            {
3328            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3329                {
3330                SCHECK_PARTIAL();
3331                RRETURN(MATCH_NOMATCH);
3332                }
3333            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3334            switch(c)            switch(c)
3335              {              {
# Line 3052  for (;;) Line 3349  for (;;)
3349          case OP_VSPACE:          case OP_VSPACE:
3350          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3351            {            {
3352            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3353                {
3354                SCHECK_PARTIAL();
3355                RRETURN(MATCH_NOMATCH);
3356                }
3357            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3358            switch(c)            switch(c)
3359              {              {
# Line 3072  for (;;) Line 3373  for (;;)
3373          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3374          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3375            {            {
3376            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3377                {
3378                SCHECK_PARTIAL();
3379                RRETURN(MATCH_NOMATCH);
3380                }
3381            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3382            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3383              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 3082  for (;;) Line 3387  for (;;)
3387          case OP_DIGIT:          case OP_DIGIT:
3388          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3389            {            {
3390            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3391               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3392                SCHECK_PARTIAL();
3393                RRETURN(MATCH_NOMATCH);
3394                }
3395              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3396              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3397            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3398            }            }
# Line 3092  for (;;) Line 3401  for (;;)
3401          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3402          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3403            {            {
3404            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3405               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))              {
3406                SCHECK_PARTIAL();
3407                RRETURN(MATCH_NOMATCH);
3408                }
3409              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3410              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3411            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3412            }            }
# Line 3102  for (;;) Line 3415  for (;;)
3415          case OP_WHITESPACE:          case OP_WHITESPACE:
3416          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3417            {            {
3418            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3419               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3420                SCHECK_PARTIAL();
3421                RRETURN(MATCH_NOMATCH);
3422                }
3423              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3424              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3425            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3426            }            }
# Line 3122  for (;;) Line 3439  for (;;)
3439          case OP_WORDCHAR:          case OP_WORDCHAR:
3440          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3441            {            {
3442            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3443               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3444                SCHECK_PARTIAL();
3445                RRETURN(MATCH_NOMATCH);
3446                }
3447              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3448              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3449            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3450            }            }
# Line 3137  for (;;) Line 3458  for (;;)
3458  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3459    
3460        /* Code for the non-UTF-8 case for minimum matching of operators other        /* Code for the non-UTF-8 case for minimum matching of operators other
3461        than OP_PROP and OP_NOTPROP. We can assume that there are the minimum        than OP_PROP and OP_NOTPROP. */
       number of bytes present, as this was tested above. */  
3462    
3463        switch(ctype)        switch(ctype)
3464          {          {
3465          case OP_ANY:          case OP_ANY:
3466          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3467            {            {
3468            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3469              {              {
3470              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3471              eptr++;              RRETURN(MATCH_NOMATCH);
3472              }              }
3473              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3474              eptr++;
3475            }            }
         else eptr += min;  
3476          break;          break;
3477    
3478          case OP_ANYBYTE:          case OP_ALLANY:
3479            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3480          eptr += min;          eptr += min;
3481          break;          break;
3482    
3483          /* Because of the CRLF case, we can't assume the minimum number of          case OP_ANYBYTE:
3484          bytes are present in this case. */          if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3485            eptr += min;
3486            break;
3487    
3488          case OP_ANYNL:          case OP_ANYNL:
3489          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3490            {            {
3491            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3492                {
3493                SCHECK_PARTIAL();
3494                RRETURN(MATCH_NOMATCH);
3495                }
3496            switch(*eptr++)            switch(*eptr++)
3497              {              {
3498              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3172  for (;;) Line 3500  for (;;)
3500              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3501              break;              break;
3502              case 0x000a:              case 0x000a:
3503                break;
3504    
3505              case 0x000b:              case 0x000b:
3506              case 0x000c:              case 0x000c:
3507              case 0x0085:              case 0x0085:
3508                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3509              break;              break;
3510              }              }
3511            }            }
# Line 3183  for (;;) Line 3514  for (;;)
3514          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
3515          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3516            {            {
3517            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3518                {
3519                SCHECK_PARTIAL();
3520                RRETURN(MATCH_NOMATCH);
3521                }
3522            switch(*eptr++)            switch(*eptr++)
3523              {              {
3524              default: break;              default: break;
# Line 3198  for (;;) Line 3533  for (;;)
3533          case OP_HSPACE:          case OP_HSPACE:
3534          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3535            {            {
3536            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3537                {
3538                SCHECK_PARTIAL();
3539                RRETURN(MATCH_NOMATCH);
3540                }
3541            switch(*eptr++)            switch(*eptr++)
3542              {              {
3543              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3213  for (;;) Line 3552  for (;;)
3552          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3553          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3554            {            {
3555            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3556                {
3557                SCHECK_PARTIAL();
3558                RRETURN(MATCH_NOMATCH);
3559                }
3560            switch(*eptr++)            switch(*eptr++)
3561              {              {
3562              default: break;              default: break;
# Line 3230  for (;;) Line 3573  for (;;)
3573          case OP_VSPACE:          case OP_VSPACE:
3574          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3575            {            {
3576            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3577                {
3578                SCHECK_PARTIAL();
3579                RRETURN(MATCH_NOMATCH);
3580                }
3581            switch(*eptr++)            switch(*eptr++)
3582              {              {
3583              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3246  for (;;) Line 3593  for (;;)
3593    
3594          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3595          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3596              {
3597              if (eptr >= md->end_subject)
3598                {
3599                SCHECK_PARTIAL();
3600                RRETURN(MATCH_NOMATCH);
3601                }
3602            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3603              }
3604          break;          break;
3605    
3606          case OP_DIGIT:          case OP_DIGIT:
3607          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3608              {
3609              if (eptr >= md->end_subject)
3610                {
3611                SCHECK_PARTIAL();
3612                RRETURN(MATCH_NOMATCH);
3613                }
3614            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3615              }
3616          break;          break;
3617    
3618          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3619          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3620              {
3621              if (eptr >= md->end_subject)
3622                {
3623                SCHECK_PARTIAL();
3624                RRETURN(MATCH_NOMATCH);
3625                }
3626            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3627              }
3628          break;          break;
3629    
3630          case OP_WHITESPACE:          case OP_WHITESPACE:
3631          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3632              {
3633              if (eptr >= md->end_subject)
3634                {
3635                SCHECK_PARTIAL();
3636                RRETURN(MATCH_NOMATCH);
3637                }
3638            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3639              }
3640          break;          break;
3641    
3642          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3643          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3644              {
3645              if (eptr >= md->end_subject)
3646                {
3647                SCHECK_PARTIAL();
3648                RRETURN(MATCH_NOMATCH);
3649                }
3650            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3651              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3652              }
3653          break;          break;
3654    
3655          case OP_WORDCHAR:          case OP_WORDCHAR:
3656          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3657              {
3658              if (eptr >= md->end_subject)
3659                {
3660                SCHECK_PARTIAL();
3661                RRETURN(MATCH_NOMATCH);
3662                }
3663            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3664              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3665              }
3666          break;          break;
3667    
3668          default:          default:
# Line 3301  for (;;) Line 3690  for (;;)
3690              {              {
3691              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3692              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3693              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
3694                  {
3695                  CHECK_PARTIAL();
3696                  RRETURN(MATCH_NOMATCH);
3697                  }
3698                if (eptr >= md->end_subject)
3699                  {
3700                  SCHECK_PARTIAL();
3701                  RRETURN(MATCH_NOMATCH);
3702                  }
3703              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3704              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3705              }              }
# Line 3312  for (;;) Line 3710  for (;;)
3710              {              {
3711              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3712              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3713              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
3714                  {
3715                  CHECK_PARTIAL();
3716                  RRETURN(MATCH_NOMATCH);
3717                  }
3718                if (eptr >= md->end_subject)
3719                  {
3720                  SCHECK_PARTIAL();
3721                  RRETURN(MATCH_NOMATCH);
3722                  }
3723              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3724              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3725              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3726                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3727                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3327  for (;;) Line 3734  for (;;)
3734              {              {
3735              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3736              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3737              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
3738                  {
3739                  CHECK_PARTIAL();
3740                  RRETURN(MATCH_NOMATCH);
3741                  }
3742                if (eptr >= md->end_subject)
3743                  {
3744                  SCHECK_PARTIAL();
3745                  RRETURN(MATCH_NOMATCH);
3746                  }
3747              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3748              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3749              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3750                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3751              }              }
# Line 3340  for (;;) Line 3756  for (;;)
3756              {              {
3757              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3758              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3759              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
3760                  {
3761                  CHECK_PARTIAL();
3762                  RRETURN(MATCH_NOMATCH);
3763                  }
3764                if (eptr >= md->end_subject)
3765                  {
3766                  SCHECK_PARTIAL();
3767                  RRETURN(MATCH_NOMATCH);
3768                  }
3769              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3770              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3771              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3772                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3773              }              }
# Line 3353  for (;;) Line 3778  for (;;)
3778              {              {
3779              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3780              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3781              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max)
3782                  {
3783                  CHECK_PARTIAL();
3784                  RRETURN(MATCH_NOMATCH);
3785                  }
3786                if (eptr >= md->end_subject)
3787                  {
3788                  SCHECK_PARTIAL();
3789                  RRETURN(MATCH_NOMATCH);
3790                  }
3791              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3792              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3793              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3794                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3795              }              }
# Line 3375  for (;;) Line 3809  for (;;)
3809            {            {
3810            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3811            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3812            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max)
3813                {
3814                CHECK_PARTIAL();
3815                RRETURN(MATCH_NOMATCH);
3816                }
3817              if (eptr >= md->end_subject)
3818                {
3819                SCHECK_PARTIAL();
3820                RRETURN(MATCH_NOMATCH);
3821                }
3822            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3823            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3824            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3825            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3826              {              {
3827              int len = 1;              int len = 1;
3828              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3829                {                else { GETCHARLEN(c, eptr, len); }
3830                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3831              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3832              eptr += len;              eptr += len;
3833              }              }
# Line 3404  for (;;) Line 3845  for (;;)
3845            {            {
3846            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3847            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3848            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max)
3849                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&              {
3850                  IS_NEWLINE(eptr)))              CHECK_PARTIAL();
3851                RRETURN(MATCH_NOMATCH);
3852                }
3853              if (eptr >= md->end_subject)
3854                {
3855                SCHECK_PARTIAL();
3856                RRETURN(MATCH_NOMATCH);
3857                }
3858              if (ctype == OP_ANY && IS_NEWLINE(eptr))
3859              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
3860            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3861            switch(ctype)            switch(ctype)
3862              {              {
3863              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3864              break;              case OP_ALLANY:
   
3865              case OP_ANYBYTE:              case OP_ANYBYTE:
3866              break;              break;
3867    
# Line 3426  for (;;) Line 3873  for (;;)
3873                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3874                break;                break;
3875                case 0x000a:                case 0x000a:
3876                  break;
3877    
3878                case 0x000b:                case 0x000b:
3879                case 0x000c:                case 0x000c:
3880                case 0x0085:                case 0x0085:
3881                case 0x2028:                case 0x2028:
3882                case 0x2029:                case 0x2029:
3883                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3884                break;                break;
3885                }                }
3886              break;              break;
# Line 3562  for (;;) Line 4012  for (;;)
4012            {            {
4013            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4014            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4015            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max)
4016                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))              {
4017                CHECK_PARTIAL();
4018                RRETURN(MATCH_NOMATCH);
4019                }
4020              if (eptr >= md->end_subject)
4021                {
4022                SCHECK_PARTIAL();
4023                RRETURN(MATCH_NOMATCH);
4024                }
4025              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4026              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4027            c = *eptr++;            c = *eptr++;
4028            switch(ctype)            switch(ctype)
4029              {              {
4030              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
4031              break;              case OP_ALLANY:
   
4032              case OP_ANYBYTE:              case OP_ANYBYTE:
4033              break;              break;
4034    
# Line 3582  for (;;) Line 4039  for (;;)
4039                case 0x000d:                case 0x000d:
4040                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4041                break;                break;
4042    
4043                case 0x000a:                case 0x000a:
4044                  break;
4045    
4046                case 0x000b:                case 0x000b:
4047                case 0x000c:                case 0x000c:
4048                case 0x0085:                case 0x0085:
4049                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4050                break;                break;
4051                }                }
4052              break;              break;
# Line 3700  for (;;) Line 4161  for (;;)
4161              int len = 1;              int len = 1;
4162              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4163              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4164              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4165              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4166                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
4167                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3715  for (;;) Line 4176  for (;;)
4176              int len = 1;              int len = 1;
4177              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4178              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4179              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4180              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4181                break;                break;
4182              eptr+= len;              eptr+= len;
# Line 3728  for (;;) Line 4189  for (;;)
4189              int len = 1;              int len = 1;
4190              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4191              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4192              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4193              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4194                break;                break;
4195              eptr+= len;              eptr+= len;
# Line 3741  for (;;) Line 4202  for (;;)
4202              int len = 1;              int len = 1;
4203              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4204              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4205              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
4206              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
4207                break;                break;
4208              eptr+= len;              eptr+= len;
# Line 3751  for (;;) Line 4212  for (;;)
4212    
4213          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4214    
4215            CHECK_PARTIAL();
4216          if (possessive) continue;          if (possessive) continue;
4217          for(;;)          for(;;)
4218            {            {
# Line 3770  for (;;) Line 4232  for (;;)
4232            {            {
4233            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
4234            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4235            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
4236            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
4237            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4238              {              {
# Line 3779  for (;;) Line 4241  for (;;)
4241                {                {
4242                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
4243                }                }
4244              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4245              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4246              eptr += len;              eptr += len;
4247              }              }
# Line 3787  for (;;) Line 4249  for (;;)
4249    
4250          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4251    
4252            CHECK_PARTIAL();
4253          if (possessive) continue;          if (possessive) continue;
4254          for(;;)          for(;;)
4255            {            {
# Line 3801  for (;;) Line 4264  for (;;)
4264                BACKCHAR(eptr);                BACKCHAR(eptr);
4265                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
4266                }                }
4267              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4268              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4269              eptr--;              eptr--;
4270              }              }
# Line 3821  for (;;) Line 4284  for (;;)
4284            case OP_ANY:            case OP_ANY:
4285            if (max < INT_MAX)            if (max < INT_MAX)
4286              {              {
4287              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
4288                {                {
4289                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4290                  {                eptr++;
4291                  if (eptr >= md->end_subject) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
4292                }                }
4293              }              }
4294    
# Line 3845  for (;;) Line 4296  for (;;)
4296    
4297            else            else
4298              {              {
4299              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
4300                {                {
4301                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4302                  {                eptr++;
4303                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
4304                }                }
4305              else              }
4306              break;
4307    
4308              case OP_ALLANY:
4309              if (max < INT_MAX)
4310                {
4311                for (i = min; i < max; i++)
4312                {                {
4313                eptr = md->end_subject;                if (eptr >= md->end_subject) break;
4314                  eptr++;
4315                  while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4316                }                }
4317              }              }
4318              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
4319            break;            break;
4320    
4321            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3883  for (;;) Line 4340  for (;;)
4340                }                }
4341              else              else
4342                {                {
4343                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
4344                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
4345                       (c != 0x000b && c != 0x000c &&
4346                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
4347                  break;                  break;
4348                eptr += len;                eptr += len;
4349                }                }
# Line 4027  for (;;) Line 4486  for (;;)
4486    
4487          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4488    
4489            CHECK_PARTIAL();
4490          if (possessive) continue;          if (possessive) continue;
4491          for(;;)          for(;;)
4492            {            {
# Line 4044  for (;;) Line 4504  for (;;)
4504          switch(ctype)          switch(ctype)
4505            {            {
4506            case OP_ANY:            case OP_ANY:
4507            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4508              {              {
4509              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4510                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4511              }              }
4512            /* For DOTALL case, fall through and treat as \C */            break;
4513    
4514              case OP_ALLANY:
4515            case OP_ANYBYTE:            case OP_ANYBYTE:
4516            c = max - min;            c = max - min;
4517            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 4074  for (;;) Line 4531  for (;;)
4531                }                }
4532              else              else
4533                {                {
4534                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4535                      (md->bsr_anycrlf ||
4536                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4537                  break;                  break;
4538                eptr++;                eptr++;
4539                }                }
# Line 4183  for (;;) Line 4642  for (;;)
4642    
4643          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4644    
4645            CHECK_PARTIAL();
4646          if (possessive) continue;          if (possessive) continue;
4647          while (eptr >= pp)          while (eptr >= pp)
4648            {            {
# Line 4224  HEAP_RETURN: Line 4684  HEAP_RETURN:
4684  switch (frame->Xwhere)  switch (frame->Xwhere)
4685    {    {
4686    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)    LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4687    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(16)    LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4688    LBL(17) LBL(18) LBL(19) LBL(20) LBL(21) LBL(22) LBL(23) LBL(24)    LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4689    LBL(25) LBL(26) LBL(27) LBL(28) LBL(29) LBL(30) LBL(31) LBL(32)    LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4690    LBL(33) LBL(34) LBL(35) LBL(36) LBL(37) LBL(38) LBL(39) LBL(40)    LBL(53) LBL(54)
4691    LBL(41) LBL(42) LBL(43) LBL(44) LBL(45) LBL(46) LBL(47) LBL(48)  #ifdef SUPPORT_UTF8
4692    LBL(49) LBL(50) LBL(51) LBL(52) LBL(53) LBL(54)    LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4693      LBL(32) LBL(34) LBL(42) LBL(46)
4694    #ifdef SUPPORT_UCP
4695      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4696    #endif  /* SUPPORT_UCP */
4697    #endif  /* SUPPORT_UTF8 */
4698    default:    default:
4699    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));    DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4700    return PCRE_ERROR_INTERNAL;    return PCRE_ERROR_INTERNAL;
# Line 4321  Returns:          > 0 => success; value Line 4786  Returns:          > 0 => success; value
4786                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4787  */  */
4788    
4789  PCRE_EXP_DEFN int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4790  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4791    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4792    int offsetcount)    int offsetcount)
# Line 4345  const uschar *tables; Line 4810  const uschar *tables;
4810  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4811  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4812  USPTR end_subject;  USPTR end_subject;
4813    USPTR start_partial = NULL;
4814  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
4815    
4816  pcre_study_data internal_study;  pcre_study_data internal_study;
# Line 4408  if (re->magic_number != MAGIC_NUMBER) Line 4874  if (re->magic_number != MAGIC_NUMBER)
4874  /* Set up other data */  /* Set up other data */
4875    
4876  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4877  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4878  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4879    
4880  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
# Line 4423  end_subject = md->end_subject; Line 4889  end_subject = md->end_subject;
4889    
4890  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4891  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4892    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4893    
4894  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4895  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
# Line 4435  md->recursive = NULL; Line 4902  md->recursive = NULL;
4902  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4903  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4904    
4905    /* Handle different \R options. */
4906    
4907    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4908      {
4909      case 0:
4910      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4911        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4912      else
4913    #ifdef BSR_ANYCRLF
4914      md->bsr_anycrlf = TRUE;
4915    #else
4916      md->bsr_anycrlf = FALSE;
4917    #endif
4918      break;
4919    
4920      case PCRE_BSR_ANYCRLF:
4921      md->bsr_anycrlf = TRUE;
4922      break;
4923    
4924      case PCRE_BSR_UNICODE:
4925      md->bsr_anycrlf = FALSE;
4926      break;
4927    
4928      default: return PCRE_ERROR_BADNEWLINE;
4929      }
4930    
4931  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4932  nothing is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
4933    
4934  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : (pcre_uint32)options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4935         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4936    {    {
4937    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4938    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4939    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4940    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
4941         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4942    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
4943    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4944    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 4475  else Line 4968  else
4968      }      }
4969    }    }
4970    
4971  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching was originally supported only for a restricted set of
4972  moment. */  regexes; from release 8.00 there are no restrictions, but the bits are still
4973    defined (though never set). So there's no harm in leaving this code. */
4974    
4975  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
4976    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
4977    
4978  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
# Line 4487  back the character offset. */ Line 4981  back the character offset. */
4981  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
4982  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
4983    {    {
4984    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((USPTR)subject, length) >= 0)
4985      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
4986    if (start_offset > 0 && start_offset < length)    if (start_offset > 0 && start_offset < length)
4987      {      {
4988      int tb = ((uschar *)subject)[start_offset];      int tb = ((USPTR)subject)[start_offset];
4989      if (tb > 127)      if (tb > 127)
4990        {        {
4991        tb &= 0xc0;        tb &= 0xc0;
# Line 4555  studied, there may be a bitmap of possib Line 5049  studied, there may be a bitmap of possib
5049    
5050  if (!anchored)  if (!anchored)
5051    {    {
5052    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
5053      {      {
5054      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
5055      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 4570  if (!anchored) Line 5064  if (!anchored)
5064  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
5065  character" set. */  character" set. */
5066    
5067  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
5068    {    {
5069    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
5070    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 4597  for(;;) Line 5091  for(;;)
5091      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
5092      }      }
5093    
5094    /* Advance to a unique first char if possible. If firstline is TRUE, the    /* If firstline is TRUE, the start of the match is constrained to the first
5095    start of the match is constrained to the first line of a multiline string.    line of a multiline string. That is, the match must be before or at the first
5096    That is, the match must be before or at the first newline. Implement this by    newline. Implement this by temporarily adjusting end_subject so that we stop
5097    temporarily adjusting end_subject so that we stop scanning at a newline. If    scanning at a newline. If the match fails at the newline, later code breaks
5098    the match fails at the newline, later code breaks this loop. */    this loop. */
5099    
5100    if (firstline)    if (firstline)
5101      {      {
5102      USPTR t = start_match;      USPTR t = start_match;
5103    #ifdef SUPPORT_UTF8
5104        if (utf8)
5105          {
5106          while (t < md->end_subject && !IS_NEWLINE(t))
5107            {
5108            t++;
5109            while (t < end_subject && (*t & 0xc0) == 0x80) t++;
5110            }
5111          }
5112        else
5113    #endif
5114      while (t < md->end_subject && !IS_NEWLINE(t)) t++;      while (t < md->end_subject && !IS_NEWLINE(t)) t++;
5115      end_subject = t;      end_subject = t;
5116      }      }
5117    
5118    /* Now test for a unique first byte */    /* There are some optimizations that avoid running the match if a known
5119      starting point is not found, or if a known later character is not present.
5120      However, there is an option that disables these, for testing and for ensuring
5121      that all callouts do actually occur. */
5122    
5123    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
5124      {      {
5125      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
       while (start_match < end_subject &&  
              md->lcc[*start_match] != first_byte)  
         start_match++;  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         start_match++;  
     }  
5126    
5127    /* Or to just after a linebreak for a multiline match if possible */      if (first_byte >= 0)
5128          {
5129          if (first_byte_caseless)
5130            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
5131              start_match++;
5132          else
5133            while (start_match < end_subject && *start_match != first_byte)
5134              start_match++;
5135          }
5136    
5137    else if (startline)      /* Or to just after a linebreak for a multiline match */
5138      {  
5139      if (start_match > md->start_subject + start_offset)      else if (startline)
5140        {        {
5141        while (start_match <= end_subject && !WAS_NEWLINE(start_match))        if (start_match > md->start_subject + start_offset)
5142          start_match++;          {
5143    #ifdef SUPPORT_UTF8
5144            if (utf8)
5145              {
5146              while (start_match < end_subject && !WAS_NEWLINE(start_match))
5147                {
5148                start_match++;
5149                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
5150                  start_match++;
5151                }
5152              }
5153            else
5154    #endif
5155            while (start_match < end_subject && !WAS_NEWLINE(start_match))
5156              start_match++;
5157    
5158            /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
5159            and we are now at a LF, advance the match position by one more character.
5160            */
5161    
5162        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,          if (start_match[-1] == CHAR_CR &&
5163        and we are now at a LF, advance the match position by one more character.               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
5164        */               start_match < end_subject &&
5165                 *start_match == CHAR_NL)
5166        if (start_match[-1] == '\r' &&            start_match++;
5167             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&          }
            start_match < end_subject &&  
            *start_match == '\n')  
         start_match++;  
5168        }        }
     }  
5169    
5170    /* Or to a non-unique first char after study */      /* Or to a non-unique first byte after study */
5171    
5172    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)  
5173        {        {
5174        register unsigned int c = *start_match;        while (start_match < end_subject)
5175        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++; else break;          {
5176            register unsigned int c = *start_match;
5177            if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
5178              else break;
5179            }
5180        }        }
5181      }      }   /* Starting optimizations */
5182    
5183    /* Restore fudged end_subject */    /* Restore fudged end_subject */
5184    
# Line 4665  for(;;) Line 5190  for(;;)
5190    printf("\n");    printf("\n");
5191  #endif  #endif
5192    
5193    /* If req_byte is set, we know that that character must appear in the subject    /* If req_byte is set, we know that that character must appear in the
5194    for the match to succeed. If the first character is set, req_byte must be    subject for the match to succeed. If the first character is set, req_byte
5195    later in the subject; otherwise the test starts at the match point. This    must be later in the subject; otherwise the test starts at the match point.
5196    optimization can save a huge amount of backtracking in patterns with nested    This optimization can save a huge amount of backtracking in patterns with
5197    unlimited repeats that aren't going to match. Writing separate code for    nested unlimited repeats that aren't going to match. Writing separate code
5198    cased/caseless versions makes it go faster, as does using an autoincrement    for cased/caseless versions makes it go faster, as does using an
5199    and backing off on a match.    autoincrement and backing off on a match.
5200    
5201    HOWEVER: when the subject string is very, very long, searching to its end can    HOWEVER: when the subject string is very, very long, searching to its end
5202    take a long time, and give bad performance on quite ordinary patterns. This    can take a long time, and give bad performance on quite ordinary patterns.
5203    showed up when somebody was matching something like /^\d+C/ on a 32-megabyte    This showed up when somebody was matching something like /^\d+C/ on a
5204    string... so we don't do this when the string is sufficiently long.    32-megabyte string... so we don't do this when the string is sufficiently
5205      long.
5206    
5207    ALSO: this processing is disabled when partial matching is requested.    ALSO: this processing is disabled when partial matching is requested, or if
5208    */    disabling is explicitly requested. */
5209    
5210    if (req_byte >= 0 &&    if ((options & PCRE_NO_START_OPTIMIZE) == 0 &&
5211          req_byte >= 0 &&
5212        end_subject - start_match < REQ_BYTE_MAX &&        end_subject - start_match < REQ_BYTE_MAX &&
5213        !md->partial)        !md->partial)
5214      {      {
# Line 4725  for(;;) Line 5252  for(;;)
5252        }        }
5253      }      }
5254    
5255    /* OK, we can now run the match. */    /* OK, we can now run the match. If "hitend" is set afterwards, remember the
5256      first starting point for which a partial match was found. */
5257    
5258    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
5259    md->match_call_count = 0;    md->match_call_count = 0;
5260    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);    rc = match(start_match, md->start_code, start_match, 2, md, ims, NULL, 0, 0);
5261      if (md->hitend && start_partial == NULL) start_partial = start_match;
5262    
5263    switch(rc)    switch(rc)
5264      {      {
# Line 4789  for(;;) Line 5318  for(;;)
5318    not contain any explicit matches for \r or \n, and the newline option is CRLF    not contain any explicit matches for \r or \n, and the newline option is CRLF
5319    or ANY or ANYCRLF, advance the match position by one more character. */    or ANY or ANYCRLF, advance the match position by one more character. */
5320    
5321    if (start_match[-1] == '\r' &&    if (start_match[-1] == CHAR_CR &&
5322        start_match < end_subject &&        start_match < end_subject &&
5323        *start_match == '\n' &&        *start_match == CHAR_NL &&
5324        (re->options & PCRE_HASCRORLF) == 0 &&        (re->flags & PCRE_HASCRORLF) == 0 &&
5325          (md->nltype == NLTYPE_ANY ||          (md->nltype == NLTYPE_ANY ||
5326           md->nltype == NLTYPE_ANYCRLF ||           md->nltype == NLTYPE_ANYCRLF ||
5327           md->nllen == 2))           md->nllen == 2))
# Line 4870  if (rc != MATCH_NOMATCH) Line 5399  if (rc != MATCH_NOMATCH)
5399    DPRINTF((">>>> error: returning %d\n", rc));    DPRINTF((">>>> error: returning %d\n", rc));
5400    return rc;    return rc;
5401    }    }
5402  else if (md->partial && md->hitend)  else if (md->partial && start_partial != NULL)
5403    {    {
5404    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
5405      if (offsetcount > 1)
5406        {
5407        offsets[0] = start_partial - (USPTR)subject;
5408        offsets[1] = end_subject - (USPTR)subject;
5409        }
5410    return PCRE_ERROR_PARTIAL;    return PCRE_ERROR_PARTIAL;
5411    }    }
5412  else  else

Legend:
Removed from v.227  
changed lines
  Added in v.426

  ViewVC Help
Powered by ViewVC 1.1.5