/[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 381 by ph10, Tue Mar 3 16:08:23 2009 UTC revision 461 by ph10, Mon Oct 5 10:59:35 2009 UTC
# Line 322  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 333  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 360  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 395  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). For hard partial matching, we then return
407    immediately. The second one is used when we already know we are past the end of
408    the subject. */
409    
410    #define CHECK_PARTIAL()\
411      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417  Performance note: It might be tempting to extract commonly used fields from the  #define SCHECK_PARTIAL()\
418  md structure (e.g. utf8, end_subject) into individual variables to improve    if (md->partial && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424    
425    /* Performance note: It might be tempting to extract commonly used fields from
426    the md structure (e.g. utf8, end_subject) into individual variables to improve
427  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
428  made performance worse.  made performance worse.
429    
# Line 425  Returns: MATCH_MATCH if matched Line 450  Returns: MATCH_MATCH if matched
450  */  */
451    
452  static int  static int
453  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
454    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
455    int flags, unsigned int rdepth)    int flags, unsigned int rdepth)
456  {  {
# Line 439  register unsigned int c; /* Character Line 464  register unsigned int c; /* Character
464  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
467    int condcode;
468    
469  /* 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
470  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 481  HEAP_RECURSE: Line 507  HEAP_RECURSE:
507  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
508  #endif  #endif
509  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
510    #define codelink           frame->Xcodelink
511  #define data               frame->Xdata  #define data               frame->Xdata
512  #define next               frame->Xnext  #define next               frame->Xnext
513  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 561  int oclength; Line 588  int oclength;
588  uschar occhars[8];  uschar occhars[8];
589  #endif  #endif
590    
591    int codelink;
592  int ctype;  int ctype;
593  int length;  int length;
594  int max;  int max;
# Line 636  for (;;) Line 664  for (;;)
664    minimize = possessive = FALSE;    minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
666    
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. */  
   
   if (md->partial &&  
       eptr >= md->end_subject &&  
       eptr > mstart)  
     md->hitend = TRUE;  
   
667    switch(op)    switch(op)
668      {      {
669      case OP_FAIL:      case OP_FAIL:
# Line 787  for (;;) Line 807  for (;;)
807    
808      case OP_COND:      case OP_COND:
809      case OP_SCOND:      case OP_SCOND:
810        codelink= GET(ecode, 1);
811    
812      /* Because of the way auto-callout works during compile, a callout item is      /* Because of the way auto-callout works during compile, a callout item is
813      inserted between OP_COND and an assertion condition. */      inserted between OP_COND and an assertion condition. */
814    
815      if (ecode[LINK_SIZE+1] == OP_CALLOUT)      if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816        {        {
817        if (pcre_callout != NULL)        if (pcre_callout != NULL)
# Line 812  for (;;) Line 834  for (;;)
834          }          }
835        ecode += _pcre_OP_lengths[OP_CALLOUT];        ecode += _pcre_OP_lengths[OP_CALLOUT];
836        }        }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840      /* Now see what the actual condition is */      /* Now see what the actual condition is */
841    
842      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
843        {        {
844        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        if (md->recursive == NULL)                /* Not recursing => FALSE */
845        condition = md->recursive != NULL &&          {
846          (offset == RREF_ANY || offset == md->recursive->group_num);          condition = FALSE;
847        ecode += condition? 3 : GET(ecode, 1);          ecode += GET(ecode, 1);
848            }
849          else
850            {
851            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
852            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
853    
854            /* If the test is for recursion into a specific subpattern, and it is
855            false, but the test was set up by name, scan the table to see if the
856            name refers to any other numbers, and test them. The condition is true
857            if any one is set. */
858    
859            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
860              {
861              uschar *slotA = md->name_table;
862              for (i = 0; i < md->name_count; i++)
863                {
864                if (GET2(slotA, 0) == recno) break;
865                slotA += md->name_entry_size;
866                }
867    
868              /* Found a name for the number - there can be only one; duplicate
869              names for different numbers are allowed, but not vice versa. First
870              scan down for duplicates. */
871    
872              if (i < md->name_count)
873                {
874                uschar *slotB = slotA;
875                while (slotB > md->name_table)
876                  {
877                  slotB -= md->name_entry_size;
878                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
879                    {
880                    condition = GET2(slotB, 0) == md->recursive->group_num;
881                    if (condition) break;
882                    }
883                  else break;
884                  }
885    
886                /* Scan up for duplicates */
887    
888                if (!condition)
889                  {
890                  slotB = slotA;
891                  for (i++; i < md->name_count; i++)
892                    {
893                    slotB += md->name_entry_size;
894                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
895                      {
896                      condition = GET2(slotB, 0) == md->recursive->group_num;
897                      if (condition) break;
898                      }
899                    else break;
900                    }
901                  }
902                }
903              }
904    
905            /* Chose branch according to the condition */
906    
907            ecode += condition? 3 : GET(ecode, 1);
908            }
909        }        }
910    
911      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
912        {        {
913        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
914        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
915    
916          /* If the numbered capture is unset, but the reference was by name,
917          scan the table to see if the name refers to any other numbers, and test
918          them. The condition is true if any one is set. This is tediously similar
919          to the code above, but not close enough to try to amalgamate. */
920    
921          if (!condition && condcode == OP_NCREF)
922            {
923            int refno = offset >> 1;
924            uschar *slotA = md->name_table;
925    
926            for (i = 0; i < md->name_count; i++)
927              {
928              if (GET2(slotA, 0) == refno) break;
929              slotA += md->name_entry_size;
930              }
931    
932            /* Found a name for the number - there can be only one; duplicate names
933            for different numbers are allowed, but not vice versa. First scan down
934            for duplicates. */
935    
936            if (i < md->name_count)
937              {
938              uschar *slotB = slotA;
939              while (slotB > md->name_table)
940                {
941                slotB -= md->name_entry_size;
942                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
943                  {
944                  offset = GET2(slotB, 0) << 1;
945                  condition = offset < offset_top &&
946                    md->offset_vector[offset] >= 0;
947                  if (condition) break;
948                  }
949                else break;
950                }
951    
952              /* Scan up for duplicates */
953    
954              if (!condition)
955                {
956                slotB = slotA;
957                for (i++; i < md->name_count; i++)
958                  {
959                  slotB += md->name_entry_size;
960                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
961                    {
962                    offset = GET2(slotB, 0) << 1;
963                    condition = offset < offset_top &&
964                      md->offset_vector[offset] >= 0;
965                    if (condition) break;
966                    }
967                  else break;
968                  }
969                }
970              }
971            }
972    
973          /* Chose branch according to the condition */
974    
975        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
976        }        }
977    
978      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
979        {        {
980        condition = FALSE;        condition = FALSE;
981        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 857  for (;;) Line 1002  for (;;)
1002        else        else
1003          {          {
1004          condition = FALSE;          condition = FALSE;
1005          ecode += GET(ecode, 1);          ecode += codelink;
1006          }          }
1007        }        }
1008    
# Line 880  for (;;) Line 1025  for (;;)
1025          goto TAIL_RECURSE;          goto TAIL_RECURSE;
1026          }          }
1027        }        }
1028      else                         /* Condition false & no 2nd alternative */      else                         /* Condition false & no alternative */
1029        {        {
1030        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1031        }        }
1032      break;      break;
1033    
1034    
1035        /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1036        to close any currently open capturing brackets. */
1037    
1038        case OP_CLOSE:
1039        number = GET2(ecode, 1);
1040        offset = number << 1;
1041    
1042    #ifdef DEBUG
1043          printf("end bracket %d at *ACCEPT", number);
1044          printf("\n");
1045    #endif
1046    
1047        md->capture_last = number;
1048        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1049          {
1050          md->offset_vector[offset] =
1051            md->offset_vector[md->offset_end - number];
1052          md->offset_vector[offset+1] = eptr - md->start_subject;
1053          if (offset_top <= offset) offset_top = offset + 2;
1054          }
1055        ecode += 3;
1056        break;
1057    
1058    
1059      /* End of the pattern, either real or forced. If we are in a top-level      /* End of the pattern, either real or forced. If we are in a top-level
1060      recursion, we should restore the offsets appropriately and continue from      recursion, we should restore the offsets appropriately and continue from
1061      after the call. */      after the call. */
# Line 900  for (;;) Line 1069  for (;;)
1069        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1070        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1071          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1072          offset_top = rec->save_offset_top;
1073        mstart = rec->save_start;        mstart = rec->save_start;
1074        ims = original_ims;        ims = original_ims;
1075        ecode = rec->after_call;        ecode = rec->after_call;
1076        break;        break;
1077        }        }
1078    
1079      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1080      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1081        the subject. In both cases, backtracking will then try other alternatives,
1082        if any. */
1083    
1084        if (eptr == mstart &&
1085            (md->notempty ||
1086              (md->notempty_atstart &&
1087                mstart == md->start_subject + md->start_offset)))
1088          RRETURN(MATCH_NOMATCH);
1089    
1090        /* Otherwise, we have a match. */
1091    
     if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);  
1092      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
1093      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1094      md->start_match_ptr = mstart;       /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
# Line 1000  for (;;) Line 1179  for (;;)
1179        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1180        }        }
1181    
1182      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1183    
1184        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1185      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1186      break;      break;
1187    
# Line 1081  for (;;) Line 1261  for (;;)
1261        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1262              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1263        new_recursive.save_start = mstart;        new_recursive.save_start = mstart;
1264          new_recursive.save_offset_top = offset_top;
1265        mstart = eptr;        mstart = eptr;
1266    
1267        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
# Line 1103  for (;;) Line 1284  for (;;)
1284          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1285            {            {
1286            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1287              if (new_recursive.offset_save != stacksave)
1288                (pcre_free)(new_recursive.offset_save);
1289            RRETURN(rrc);            RRETURN(rrc);
1290            }            }
1291    
# Line 1303  for (;;) Line 1486  for (;;)
1486          mstart = rec->save_start;          mstart = rec->save_start;
1487          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1488            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1489            offset_top = rec->save_offset_top;
1490          ecode = rec->after_call;          ecode = rec->after_call;
1491          ims = original_ims;          ims = original_ims;
1492          break;          break;
# Line 1442  for (;;) Line 1626  for (;;)
1626    
1627        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1628        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1629        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1630          partial matching. */
1631    
1632  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1633        if (utf8)        if (utf8)
1634          {          {
1635          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1636            {            {
1637            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1638            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1639              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1640            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1641            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1642            }            }
1643          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1644              {
1645              SCHECK_PARTIAL();
1646              cur_is_word = FALSE;
1647              }
1648            else
1649            {            {
1650            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1651            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1463  for (;;) Line 1654  for (;;)
1654        else        else
1655  #endif  #endif
1656    
1657        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1658    
1659          {          {
1660          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1661            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1662          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1663            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1664              }
1665            if (eptr >= md->end_subject)
1666              {
1667              SCHECK_PARTIAL();
1668              cur_is_word = FALSE;
1669              }
1670            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1671          }          }
1672    
1673        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1487  for (;;) Line 1685  for (;;)
1685      /* Fall through */      /* Fall through */
1686    
1687      case OP_ALLANY:      case OP_ALLANY:
1688      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1689          {
1690          SCHECK_PARTIAL();
1691          RRETURN(MATCH_NOMATCH);
1692          }
1693      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
1694      ecode++;      ecode++;
1695      break;      break;
# Line 1496  for (;;) Line 1698  for (;;)
1698      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1699    
1700      case OP_ANYBYTE:      case OP_ANYBYTE:
1701      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1702          {
1703          SCHECK_PARTIAL();
1704          RRETURN(MATCH_NOMATCH);
1705          }
1706      ecode++;      ecode++;
1707      break;      break;
1708    
1709      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1710      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1711          {
1712          SCHECK_PARTIAL();
1713          RRETURN(MATCH_NOMATCH);
1714          }
1715      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1716      if (      if (
1717  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1514  for (;;) Line 1724  for (;;)
1724      break;      break;
1725    
1726      case OP_DIGIT:      case OP_DIGIT:
1727      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1728          {
1729          SCHECK_PARTIAL();
1730          RRETURN(MATCH_NOMATCH);
1731          }
1732      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1733      if (      if (
1734  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1527  for (;;) Line 1741  for (;;)
1741      break;      break;
1742    
1743      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1744      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1745          {
1746          SCHECK_PARTIAL();
1747          RRETURN(MATCH_NOMATCH);
1748          }
1749      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1750      if (      if (
1751  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1540  for (;;) Line 1758  for (;;)
1758      break;      break;
1759    
1760      case OP_WHITESPACE:      case OP_WHITESPACE:
1761      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1762          {
1763          SCHECK_PARTIAL();
1764          RRETURN(MATCH_NOMATCH);
1765          }
1766      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1767      if (      if (
1768  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1553  for (;;) Line 1775  for (;;)
1775      break;      break;
1776    
1777      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1778      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1779          {
1780          SCHECK_PARTIAL();
1781          RRETURN(MATCH_NOMATCH);
1782          }
1783      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1784      if (      if (
1785  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1566  for (;;) Line 1792  for (;;)
1792      break;      break;
1793    
1794      case OP_WORDCHAR:      case OP_WORDCHAR:
1795      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1796          {
1797          SCHECK_PARTIAL();
1798          RRETURN(MATCH_NOMATCH);
1799          }
1800      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1801      if (      if (
1802  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1579  for (;;) Line 1809  for (;;)
1809      break;      break;
1810    
1811      case OP_ANYNL:      case OP_ANYNL:
1812      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1813          {
1814          SCHECK_PARTIAL();
1815          RRETURN(MATCH_NOMATCH);
1816          }
1817      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1818      switch(c)      switch(c)
1819        {        {
# Line 1603  for (;;) Line 1837  for (;;)
1837      break;      break;
1838    
1839      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
1840      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1841          {
1842          SCHECK_PARTIAL();
1843          RRETURN(MATCH_NOMATCH);
1844          }
1845      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1846      switch(c)      switch(c)
1847        {        {
# Line 1633  for (;;) Line 1871  for (;;)
1871      break;      break;
1872    
1873      case OP_HSPACE:      case OP_HSPACE:
1874      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1875          {
1876          SCHECK_PARTIAL();
1877          RRETURN(MATCH_NOMATCH);
1878          }
1879      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1880      switch(c)      switch(c)
1881        {        {
# Line 1663  for (;;) Line 1905  for (;;)
1905      break;      break;
1906    
1907      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
1908      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1909          {
1910          SCHECK_PARTIAL();
1911          RRETURN(MATCH_NOMATCH);
1912          }
1913      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1914      switch(c)      switch(c)
1915        {        {
# Line 1681  for (;;) Line 1927  for (;;)
1927      break;      break;
1928    
1929      case OP_VSPACE:      case OP_VSPACE:
1930      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1931          {
1932          SCHECK_PARTIAL();
1933          RRETURN(MATCH_NOMATCH);
1934          }
1935      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1936      switch(c)      switch(c)
1937        {        {
# Line 1704  for (;;) Line 1954  for (;;)
1954    
1955      case OP_PROP:      case OP_PROP:
1956      case OP_NOTPROP:      case OP_NOTPROP:
1957      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1958          {
1959          SCHECK_PARTIAL();
1960          RRETURN(MATCH_NOMATCH);
1961          }
1962      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1963        {        {
1964        const ucd_record * prop = GET_UCD(c);        const ucd_record *prop = GET_UCD(c);
1965    
1966        switch(ecode[1])        switch(ecode[1])
1967          {          {
# Line 1749  for (;;) Line 2003  for (;;)
2003      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2004    
2005      case OP_EXTUNI:      case OP_EXTUNI:
2006      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2007          {
2008          SCHECK_PARTIAL();
2009          RRETURN(MATCH_NOMATCH);
2010          }
2011      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2012        {        {
2013        int category = UCD_CATEGORY(c);        int category = UCD_CATEGORY(c);
# Line 1829  for (;;) Line 2087  for (;;)
2087          break;          break;
2088    
2089          default:               /* No repeat follows */          default:               /* No repeat follows */
2090          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2091              {
2092              CHECK_PARTIAL();
2093              RRETURN(MATCH_NOMATCH);
2094              }
2095          eptr += length;          eptr += length;
2096          continue;              /* With the main loop */          continue;              /* With the main loop */
2097          }          }
# Line 1845  for (;;) Line 2107  for (;;)
2107    
2108        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2109          {          {
2110          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2111              {
2112              CHECK_PARTIAL();
2113              RRETURN(MATCH_NOMATCH);
2114              }
2115          eptr += length;          eptr += length;
2116          }          }
2117    
# Line 1862  for (;;) Line 2128  for (;;)
2128            {            {
2129            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2130            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2131            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
2132              if (!match_ref(offset, eptr, length, md, ims))
2133                {
2134                CHECK_PARTIAL();
2135              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2136                }
2137            eptr += length;            eptr += length;
2138            }            }
2139          /* Control never gets here */          /* Control never gets here */
# Line 1890  for (;;) Line 2160  for (;;)
2160        }        }
2161      /* Control never gets here */      /* Control never gets here */
2162    
   
   
2163      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2164      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2165      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1946  for (;;) Line 2214  for (;;)
2214          {          {
2215          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2216            {            {
2217            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2218                {
2219                SCHECK_PARTIAL();
2220                RRETURN(MATCH_NOMATCH);
2221                }
2222            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2223            if (c > 255)            if (c > 255)
2224              {              {
# Line 1964  for (;;) Line 2236  for (;;)
2236          {          {
2237          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2238            {            {
2239            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2240                {
2241                SCHECK_PARTIAL();
2242                RRETURN(MATCH_NOMATCH);
2243                }
2244            c = *eptr++;            c = *eptr++;
2245            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2246            }            }
# Line 1988  for (;;) Line 2264  for (;;)
2264              {              {
2265              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2266              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2267              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2268                if (eptr >= md->end_subject)
2269                  {
2270                  SCHECK_PARTIAL();
2271                  RRETURN(MATCH_NOMATCH);
2272                  }
2273              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2274              if (c > 255)              if (c > 255)
2275                {                {
# Line 2008  for (;;) Line 2289  for (;;)
2289              {              {
2290              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2291              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2292              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2293                if (eptr >= md->end_subject)
2294                  {
2295                  SCHECK_PARTIAL();
2296                  RRETURN(MATCH_NOMATCH);
2297                  }
2298              c = *eptr++;              c = *eptr++;
2299              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2300              }              }
# Line 2075  for (;;) Line 2361  for (;;)
2361    
2362    
2363      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2364      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
2365        mode, because Unicode properties are supported in non-UTF-8 mode. */
2366    
2367  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2368      case OP_XCLASS:      case OP_XCLASS:
# Line 2116  for (;;) Line 2403  for (;;)
2403    
2404        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2405          {          {
2406          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2407          GETCHARINC(c, eptr);            {
2408              SCHECK_PARTIAL();
2409              RRETURN(MATCH_NOMATCH);
2410              }
2411            GETCHARINCTEST(c, eptr);
2412          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2413          }          }
2414    
# Line 2135  for (;;) Line 2426  for (;;)
2426            {            {
2427            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2428            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2429            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2430            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2431                {
2432                SCHECK_PARTIAL();
2433                RRETURN(MATCH_NOMATCH);
2434                }
2435              GETCHARINCTEST(c, eptr);
2436            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2437            }            }
2438          /* Control never gets here */          /* Control never gets here */
# Line 2151  for (;;) Line 2447  for (;;)
2447            {            {
2448            int len = 1;            int len = 1;
2449            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2450            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2451            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2452            eptr += len;            eptr += len;
2453            }            }
# Line 2178  for (;;) Line 2474  for (;;)
2474        length = 1;        length = 1;
2475        ecode++;        ecode++;
2476        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2477        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2478            {
2479            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2480            RRETURN(MATCH_NOMATCH);
2481            }
2482        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2483        }        }
2484      else      else
# Line 2186  for (;;) Line 2486  for (;;)
2486    
2487      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2488        {        {
2489        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2490            {
2491            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2492            RRETURN(MATCH_NOMATCH);
2493            }
2494        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2495        ecode += 2;        ecode += 2;
2496        }        }
# Line 2202  for (;;) Line 2506  for (;;)
2506        ecode++;        ecode++;
2507        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2508    
2509        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2510            {
2511            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2512            RRETURN(MATCH_NOMATCH);
2513            }
2514    
2515        /* If the pattern character's value is < 128, we have only one byte, and        /* If the pattern character's value is < 128, we have only one byte, and
2516        can use the fast lookup table. */        can use the fast lookup table. */
# Line 2237  for (;;) Line 2545  for (;;)
2545    
2546      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2547        {        {
2548        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2549            {
2550            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2551            RRETURN(MATCH_NOMATCH);
2552            }
2553        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2554        ecode += 2;        ecode += 2;
2555        }        }
# Line 2291  for (;;) Line 2603  for (;;)
2603      case OP_MINQUERY:      case OP_MINQUERY:
2604      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2605      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2606    
2607      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2608      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2609      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2610    
2611      /* 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. */  
2612    
2613      REPEATCHAR:      REPEATCHAR:
2614  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2306  for (;;) Line 2617  for (;;)
2617        length = 1;        length = 1;
2618        charptr = ecode;        charptr = ecode;
2619        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2620        ecode += length;        ecode += length;
2621    
2622        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2324  for (;;) Line 2634  for (;;)
2634    
2635          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2636            {            {
2637            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2638                memcmp(eptr, charptr, length) == 0) eptr += length;
2639  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2640            /* Need braces because of following else */            else if (oclength > 0 &&
2641            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                     eptr <= md->end_subject - oclength &&
2642                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2643    #endif  /* SUPPORT_UCP */
2644            else            else
2645              {              {
2646              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2647              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2648              }              }
 #else   /* without SUPPORT_UCP */  
           else { RRETURN(MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2649            }            }
2650    
2651          if (min == max) continue;          if (min == max) continue;
# Line 2346  for (;;) Line 2656  for (;;)
2656              {              {
2657              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2658              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2659              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2660              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2661                  memcmp(eptr, charptr, length) == 0) eptr += length;
2662  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2663              /* Need braces because of following else */              else if (oclength > 0 &&
2664              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                       eptr <= md->end_subject - oclength &&
2665                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2666    #endif  /* SUPPORT_UCP */
2667              else              else
2668                {                {
2669                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2670                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2671                }                }
 #else   /* without SUPPORT_UCP */  
             else { RRETURN (MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2672              }              }
2673            /* Control never gets here */            /* Control never gets here */
2674            }            }
# Line 2368  for (;;) Line 2678  for (;;)
2678            pp = eptr;            pp = eptr;
2679            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2680              {              {
2681              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2682              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2683  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2684              else if (oclength == 0) break;              else if (oclength > 0 &&
2685              else                       eptr <= md->end_subject - oclength &&
2686                {                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
               if (memcmp(eptr, occhars, oclength) != 0) break;  
               eptr += oclength;  
               }  
 #else   /* without SUPPORT_UCP */  
             else break;  
2687  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2688                else break;
2689              }              }
2690    
2691            if (possessive) continue;            if (possessive) continue;
2692    
2693            for(;;)            for(;;)
2694             {              {
2695             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2696             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2697             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2698  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2699             eptr--;              eptr--;
2700             BACKCHAR(eptr);              BACKCHAR(eptr);
2701  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2702             eptr -= length;              eptr -= length;
2703  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2704             }              }
2705            }            }
2706          /* Control never gets here */          /* Control never gets here */
2707          }          }
# Line 2407  for (;;) Line 2714  for (;;)
2714  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2715    
2716      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2717        {  
2718        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2719    
2720      /* 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
2721      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 2428  for (;;) Line 2733  for (;;)
2733        {        {
2734        fc = md->lcc[fc];        fc = md->lcc[fc];
2735        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2736            {
2737            if (eptr >= md->end_subject)
2738              {
2739              SCHECK_PARTIAL();
2740              RRETURN(MATCH_NOMATCH);
2741              }
2742          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2743            }
2744        if (min == max) continue;        if (min == max) continue;
2745        if (minimize)        if (minimize)
2746          {          {
# Line 2436  for (;;) Line 2748  for (;;)
2748            {            {
2749            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2750            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2751            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2752                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2753                {
2754                SCHECK_PARTIAL();
2755              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2756                }
2757              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2758            }            }
2759          /* Control never gets here */          /* Control never gets here */
2760          }          }
# Line 2450  for (;;) Line 2766  for (;;)
2766            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2767            eptr++;            eptr++;
2768            }            }
2769    
2770          if (possessive) continue;          if (possessive) continue;
2771    
2772          while (eptr >= pp)          while (eptr >= pp)
2773            {            {
2774            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
# Line 2466  for (;;) Line 2784  for (;;)
2784    
2785      else      else
2786        {        {
2787        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2788            {
2789            if (eptr >= md->end_subject)
2790              {
2791              SCHECK_PARTIAL();
2792              RRETURN(MATCH_NOMATCH);
2793              }
2794            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2795            }
2796    
2797        if (min == max) continue;        if (min == max) continue;
2798    
2799        if (minimize)        if (minimize)
2800          {          {
2801          for (fi = min;; fi++)          for (fi = min;; fi++)
2802            {            {
2803            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2804            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2805            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2806              if (eptr >= md->end_subject)
2807                {
2808                SCHECK_PARTIAL();
2809              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2810                }
2811              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2812            }            }
2813          /* Control never gets here */          /* Control never gets here */
2814          }          }
# Line 2488  for (;;) Line 2821  for (;;)
2821            eptr++;            eptr++;
2822            }            }
2823          if (possessive) continue;          if (possessive) continue;
2824    
2825          while (eptr >= pp)          while (eptr >= pp)
2826            {            {
2827            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
# Line 2503  for (;;) Line 2837  for (;;)
2837      checking can be multibyte. */      checking can be multibyte. */
2838    
2839      case OP_NOT:      case OP_NOT:
2840      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2841          {
2842          SCHECK_PARTIAL();
2843          RRETURN(MATCH_NOMATCH);
2844          }
2845      ecode++;      ecode++;
2846      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2847      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2580  for (;;) Line 2918  for (;;)
2918      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2919      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2920    
2921      /* 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. */  
2922    
2923      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2924      fc = *ecode++;      fc = *ecode++;
2925    
2926      /* 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 2610  for (;;) Line 2945  for (;;)
2945          register unsigned int d;          register unsigned int d;
2946          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2947            {            {
2948              if (eptr >= md->end_subject)
2949                {
2950                SCHECK_PARTIAL();
2951                RRETURN(MATCH_NOMATCH);
2952                }
2953            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2954            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2955            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2621  for (;;) Line 2961  for (;;)
2961        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2962          {          {
2963          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2964              {
2965              if (eptr >= md->end_subject)
2966                {
2967                SCHECK_PARTIAL();
2968                RRETURN(MATCH_NOMATCH);
2969                }
2970            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2971              }
2972          }          }
2973    
2974        if (min == max) continue;        if (min == max) continue;
# Line 2637  for (;;) Line 2984  for (;;)
2984              {              {
2985              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2986              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2987              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2988                if (eptr >= md->end_subject)
2989                  {
2990                  SCHECK_PARTIAL();
2991                  RRETURN(MATCH_NOMATCH);
2992                  }
2993              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2994              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2995              if (fc == d) RRETURN(MATCH_NOMATCH);              if (fc == d) RRETURN(MATCH_NOMATCH);
   
2996              }              }
2997            }            }
2998          else          else
# Line 2652  for (;;) Line 3003  for (;;)
3003              {              {
3004              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3005              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3006              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
3007                if (eptr >= md->end_subject)
3008                  {
3009                  SCHECK_PARTIAL();
3010                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3011                  }
3012                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
3013              }              }
3014            }            }
3015          /* Control never gets here */          /* Control never gets here */
# Line 2722  for (;;) Line 3078  for (;;)
3078          register unsigned int d;          register unsigned int d;
3079          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3080            {            {
3081              if (eptr >= md->end_subject)
3082                {
3083                SCHECK_PARTIAL();
3084                RRETURN(MATCH_NOMATCH);
3085                }
3086            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3087            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
3088            }            }
# Line 2731  for (;;) Line 3092  for (;;)
3092        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3093          {          {
3094          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3095              {
3096              if (eptr >= md->end_subject)
3097                {
3098                SCHECK_PARTIAL();
3099                RRETURN(MATCH_NOMATCH);
3100                }
3101            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3102              }
3103          }          }
3104    
3105        if (min == max) continue;        if (min == max) continue;
# Line 2747  for (;;) Line 3115  for (;;)
3115              {              {
3116              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3117              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3118              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3119                if (eptr >= md->end_subject)
3120                  {
3121                  SCHECK_PARTIAL();
3122                  RRETURN(MATCH_NOMATCH);
3123                  }
3124              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3125              if (fc == d) RRETURN(MATCH_NOMATCH);              if (fc == d) RRETURN(MATCH_NOMATCH);
3126              }              }
# Line 2760  for (;;) Line 3133  for (;;)
3133              {              {
3134              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3135              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3136              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
3137                if (eptr >= md->end_subject)
3138                  {
3139                  SCHECK_PARTIAL();
3140                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3141                  }
3142                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3143              }              }
3144            }            }
3145          /* Control never gets here */          /* Control never gets here */
# Line 2895  for (;;) Line 3273  for (;;)
3273    
3274      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3275      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
3276      (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  
3277      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
3278      and single-bytes. */      and single-bytes. */
3279    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3280      if (min > 0)      if (min > 0)
3281        {        {
3282  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2913  for (;;) Line 3288  for (;;)
3288            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3289            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3290              {              {
3291              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3292                  {
3293                  SCHECK_PARTIAL();
3294                  RRETURN(MATCH_NOMATCH);
3295                  }
3296              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3297              }              }
3298            break;            break;
# Line 2921  for (;;) Line 3300  for (;;)
3300            case PT_LAMP:            case PT_LAMP:
3301            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3302              {              {
3303              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3304                  {
3305                  SCHECK_PARTIAL();
3306                  RRETURN(MATCH_NOMATCH);
3307                  }
3308              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3309              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3310              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 2934  for (;;) Line 3317  for (;;)
3317            case PT_GC:            case PT_GC:
3318            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3319              {              {
3320              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3321                  {
3322                  SCHECK_PARTIAL();
3323                  RRETURN(MATCH_NOMATCH);
3324                  }
3325              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3326              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
3327              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 2945  for (;;) Line 3332  for (;;)
3332            case PT_PC:            case PT_PC:
3333            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3334              {              {
3335              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3336                  {
3337                  SCHECK_PARTIAL();
3338                  RRETURN(MATCH_NOMATCH);
3339                  }
3340              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3341              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3342              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 2956  for (;;) Line 3347  for (;;)
3347            case PT_SC:            case PT_SC:
3348            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3349              {              {
3350              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3351                  {
3352                  SCHECK_PARTIAL();
3353                  RRETURN(MATCH_NOMATCH);
3354                  }
3355              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3356              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
3357              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 2976  for (;;) Line 3371  for (;;)
3371          {          {
3372          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3373            {            {
3374              if (eptr >= md->end_subject)
3375                {
3376                SCHECK_PARTIAL();
3377                RRETURN(MATCH_NOMATCH);
3378                }
3379            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3380            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
3381            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3382            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3383              {              {
3384              int len = 1;              int len = 1;
3385              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3386                {                else { GETCHARLEN(c, eptr, len); }
               GETCHARLEN(c, eptr, len);  
               }  
3387              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
3388              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3389              eptr += len;              eptr += len;
# Line 3004  for (;;) Line 3402  for (;;)
3402          case OP_ANY:          case OP_ANY:
3403          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3404            {            {
3405            if (eptr >= md->end_subject || IS_NEWLINE(eptr))            if (eptr >= md->end_subject)
3406                {
3407                SCHECK_PARTIAL();
3408              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3409                }
3410              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3411            eptr++;            eptr++;
3412            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3413            }            }
# Line 3014  for (;;) Line 3416  for (;;)
3416          case OP_ALLANY:          case OP_ALLANY:
3417          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3418            {            {
3419            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3420                {
3421                SCHECK_PARTIAL();
3422                RRETURN(MATCH_NOMATCH);
3423                }
3424            eptr++;            eptr++;
3425            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3426            }            }
3427          break;          break;
3428    
3429          case OP_ANYBYTE:          case OP_ANYBYTE:
3430            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3431          eptr += min;          eptr += min;
3432          break;          break;
3433    
3434          case OP_ANYNL:          case OP_ANYNL:
3435          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3436            {            {
3437            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3438                {
3439                SCHECK_PARTIAL();
3440                RRETURN(MATCH_NOMATCH);
3441                }
3442            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3443            switch(c)            switch(c)
3444              {              {
# Line 3053  for (;;) Line 3464  for (;;)
3464          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
3465          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3466            {            {
3467            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3468                {
3469                SCHECK_PARTIAL();
3470                RRETURN(MATCH_NOMATCH);
3471                }
3472            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3473            switch(c)            switch(c)
3474              {              {
# Line 3085  for (;;) Line 3500  for (;;)
3500          case OP_HSPACE:          case OP_HSPACE:
3501          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3502            {            {
3503            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3504                {
3505                SCHECK_PARTIAL();
3506                RRETURN(MATCH_NOMATCH);
3507                }
3508            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3509            switch(c)            switch(c)
3510              {              {
# Line 3117  for (;;) Line 3536  for (;;)
3536          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3537          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3538            {            {
3539            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3540                {
3541                SCHECK_PARTIAL();
3542                RRETURN(MATCH_NOMATCH);
3543                }
3544            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3545            switch(c)            switch(c)
3546              {              {
# Line 3137  for (;;) Line 3560  for (;;)
3560          case OP_VSPACE:          case OP_VSPACE:
3561          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3562            {            {
3563            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3564                {
3565                SCHECK_PARTIAL();
3566                RRETURN(MATCH_NOMATCH);
3567                }
3568            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3569            switch(c)            switch(c)
3570              {              {
# Line 3157  for (;;) Line 3584  for (;;)
3584          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3585          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3586            {            {
3587            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3588                {
3589                SCHECK_PARTIAL();
3590                RRETURN(MATCH_NOMATCH);
3591                }
3592            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3593            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3594              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 3167  for (;;) Line 3598  for (;;)
3598          case OP_DIGIT:          case OP_DIGIT:
3599          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3600            {            {
3601            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3602               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3603                SCHECK_PARTIAL();
3604                RRETURN(MATCH_NOMATCH);
3605                }
3606              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3607              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3608            /* 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 */
3609            }            }
# Line 3177  for (;;) Line 3612  for (;;)
3612          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3613          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3614            {            {
3615            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3616               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))              {
3617                SCHECK_PARTIAL();
3618                RRETURN(MATCH_NOMATCH);
3619                }
3620              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3621              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3622            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3623            }            }
# Line 3187  for (;;) Line 3626  for (;;)
3626          case OP_WHITESPACE:          case OP_WHITESPACE:
3627          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3628            {            {
3629            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3630               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3631                SCHECK_PARTIAL();
3632                RRETURN(MATCH_NOMATCH);
3633                }
3634              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3635              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3636            /* 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 */
3637            }            }
# Line 3207  for (;;) Line 3650  for (;;)
3650          case OP_WORDCHAR:          case OP_WORDCHAR:
3651          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3652            {            {
3653            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3654               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3655                SCHECK_PARTIAL();
3656                RRETURN(MATCH_NOMATCH);
3657                }
3658              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3659              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3660            /* 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 */
3661            }            }
# Line 3222  for (;;) Line 3669  for (;;)
3669  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3670    
3671        /* 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
3672        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. */  
3673    
3674        switch(ctype)        switch(ctype)
3675          {          {
3676          case OP_ANY:          case OP_ANY:
3677          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3678            {            {
3679              if (eptr >= md->end_subject)
3680                {
3681                SCHECK_PARTIAL();
3682                RRETURN(MATCH_NOMATCH);
3683                }
3684            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3685            eptr++;            eptr++;
3686            }            }
3687          break;          break;
3688    
3689          case OP_ALLANY:          case OP_ALLANY:
3690            if (eptr > md->end_subject - min)
3691              {
3692              SCHECK_PARTIAL();
3693              RRETURN(MATCH_NOMATCH);
3694              }
3695          eptr += min;          eptr += min;
3696          break;          break;
3697    
3698          case OP_ANYBYTE:          case OP_ANYBYTE:
3699            if (eptr > md->end_subject - min)
3700              {
3701              SCHECK_PARTIAL();
3702              RRETURN(MATCH_NOMATCH);
3703              }
3704          eptr += min;          eptr += min;
3705          break;          break;
3706    
         /* Because of the CRLF case, we can't assume the minimum number of  
         bytes are present in this case. */  
   
3707          case OP_ANYNL:          case OP_ANYNL:
3708          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3709            {            {
3710            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3711                {
3712                SCHECK_PARTIAL();
3713                RRETURN(MATCH_NOMATCH);
3714                }
3715            switch(*eptr++)            switch(*eptr++)
3716              {              {
3717              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3271  for (;;) Line 3733  for (;;)
3733          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
3734          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3735            {            {
3736            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3737                {
3738                SCHECK_PARTIAL();
3739                RRETURN(MATCH_NOMATCH);
3740                }
3741            switch(*eptr++)            switch(*eptr++)
3742              {              {
3743              default: break;              default: break;
# Line 3286  for (;;) Line 3752  for (;;)
3752          case OP_HSPACE:          case OP_HSPACE:
3753          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3754            {            {
3755            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3756                {
3757                SCHECK_PARTIAL();
3758                RRETURN(MATCH_NOMATCH);
3759                }
3760            switch(*eptr++)            switch(*eptr++)
3761              {              {
3762              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3301  for (;;) Line 3771  for (;;)
3771          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3772          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3773            {            {
3774            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3775                {
3776                SCHECK_PARTIAL();
3777                RRETURN(MATCH_NOMATCH);
3778                }
3779            switch(*eptr++)            switch(*eptr++)
3780              {              {
3781              default: break;              default: break;
# Line 3318  for (;;) Line 3792  for (;;)
3792          case OP_VSPACE:          case OP_VSPACE:
3793          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3794            {            {
3795            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3796                {
3797                SCHECK_PARTIAL();
3798                RRETURN(MATCH_NOMATCH);
3799                }
3800            switch(*eptr++)            switch(*eptr++)
3801              {              {
3802              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3334  for (;;) Line 3812  for (;;)
3812    
3813          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3814          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3815              {
3816              if (eptr >= md->end_subject)
3817                {
3818                SCHECK_PARTIAL();
3819                RRETURN(MATCH_NOMATCH);
3820                }
3821            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3822              }
3823          break;          break;
3824    
3825          case OP_DIGIT:          case OP_DIGIT:
3826          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3827              {
3828              if (eptr >= md->end_subject)
3829                {
3830                SCHECK_PARTIAL();
3831                RRETURN(MATCH_NOMATCH);
3832                }
3833            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3834              }
3835          break;          break;
3836    
3837          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3838          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3839              {
3840              if (eptr >= md->end_subject)
3841                {
3842                SCHECK_PARTIAL();
3843                RRETURN(MATCH_NOMATCH);
3844                }
3845            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3846              }
3847          break;          break;
3848    
3849          case OP_WHITESPACE:          case OP_WHITESPACE:
3850          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3851              {
3852              if (eptr >= md->end_subject)
3853                {
3854                SCHECK_PARTIAL();
3855                RRETURN(MATCH_NOMATCH);
3856                }
3857            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3858              }
3859          break;          break;
3860    
3861          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3862          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3863              {
3864              if (eptr >= md->end_subject)
3865                {
3866                SCHECK_PARTIAL();
3867                RRETURN(MATCH_NOMATCH);
3868                }
3869            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3870              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3871              }
3872          break;          break;
3873    
3874          case OP_WORDCHAR:          case OP_WORDCHAR:
3875          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3876              {
3877              if (eptr >= md->end_subject)
3878                {
3879                SCHECK_PARTIAL();
3880                RRETURN(MATCH_NOMATCH);
3881                }
3882            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3883              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3884              }
3885          break;          break;
3886    
3887          default:          default:
# Line 3389  for (;;) Line 3909  for (;;)
3909              {              {
3910              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3911              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3912              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3913                if (eptr >= md->end_subject)
3914                  {
3915                  SCHECK_PARTIAL();
3916                  RRETURN(MATCH_NOMATCH);
3917                  }
3918              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3919              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3920              }              }
# Line 3400  for (;;) Line 3925  for (;;)
3925              {              {
3926              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3927              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3928              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3929                if (eptr >= md->end_subject)
3930                  {
3931                  SCHECK_PARTIAL();
3932                  RRETURN(MATCH_NOMATCH);
3933                  }
3934              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3935              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3936              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 3415  for (;;) Line 3945  for (;;)
3945              {              {
3946              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3947              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3948              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3949                if (eptr >= md->end_subject)
3950                  {
3951                  SCHECK_PARTIAL();
3952                  RRETURN(MATCH_NOMATCH);
3953                  }
3954              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3955              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
3956              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 3428  for (;;) Line 3963  for (;;)
3963              {              {
3964              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3965              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3966              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3967                if (eptr >= md->end_subject)
3968                  {
3969                  SCHECK_PARTIAL();
3970                  RRETURN(MATCH_NOMATCH);
3971                  }
3972              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3973              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3974              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 3441  for (;;) Line 3981  for (;;)
3981              {              {
3982              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3983              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3984              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3985                if (eptr >= md->end_subject)
3986                  {
3987                  SCHECK_PARTIAL();
3988                  RRETURN(MATCH_NOMATCH);
3989                  }
3990              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3991              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
3992              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 3463  for (;;) Line 4008  for (;;)
4008            {            {
4009            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
4010            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4011            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
4012              if (eptr >= md->end_subject)
4013                {
4014                SCHECK_PARTIAL();
4015                RRETURN(MATCH_NOMATCH);
4016                }
4017            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4018            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
4019            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
4020            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4021              {              {
4022              int len = 1;              int len = 1;
4023              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
4024                {                else { GETCHARLEN(c, eptr, len); }
               GETCHARLEN(c, eptr, len);  
               }  
4025              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4026              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4027              eptr += len;              eptr += len;
# Line 3492  for (;;) Line 4040  for (;;)
4040            {            {
4041            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
4042            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4043            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4044                 (ctype == OP_ANY && IS_NEWLINE(eptr)))            if (eptr >= md->end_subject)
4045                {
4046                SCHECK_PARTIAL();
4047                RRETURN(MATCH_NOMATCH);
4048                }
4049              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4050              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4051            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4052            switch(ctype)            switch(ctype)
4053              {              {
# Line 3651  for (;;) Line 4203  for (;;)
4203            {            {
4204            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4205            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4206            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4207                 (ctype == OP_ANY && IS_NEWLINE(eptr)))            if (eptr >= md->end_subject)
4208                {
4209                SCHECK_PARTIAL();
4210                RRETURN(MATCH_NOMATCH);
4211                }
4212              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4213              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4214            c = *eptr++;            c = *eptr++;
4215            switch(ctype)            switch(ctype)
4216              {              {
# Line 4437  const uschar *tables; Line 4993  const uschar *tables;
4993  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4994  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4995  USPTR end_subject;  USPTR end_subject;
4996    USPTR start_partial = NULL;
4997  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
4998    
4999  pcre_study_data internal_study;  pcre_study_data internal_study;
# Line 4453  if (re == NULL || subject == NULL || Line 5010  if (re == NULL || subject == NULL ||
5010     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
5011  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5012    
5013    /* This information is for finding all the numbers associated with a given
5014    name, for condition testing. */
5015    
5016    md->name_table = (uschar *)re + re->name_table_offset;
5017    md->name_count = re->name_count;
5018    md->name_entry_size = re->name_entry_size;
5019    
5020  /* Fish out the optional data from the extra_data structure, first setting  /* Fish out the optional data from the extra_data structure, first setting
5021  the default values. */  the default values. */
5022    
# Line 4520  md->jscript_compat = (re->options & PCRE Line 5084  md->jscript_compat = (re->options & PCRE
5084  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
5085  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
5086  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
5087  md->partial = (options & PCRE_PARTIAL) != 0;  md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
5088    md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
5089                  ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
5090  md->hitend = FALSE;  md->hitend = FALSE;
5091    
5092  md->recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
# Line 4561  switch ((((options & PCRE_NEWLINE_BITS) Line 5127  switch ((((options & PCRE_NEWLINE_BITS)
5127          (pcre_uint32)options) & PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
5128    {    {
5129    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
5130    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
5131    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
5132    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
5133         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
5134    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
5135    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
5136    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 4594  else Line 5160  else
5160      }      }
5161    }    }
5162    
5163  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching was originally supported only for a restricted set of
5164  moment. */  regexes; from release 8.00 there are no restrictions, but the bits are still
5165    defined (though never set). So there's no harm in leaving this code. */
5166    
5167  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
5168    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
# Line 4606  back the character offset. */ Line 5173  back the character offset. */
5173  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5174  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
5175    {    {
5176    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((USPTR)subject, length) >= 0)
5177      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
5178    if (start_offset > 0 && start_offset < length)    if (start_offset > 0 && start_offset < length)
5179      {      {
5180      int tb = ((uschar *)subject)[start_offset];      int tb = ((USPTR)subject)[start_offset];
5181      if (tb > 127)      if (tb > 127)
5182        {        {
5183        tb &= 0xc0;        tb &= 0xc0;
# Line 4682  if (!anchored) Line 5249  if (!anchored)
5249      }      }
5250    else    else
5251      if (!startline && study != NULL &&      if (!startline && study != NULL &&
5252        (study->options & PCRE_STUDY_MAPPED) != 0)        (study->flags & PCRE_STUDY_MAPPED) != 0)
5253          start_bits = study->start_bits;          start_bits = study->start_bits;
5254    }    }
5255    
# Line 4716  for(;;) Line 5283  for(;;)
5283      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
5284      }      }
5285    
5286    /* 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
5287    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
5288    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
5289    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
5290    the match fails at the newline, later code breaks this loop. */    this loop. */
5291    
5292    if (firstline)    if (firstline)
5293      {      {
# Line 4740  for(;;) Line 5307  for(;;)
5307      end_subject = t;      end_subject = t;
5308      }      }
5309    
5310    /* Now advance to a unique first byte if there is one. */    /* There are some optimizations that avoid running the match if a known
5311      starting point is not found, or if a known later character is not present.
5312      However, there is an option that disables these, for testing and for ensuring
5313      that all callouts do actually occur. */
5314    
5315    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
5316      {      {
5317      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
5318        while (start_match < end_subject && md->lcc[*start_match] != first_byte)  
5319          start_match++;      if (first_byte >= 0)
5320      else        {
5321        while (start_match < end_subject && *start_match != first_byte)        if (first_byte_caseless)
5322          start_match++;          while (start_match < end_subject && md->lcc[*start_match] != first_byte)
5323      }            start_match++;
5324          else
5325            while (start_match < end_subject && *start_match != first_byte)
5326              start_match++;
5327          }
5328    
5329    /* Or to just after a linebreak for a multiline match */      /* Or to just after a linebreak for a multiline match */
5330    
5331    else if (startline)      else if (startline)
     {  
     if (start_match > md->start_subject + start_offset)  
5332        {        {
5333  #ifdef SUPPORT_UTF8        if (start_match > md->start_subject + start_offset)
       if (utf8)  
5334          {          {
5335          while (start_match < end_subject && !WAS_NEWLINE(start_match))  #ifdef SUPPORT_UTF8
5336            if (utf8)
5337            {            {
5338            start_match++;            while (start_match < end_subject && !WAS_NEWLINE(start_match))
5339            while(start_match < end_subject && (*start_match & 0xc0) == 0x80)              {
5340              start_match++;              start_match++;
5341                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
5342                  start_match++;
5343                }
5344            }            }
5345          }          else
       else  
5346  #endif  #endif
5347        while (start_match < end_subject && !WAS_NEWLINE(start_match))          while (start_match < end_subject && !WAS_NEWLINE(start_match))
5348          start_match++;            start_match++;
5349    
5350        /* If we have just passed a CR and the newline option is ANY or ANYCRLF,          /* If we have just passed a CR and the newline option is ANY or ANYCRLF,
5351        and we are now at a LF, advance the match position by one more character.          and we are now at a LF, advance the match position by one more character.
5352        */          */
5353    
5354        if (start_match[-1] == '\r' &&          if (start_match[-1] == CHAR_CR &&
5355             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
5356             start_match < end_subject &&               start_match < end_subject &&
5357             *start_match == '\n')               *start_match == CHAR_NL)
5358          start_match++;            start_match++;
5359            }
5360        }        }
     }  
5361    
5362    /* Or to a non-unique first byte after study */      /* Or to a non-unique first byte after study */
5363    
5364    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)  
5365        {        {
5366        register unsigned int c = *start_match;        while (start_match < end_subject)
5367        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;          {
5368          else break;          register unsigned int c = *start_match;
5369            if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
5370              else break;
5371            }
5372        }        }
5373      }      }   /* Starting optimizations */
5374    
5375    /* Restore fudged end_subject */    /* Restore fudged end_subject */
5376    
5377    end_subject = save_end_subject;    end_subject = save_end_subject;
5378    
5379  #ifdef DEBUG  /* Sigh. Some compilers never learn. */    /* The following two optimizations are disabled for partial matching or if
5380    printf(">>>> Match against: ");    disabling is explicitly requested. */
   pchars(start_match, end_subject - start_match, TRUE, md);  
   printf("\n");  
 #endif  
5381    
5382    /* If req_byte is set, we know that that character must appear in the subject    if ((options & PCRE_NO_START_OPTIMIZE) == 0 && !md->partial)
   for the match to succeed. If the first character is set, req_byte must be  
   later in the subject; otherwise the test starts at the match point. This  
   optimization can save a huge amount of backtracking in patterns with nested  
   unlimited repeats that aren't going to match. Writing separate code for  
   cased/caseless versions makes it go faster, as does using an autoincrement  
   and backing off on a match.  
   
   HOWEVER: when the subject string is very, very long, searching to its end can  
   take a long time, and give bad performance on quite ordinary patterns. This  
   showed up when somebody was matching something like /^\d+C/ on a 32-megabyte  
   string... so we don't do this when the string is sufficiently long.  
   
   ALSO: this processing is disabled when partial matching is requested.  
   */  
   
   if (req_byte >= 0 &&  
       end_subject - start_match < REQ_BYTE_MAX &&  
       !md->partial)  
5383      {      {
5384      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);      /* If the pattern was studied, a minimum subject length may be set. This is
5385        a lower bound; no actual string of that length may actually match the
5386        pattern. Although the value is, strictly, in characters, we treat it as
5387        bytes to avoid spending too much time in this optimization. */
5388    
5389        if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
5390            end_subject - start_match < study->minlength)
5391          {
5392          rc = MATCH_NOMATCH;
5393          break;
5394          }
5395    
5396      /* We don't need to repeat the search if we haven't yet reached the      /* If req_byte is set, we know that that character must appear in the
5397      place we found it at last time. */      subject for the match to succeed. If the first character is set, req_byte
5398        must be later in the subject; otherwise the test starts at the match point.
5399        This optimization can save a huge amount of backtracking in patterns with
5400        nested unlimited repeats that aren't going to match. Writing separate code
5401        for cased/caseless versions makes it go faster, as does using an
5402        autoincrement and backing off on a match.
5403    
5404      if (p > req_byte_ptr)      HOWEVER: when the subject string is very, very long, searching to its end
5405        can take a long time, and give bad performance on quite ordinary patterns.
5406        This showed up when somebody was matching something like /^\d+C/ on a
5407        32-megabyte string... so we don't do this when the string is sufficiently
5408        long. */
5409    
5410        if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX)
5411        {        {
5412        if (req_byte_caseless)        register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
5413    
5414          /* We don't need to repeat the search if we haven't yet reached the
5415          place we found it at last time. */
5416    
5417          if (p > req_byte_ptr)
5418          {          {
5419          while (p < end_subject)          if (req_byte_caseless)
5420            {            {
5421            register int pp = *p++;            while (p < end_subject)
5422            if (pp == req_byte || pp == req_byte2) { p--; break; }              {
5423                register int pp = *p++;
5424                if (pp == req_byte || pp == req_byte2) { p--; break; }
5425                }
5426            }            }
5427          }          else
       else  
         {  
         while (p < end_subject)  
5428            {            {
5429            if (*p++ == req_byte) { p--; break; }            while (p < end_subject)
5430                {
5431                if (*p++ == req_byte) { p--; break; }
5432                }
5433            }            }
         }  
5434    
5435        /* If we can't find the required character, break the matching loop,          /* If we can't find the required character, break the matching loop,
5436        forcing a match failure. */          forcing a match failure. */
5437    
5438        if (p >= end_subject)          if (p >= end_subject)
5439          {            {
5440          rc = MATCH_NOMATCH;            rc = MATCH_NOMATCH;
5441          break;            break;
5442          }            }
5443    
5444        /* If we have found the required character, save the point where we          /* If we have found the required character, save the point where we
5445        found it, so that we don't search again next time round the loop if          found it, so that we don't search again next time round the loop if
5446        the start hasn't passed this character yet. */          the start hasn't passed this character yet. */
5447    
5448        req_byte_ptr = p;          req_byte_ptr = p;
5449            }
5450        }        }
5451      }      }
5452    
5453    /* OK, we can now run the match. */  #ifdef DEBUG  /* Sigh. Some compilers never learn. */
5454      printf(">>>> Match against: ");
5455      pchars(start_match, end_subject - start_match, TRUE, md);
5456      printf("\n");
5457    #endif
5458    
5459      /* OK, we can now run the match. If "hitend" is set afterwards, remember the
5460      first starting point for which a partial match was found. */
5461    
5462    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
5463      md->start_used_ptr = start_match;
5464    md->match_call_count = 0;    md->match_call_count = 0;
5465    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);
5466      if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
5467    
5468    switch(rc)    switch(rc)
5469      {      {
# Line 4901  for(;;) Line 5493  for(;;)
5493      rc = MATCH_NOMATCH;      rc = MATCH_NOMATCH;
5494      goto ENDLOOP;      goto ENDLOOP;
5495    
5496      /* Any other return is some kind of error. */      /* Any other return is either a match, or some kind of error. */
5497    
5498      default:      default:
5499      goto ENDLOOP;      goto ENDLOOP;
# Line 4931  for(;;) Line 5523  for(;;)
5523    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
5524    or ANY or ANYCRLF, advance the match position by one more character. */    or ANY or ANYCRLF, advance the match position by one more character. */
5525    
5526    if (start_match[-1] == '\r' &&    if (start_match[-1] == CHAR_CR &&
5527        start_match < end_subject &&        start_match < end_subject &&
5528        *start_match == '\n' &&        *start_match == CHAR_NL &&
5529        (re->flags & PCRE_HASCRORLF) == 0 &&        (re->flags & PCRE_HASCRORLF) == 0 &&
5530          (md->nltype == NLTYPE_ANY ||          (md->nltype == NLTYPE_ANY ||
5531           md->nltype == NLTYPE_ANYCRLF ||           md->nltype == NLTYPE_ANYCRLF ||
# Line 5007  if (using_temporary_offsets) Line 5599  if (using_temporary_offsets)
5599    (pcre_free)(md->offset_vector);    (pcre_free)(md->offset_vector);
5600    }    }
5601    
5602  if (rc != MATCH_NOMATCH)  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)
5603    {    {
5604    DPRINTF((">>>> error: returning %d\n", rc));    DPRINTF((">>>> error: returning %d\n", rc));
5605    return rc;    return rc;
5606    }    }
5607  else if (md->partial && md->hitend)  else if (start_partial != NULL)
5608    {    {
5609    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
5610      if (offsetcount > 1)
5611        {
5612        offsets[0] = start_partial - (USPTR)subject;
5613        offsets[1] = end_subject - (USPTR)subject;
5614        }
5615    return PCRE_ERROR_PARTIAL;    return PCRE_ERROR_PARTIAL;
5616    }    }
5617  else  else

Legend:
Removed from v.381  
changed lines
  Added in v.461

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12