/[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 371 by ph10, Mon Aug 25 18:28:05 2008 UTC revision 482 by ph10, Mon Jan 4 15:55:46 2010 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2008 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 89  static const char rep_max[] = { 0, 0, 0, Line 89  static const char rep_max[] = { 0, 0, 0,
89    
90    
91    
92  #ifdef DEBUG  #ifdef PCRE_DEBUG
93  /*************************************************  /*************************************************
94  *        Debugging function to print chars       *  *        Debugging function to print chars       *
95  *************************************************/  *************************************************/
# Line 141  match_ref(int offset, register USPTR ept Line 141  match_ref(int offset, register USPTR ept
141  {  {
142  USPTR p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
143    
144  #ifdef DEBUG  #ifdef PCRE_DEBUG
145  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
146    printf("matching subject <null>");    printf("matching subject <null>");
147  else  else
# Line 254  actuall used in this definition. */ Line 254  actuall used in this definition. */
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef PCRE_DEBUG
258  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
# 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    #define SCHECK_PARTIAL()\
418      if (md->partial != 0 && 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 the  /* Performance note: It might be tempting to extract commonly used fields from
426  md structure (e.g. utf8, end_subject) into individual variables to improve  the md structure (e.g. utf8, end_subject) into individual variables to improve
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 594  TAIL_RECURSE: Line 622  TAIL_RECURSE:
622  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
623  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
624  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
625  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
626  defined). However, RMATCH isn't like a function call because it's quite a  defined). However, RMATCH isn't like a function call because it's quite a
627  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
# 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 693  for (;;) Line 713  for (;;)
713      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
714      offset = number << 1;      offset = number << 1;
715    
716  #ifdef DEBUG  #ifdef PCRE_DEBUG
717      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
718      printf("subject=");      printf("subject=");
719      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
# Line 787  for (;;) Line 807  for (;;)
807    
808      case OP_COND:      case OP_COND:
809      case OP_SCOND:      case OP_SCOND:
810      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
811    
812        /* Because of the way auto-callout works during compile, a callout item is
813        inserted between OP_COND and an assertion condition. */
814    
815        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816        {        {
817        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        if (pcre_callout != NULL)
818        condition = md->recursive != NULL &&          {
819          (offset == RREF_ANY || offset == md->recursive->group_num);          pcre_callout_block cb;
820        ecode += condition? 3 : GET(ecode, 1);          cb.version          = 1;   /* Version 1 of the callout block */
821            cb.callout_number   = ecode[LINK_SIZE+2];
822            cb.offset_vector    = md->offset_vector;
823            cb.subject          = (PCRE_SPTR)md->start_subject;
824            cb.subject_length   = md->end_subject - md->start_subject;
825            cb.start_match      = mstart - md->start_subject;
826            cb.current_position = eptr - md->start_subject;
827            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
828            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
829            cb.capture_top      = offset_top/2;
830            cb.capture_last     = md->capture_last;
831            cb.callout_data     = md->callout_data;
832            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
833            if (rrc < 0) RRETURN(rrc);
834            }
835          ecode += _pcre_OP_lengths[OP_CALLOUT];
836          }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840        /* Now see what the actual condition is */
841    
842        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
843          {
844          if (md->recursive == NULL)                /* Not recursing => FALSE */
845            {
846            condition = FALSE;
847            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 829  for (;;) Line 1002  for (;;)
1002        else        else
1003          {          {
1004          condition = FALSE;          condition = FALSE;
1005          ecode += GET(ecode, 1);          ecode += codelink;
1006          }          }
1007        }        }
1008    
# Line 852  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 PCRE_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 872  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 926  for (;;) Line 1133  for (;;)
1133      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1134      continue;      continue;
1135    
1136      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1137        PRUNE, or COMMIT means we must assume failure without checking subsequent
1138        branches. */
1139    
1140      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1141      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
# Line 935  for (;;) Line 1144  for (;;)
1144        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1145          RM5);          RM5);
1146        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1147          if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1148            {
1149            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1150            break;
1151            }
1152        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1153        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1154        }        }
# Line 972  for (;;) Line 1186  for (;;)
1186        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1187        }        }
1188    
1189      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1190    
1191        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1192      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1193      break;      break;
1194    
# Line 1053  for (;;) Line 1268  for (;;)
1268        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1269              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1270        new_recursive.save_start = mstart;        new_recursive.save_start = mstart;
1271          new_recursive.save_offset_top = offset_top;
1272        mstart = eptr;        mstart = eptr;
1273    
1274        /* 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 1075  for (;;) Line 1291  for (;;)
1291          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1292            {            {
1293            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1294              if (new_recursive.offset_save != stacksave)
1295                (pcre_free)(new_recursive.offset_save);
1296            RRETURN(rrc);            RRETURN(rrc);
1297            }            }
1298    
# Line 1250  for (;;) Line 1468  for (;;)
1468        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1469        offset = number << 1;        offset = number << 1;
1470    
1471  #ifdef DEBUG  #ifdef PCRE_DEBUG
1472        printf("end bracket %d", number);        printf("end bracket %d", number);
1473        printf("\n");        printf("\n");
1474  #endif  #endif
# Line 1275  for (;;) Line 1493  for (;;)
1493          mstart = rec->save_start;          mstart = rec->save_start;
1494          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1495            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1496            offset_top = rec->save_offset_top;
1497          ecode = rec->after_call;          ecode = rec->after_call;
1498          ims = original_ims;          ims = original_ims;
1499          break;          break;
# Line 1414  for (;;) Line 1633  for (;;)
1633    
1634        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1635        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
1636        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1637          partial matching. */
1638    
1639  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1640        if (utf8)        if (utf8)
1641          {          {
1642          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1643            {            {
1644            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1645            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1646              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1647            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1648            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1649            }            }
1650          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1651              {
1652              SCHECK_PARTIAL();
1653              cur_is_word = FALSE;
1654              }
1655            else
1656            {            {
1657            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1658            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1435  for (;;) Line 1661  for (;;)
1661        else        else
1662  #endif  #endif
1663    
1664        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1665    
1666          {          {
1667          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1668            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1669          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1670            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1671              }
1672            if (eptr >= md->end_subject)
1673              {
1674              SCHECK_PARTIAL();
1675              cur_is_word = FALSE;
1676              }
1677            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1678          }          }
1679    
1680        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1459  for (;;) Line 1692  for (;;)
1692      /* Fall through */      /* Fall through */
1693    
1694      case OP_ALLANY:      case OP_ALLANY:
1695      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1696          {
1697          SCHECK_PARTIAL();
1698          RRETURN(MATCH_NOMATCH);
1699          }
1700      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
1701      ecode++;      ecode++;
1702      break;      break;
# Line 1468  for (;;) Line 1705  for (;;)
1705      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1706    
1707      case OP_ANYBYTE:      case OP_ANYBYTE:
1708      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1709          {
1710          SCHECK_PARTIAL();
1711          RRETURN(MATCH_NOMATCH);
1712          }
1713      ecode++;      ecode++;
1714      break;      break;
1715    
1716      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1717      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1718          {
1719          SCHECK_PARTIAL();
1720          RRETURN(MATCH_NOMATCH);
1721          }
1722      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1723      if (      if (
1724  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1486  for (;;) Line 1731  for (;;)
1731      break;      break;
1732    
1733      case OP_DIGIT:      case OP_DIGIT:
1734      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1735          {
1736          SCHECK_PARTIAL();
1737          RRETURN(MATCH_NOMATCH);
1738          }
1739      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1740      if (      if (
1741  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1499  for (;;) Line 1748  for (;;)
1748      break;      break;
1749    
1750      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1751      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1752          {
1753          SCHECK_PARTIAL();
1754          RRETURN(MATCH_NOMATCH);
1755          }
1756      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1757      if (      if (
1758  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1512  for (;;) Line 1765  for (;;)
1765      break;      break;
1766    
1767      case OP_WHITESPACE:      case OP_WHITESPACE:
1768      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1769          {
1770          SCHECK_PARTIAL();
1771          RRETURN(MATCH_NOMATCH);
1772          }
1773      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1774      if (      if (
1775  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1525  for (;;) Line 1782  for (;;)
1782      break;      break;
1783    
1784      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1785      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1786          {
1787          SCHECK_PARTIAL();
1788          RRETURN(MATCH_NOMATCH);
1789          }
1790      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1791      if (      if (
1792  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1538  for (;;) Line 1799  for (;;)
1799      break;      break;
1800    
1801      case OP_WORDCHAR:      case OP_WORDCHAR:
1802      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1803          {
1804          SCHECK_PARTIAL();
1805          RRETURN(MATCH_NOMATCH);
1806          }
1807      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1808      if (      if (
1809  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1551  for (;;) Line 1816  for (;;)
1816      break;      break;
1817    
1818      case OP_ANYNL:      case OP_ANYNL:
1819      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1820          {
1821          SCHECK_PARTIAL();
1822          RRETURN(MATCH_NOMATCH);
1823          }
1824      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1825      switch(c)      switch(c)
1826        {        {
# Line 1575  for (;;) Line 1844  for (;;)
1844      break;      break;
1845    
1846      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
1847      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1848          {
1849          SCHECK_PARTIAL();
1850          RRETURN(MATCH_NOMATCH);
1851          }
1852      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1853      switch(c)      switch(c)
1854        {        {
# Line 1605  for (;;) Line 1878  for (;;)
1878      break;      break;
1879    
1880      case OP_HSPACE:      case OP_HSPACE:
1881      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1882          {
1883          SCHECK_PARTIAL();
1884          RRETURN(MATCH_NOMATCH);
1885          }
1886      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1887      switch(c)      switch(c)
1888        {        {
# Line 1635  for (;;) Line 1912  for (;;)
1912      break;      break;
1913    
1914      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
1915      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1916          {
1917          SCHECK_PARTIAL();
1918          RRETURN(MATCH_NOMATCH);
1919          }
1920      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1921      switch(c)      switch(c)
1922        {        {
# Line 1653  for (;;) Line 1934  for (;;)
1934      break;      break;
1935    
1936      case OP_VSPACE:      case OP_VSPACE:
1937      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1938          {
1939          SCHECK_PARTIAL();
1940          RRETURN(MATCH_NOMATCH);
1941          }
1942      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1943      switch(c)      switch(c)
1944        {        {
# Line 1676  for (;;) Line 1961  for (;;)
1961    
1962      case OP_PROP:      case OP_PROP:
1963      case OP_NOTPROP:      case OP_NOTPROP:
1964      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1965          {
1966          SCHECK_PARTIAL();
1967          RRETURN(MATCH_NOMATCH);
1968          }
1969      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1970        {        {
1971        const ucd_record * prop = GET_UCD(c);        const ucd_record *prop = GET_UCD(c);
1972    
1973        switch(ecode[1])        switch(ecode[1])
1974          {          {
# Line 1721  for (;;) Line 2010  for (;;)
2010      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2011    
2012      case OP_EXTUNI:      case OP_EXTUNI:
2013      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2014          {
2015          SCHECK_PARTIAL();
2016          RRETURN(MATCH_NOMATCH);
2017          }
2018      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2019        {        {
2020        int category = UCD_CATEGORY(c);        int category = UCD_CATEGORY(c);
# Line 1801  for (;;) Line 2094  for (;;)
2094          break;          break;
2095    
2096          default:               /* No repeat follows */          default:               /* No repeat follows */
2097          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2098              {
2099              CHECK_PARTIAL();
2100              RRETURN(MATCH_NOMATCH);
2101              }
2102          eptr += length;          eptr += length;
2103          continue;              /* With the main loop */          continue;              /* With the main loop */
2104          }          }
# Line 1817  for (;;) Line 2114  for (;;)
2114    
2115        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2116          {          {
2117          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2118              {
2119              CHECK_PARTIAL();
2120              RRETURN(MATCH_NOMATCH);
2121              }
2122          eptr += length;          eptr += length;
2123          }          }
2124    
# Line 1834  for (;;) Line 2135  for (;;)
2135            {            {
2136            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2137            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2138            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
2139              if (!match_ref(offset, eptr, length, md, ims))
2140                {
2141                CHECK_PARTIAL();
2142              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2143                }
2144            eptr += length;            eptr += length;
2145            }            }
2146          /* Control never gets here */          /* Control never gets here */
# Line 1848  for (;;) Line 2153  for (;;)
2153          pp = eptr;          pp = eptr;
2154          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2155            {            {
2156            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2157                {
2158                CHECK_PARTIAL();
2159                break;
2160                }
2161            eptr += length;            eptr += length;
2162            }            }
2163          while (eptr >= pp)          while (eptr >= pp)
# Line 1862  for (;;) Line 2171  for (;;)
2171        }        }
2172      /* Control never gets here */      /* Control never gets here */
2173    
   
   
2174      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2175      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,
2176      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 1918  for (;;) Line 2225  for (;;)
2225          {          {
2226          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2227            {            {
2228            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2229                {
2230                SCHECK_PARTIAL();
2231                RRETURN(MATCH_NOMATCH);
2232                }
2233            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2234            if (c > 255)            if (c > 255)
2235              {              {
# Line 1936  for (;;) Line 2247  for (;;)
2247          {          {
2248          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2249            {            {
2250            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2251                {
2252                SCHECK_PARTIAL();
2253                RRETURN(MATCH_NOMATCH);
2254                }
2255            c = *eptr++;            c = *eptr++;
2256            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2257            }            }
# Line 1960  for (;;) Line 2275  for (;;)
2275              {              {
2276              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2277              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2278              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2279                if (eptr >= md->end_subject)
2280                  {
2281                  SCHECK_PARTIAL();
2282                  RRETURN(MATCH_NOMATCH);
2283                  }
2284              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2285              if (c > 255)              if (c > 255)
2286                {                {
# Line 1980  for (;;) Line 2300  for (;;)
2300              {              {
2301              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2302              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2303              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2304                if (eptr >= md->end_subject)
2305                  {
2306                  SCHECK_PARTIAL();
2307                  RRETURN(MATCH_NOMATCH);
2308                  }
2309              c = *eptr++;              c = *eptr++;
2310              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2311              }              }
# Line 2001  for (;;) Line 2326  for (;;)
2326            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2327              {              {
2328              int len = 1;              int len = 1;
2329              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2330                  {
2331                  SCHECK_PARTIAL();
2332                  break;
2333                  }
2334              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2335              if (c > 255)              if (c > 255)
2336                {                {
# Line 2027  for (;;) Line 2356  for (;;)
2356            {            {
2357            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2358              {              {
2359              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2360                  {
2361                  SCHECK_PARTIAL();
2362                  break;
2363                  }
2364              c = *eptr;              c = *eptr;
2365              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2366              eptr++;              eptr++;
# Line 2047  for (;;) Line 2380  for (;;)
2380    
2381    
2382      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2383      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
2384        mode, because Unicode properties are supported in non-UTF-8 mode. */
2385    
2386  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2387      case OP_XCLASS:      case OP_XCLASS:
# Line 2088  for (;;) Line 2422  for (;;)
2422    
2423        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2424          {          {
2425          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2426          GETCHARINC(c, eptr);            {
2427              SCHECK_PARTIAL();
2428              RRETURN(MATCH_NOMATCH);
2429              }
2430            GETCHARINCTEST(c, eptr);
2431          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2432          }          }
2433    
# Line 2107  for (;;) Line 2445  for (;;)
2445            {            {
2446            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2447            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2448            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2449            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2450                {
2451                SCHECK_PARTIAL();
2452                RRETURN(MATCH_NOMATCH);
2453                }
2454              GETCHARINCTEST(c, eptr);
2455            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2456            }            }
2457          /* Control never gets here */          /* Control never gets here */
# Line 2122  for (;;) Line 2465  for (;;)
2465          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2466            {            {
2467            int len = 1;            int len = 1;
2468            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2469            GETCHARLEN(c, eptr, len);              {
2470                SCHECK_PARTIAL();
2471                break;
2472                }
2473              GETCHARLENTEST(c, eptr, len);
2474            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2475            eptr += len;            eptr += len;
2476            }            }
# Line 2150  for (;;) Line 2497  for (;;)
2497        length = 1;        length = 1;
2498        ecode++;        ecode++;
2499        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2500        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2501            {
2502            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2503            RRETURN(MATCH_NOMATCH);
2504            }
2505        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2506        }        }
2507      else      else
# Line 2158  for (;;) Line 2509  for (;;)
2509    
2510      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2511        {        {
2512        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2513            {
2514            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2515            RRETURN(MATCH_NOMATCH);
2516            }
2517        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2518        ecode += 2;        ecode += 2;
2519        }        }
# Line 2174  for (;;) Line 2529  for (;;)
2529        ecode++;        ecode++;
2530        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2531    
2532        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2533            {
2534            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2535            RRETURN(MATCH_NOMATCH);
2536            }
2537    
2538        /* 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
2539        can use the fast lookup table. */        can use the fast lookup table. */
# Line 2209  for (;;) Line 2568  for (;;)
2568    
2569      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2570        {        {
2571        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2572            {
2573            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2574            RRETURN(MATCH_NOMATCH);
2575            }
2576        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2577        ecode += 2;        ecode += 2;
2578        }        }
# Line 2263  for (;;) Line 2626  for (;;)
2626      case OP_MINQUERY:      case OP_MINQUERY:
2627      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2628      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2629    
2630      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2631      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2632      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2633    
2634      /* 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. */  
2635    
2636      REPEATCHAR:      REPEATCHAR:
2637  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2278  for (;;) Line 2640  for (;;)
2640        length = 1;        length = 1;
2641        charptr = ecode;        charptr = ecode;
2642        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2643        ecode += length;        ecode += length;
2644    
2645        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2296  for (;;) Line 2657  for (;;)
2657    
2658          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2659            {            {
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    
2674          if (min == max) continue;          if (min == max) continue;
# Line 2318  for (;;) Line 2679  for (;;)
2679              {              {
2680              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2681              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2682              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2683              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2684                  memcmp(eptr, charptr, length) == 0) eptr += length;
2685  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2686              /* Need braces because of following else */              else if (oclength > 0 &&
2687              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                       eptr <= md->end_subject - oclength &&
2688                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2689    #endif  /* SUPPORT_UCP */
2690              else              else
2691                {                {
2692                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2693                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2694                }                }
 #else   /* without SUPPORT_UCP */  
             else { RRETURN (MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2695              }              }
2696            /* Control never gets here */            /* Control never gets here */
2697            }            }
# Line 2340  for (;;) Line 2701  for (;;)
2701            pp = eptr;            pp = eptr;
2702            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2703              {              {
2704              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2705              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2706  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2707              else if (oclength == 0) break;              else if (oclength > 0 &&
2708                         eptr <= md->end_subject - oclength &&
2709                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2710    #endif  /* SUPPORT_UCP */
2711              else              else
2712                {                {
2713                if (memcmp(eptr, occhars, oclength) != 0) break;                CHECK_PARTIAL();
2714                eptr += oclength;                break;
2715                }                }
 #else   /* without SUPPORT_UCP */  
             else break;  
 #endif  /* SUPPORT_UCP */  
2716              }              }
2717    
2718            if (possessive) continue;            if (possessive) continue;
2719    
2720            for(;;)            for(;;)
2721             {              {
2722             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2723             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2724             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2725  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2726             eptr--;              eptr--;
2727             BACKCHAR(eptr);              BACKCHAR(eptr);
2728  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2729             eptr -= length;              eptr -= length;
2730  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2731             }              }
2732            }            }
2733          /* Control never gets here */          /* Control never gets here */
2734          }          }
# Line 2379  for (;;) Line 2741  for (;;)
2741  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2742    
2743      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2744        {  
2745        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2746    
2747      /* 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
2748      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 2400  for (;;) Line 2760  for (;;)
2760        {        {
2761        fc = md->lcc[fc];        fc = md->lcc[fc];
2762        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2763            {
2764            if (eptr >= md->end_subject)
2765              {
2766              SCHECK_PARTIAL();
2767              RRETURN(MATCH_NOMATCH);
2768              }
2769          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2770            }
2771        if (min == max) continue;        if (min == max) continue;
2772        if (minimize)        if (minimize)
2773          {          {
# Line 2408  for (;;) Line 2775  for (;;)
2775            {            {
2776            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2777            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2778            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2779                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2780                {
2781                SCHECK_PARTIAL();
2782              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2783                }
2784              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2785            }            }
2786          /* Control never gets here */          /* Control never gets here */
2787          }          }
# Line 2419  for (;;) Line 2790  for (;;)
2790          pp = eptr;          pp = eptr;
2791          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2792            {            {
2793            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2794                {
2795                SCHECK_PARTIAL();
2796                break;
2797                }
2798              if (fc != md->lcc[*eptr]) break;
2799            eptr++;            eptr++;
2800            }            }
2801    
2802          if (possessive) continue;          if (possessive) continue;
2803    
2804          while (eptr >= pp)          while (eptr >= pp)
2805            {            {
2806            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
# Line 2438  for (;;) Line 2816  for (;;)
2816    
2817      else      else
2818        {        {
2819        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2820            {
2821            if (eptr >= md->end_subject)
2822              {
2823              SCHECK_PARTIAL();
2824              RRETURN(MATCH_NOMATCH);
2825              }
2826            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2827            }
2828    
2829        if (min == max) continue;        if (min == max) continue;
2830    
2831        if (minimize)        if (minimize)
2832          {          {
2833          for (fi = min;; fi++)          for (fi = min;; fi++)
2834            {            {
2835            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2836            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2837            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2838              if (eptr >= md->end_subject)
2839                {
2840                SCHECK_PARTIAL();
2841              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2842                }
2843              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2844            }            }
2845          /* Control never gets here */          /* Control never gets here */
2846          }          }
# Line 2456  for (;;) Line 2849  for (;;)
2849          pp = eptr;          pp = eptr;
2850          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2851            {            {
2852            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
2853                {
2854                SCHECK_PARTIAL();
2855                break;
2856                }
2857              if (fc != *eptr) break;
2858            eptr++;            eptr++;
2859            }            }
2860          if (possessive) continue;          if (possessive) continue;
2861    
2862          while (eptr >= pp)          while (eptr >= pp)
2863            {            {
2864            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
# Line 2475  for (;;) Line 2874  for (;;)
2874      checking can be multibyte. */      checking can be multibyte. */
2875    
2876      case OP_NOT:      case OP_NOT:
2877      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2878          {
2879          SCHECK_PARTIAL();
2880          RRETURN(MATCH_NOMATCH);
2881          }
2882      ecode++;      ecode++;
2883      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2884      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2552  for (;;) Line 2955  for (;;)
2955      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2956      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2957    
2958      /* 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. */  
2959    
2960      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2961      fc = *ecode++;      fc = *ecode++;
2962    
2963      /* 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 2582  for (;;) Line 2982  for (;;)
2982          register unsigned int d;          register unsigned int d;
2983          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2984            {            {
2985              if (eptr >= md->end_subject)
2986                {
2987                SCHECK_PARTIAL();
2988                RRETURN(MATCH_NOMATCH);
2989                }
2990            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2991            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2992            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2593  for (;;) Line 2998  for (;;)
2998        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2999          {          {
3000          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3001            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            {
3002              if (eptr >= md->end_subject)
3003                {
3004                SCHECK_PARTIAL();
3005                RRETURN(MATCH_NOMATCH);
3006                }
3007              if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
3008              }
3009          }          }
3010    
3011        if (min == max) continue;        if (min == max) continue;
# Line 2609  for (;;) Line 3021  for (;;)
3021              {              {
3022              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3023              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3024              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3025                if (eptr >= md->end_subject)
3026                  {
3027                  SCHECK_PARTIAL();
3028                  RRETURN(MATCH_NOMATCH);
3029                  }
3030              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3031              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3032              if (fc == d) RRETURN(MATCH_NOMATCH);              if (fc == d) RRETURN(MATCH_NOMATCH);
   
3033              }              }
3034            }            }
3035          else          else
# Line 2624  for (;;) Line 3040  for (;;)
3040              {              {
3041              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3042              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3043              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
3044                if (eptr >= md->end_subject)
3045                  {
3046                  SCHECK_PARTIAL();
3047                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3048                  }
3049                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
3050              }              }
3051            }            }
3052          /* Control never gets here */          /* Control never gets here */
# Line 2645  for (;;) Line 3066  for (;;)
3066            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3067              {              {
3068              int len = 1;              int len = 1;
3069              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3070                  {
3071                  SCHECK_PARTIAL();
3072                  break;
3073                  }
3074              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3075              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3076              if (fc == d) break;              if (fc == d) break;
# Line 2666  for (;;) Line 3091  for (;;)
3091            {            {
3092            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3093              {              {
3094              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3095                  {
3096                  SCHECK_PARTIAL();
3097                  break;
3098                  }
3099                if (fc == md->lcc[*eptr]) break;
3100              eptr++;              eptr++;
3101              }              }
3102            if (possessive) continue;            if (possessive) continue;
# Line 2694  for (;;) Line 3124  for (;;)
3124          register unsigned int d;          register unsigned int d;
3125          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3126            {            {
3127              if (eptr >= md->end_subject)
3128                {
3129                SCHECK_PARTIAL();
3130                RRETURN(MATCH_NOMATCH);
3131                }
3132            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3133            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
3134            }            }
# Line 2703  for (;;) Line 3138  for (;;)
3138        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3139          {          {
3140          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3141              {
3142              if (eptr >= md->end_subject)
3143                {
3144                SCHECK_PARTIAL();
3145                RRETURN(MATCH_NOMATCH);
3146                }
3147            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3148              }
3149          }          }
3150    
3151        if (min == max) continue;        if (min == max) continue;
# Line 2719  for (;;) Line 3161  for (;;)
3161              {              {
3162              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3163              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3164              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3165                if (eptr >= md->end_subject)
3166                  {
3167                  SCHECK_PARTIAL();
3168                  RRETURN(MATCH_NOMATCH);
3169                  }
3170              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3171              if (fc == d) RRETURN(MATCH_NOMATCH);              if (fc == d) RRETURN(MATCH_NOMATCH);
3172              }              }
# Line 2732  for (;;) Line 3179  for (;;)
3179              {              {
3180              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3181              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3182              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
3183                if (eptr >= md->end_subject)
3184                  {
3185                  SCHECK_PARTIAL();
3186                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3187                  }
3188                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3189              }              }
3190            }            }
3191          /* Control never gets here */          /* Control never gets here */
# Line 2753  for (;;) Line 3205  for (;;)
3205            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3206              {              {
3207              int len = 1;              int len = 1;
3208              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3209                  {
3210                  SCHECK_PARTIAL();
3211                  break;
3212                  }
3213              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3214              if (fc == d) break;              if (fc == d) break;
3215              eptr += len;              eptr += len;
# Line 2773  for (;;) Line 3229  for (;;)
3229            {            {
3230            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3231              {              {
3232              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3233                  {
3234                  SCHECK_PARTIAL();
3235                  break;
3236                  }
3237                if (fc == *eptr) break;
3238              eptr++;              eptr++;
3239              }              }
3240            if (possessive) continue;            if (possessive) continue;
# Line 2867  for (;;) Line 3328  for (;;)
3328    
3329      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3330      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
3331      (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  
3332      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
3333      and single-bytes. */      and single-bytes. */
3334    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3335      if (min > 0)      if (min > 0)
3336        {        {
3337  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2885  for (;;) Line 3343  for (;;)
3343            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3344            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3345              {              {
3346              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3347                  {
3348                  SCHECK_PARTIAL();
3349                  RRETURN(MATCH_NOMATCH);
3350                  }
3351              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3352              }              }
3353            break;            break;
# Line 2893  for (;;) Line 3355  for (;;)
3355            case PT_LAMP:            case PT_LAMP:
3356            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3357              {              {
3358              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3359                  {
3360                  SCHECK_PARTIAL();
3361                  RRETURN(MATCH_NOMATCH);
3362                  }
3363              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3364              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3365              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 2906  for (;;) Line 3372  for (;;)
3372            case PT_GC:            case PT_GC:
3373            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3374              {              {
3375              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3376                  {
3377                  SCHECK_PARTIAL();
3378                  RRETURN(MATCH_NOMATCH);
3379                  }
3380              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3381              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
3382              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 2917  for (;;) Line 3387  for (;;)
3387            case PT_PC:            case PT_PC:
3388            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3389              {              {
3390              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3391                  {
3392                  SCHECK_PARTIAL();
3393                  RRETURN(MATCH_NOMATCH);
3394                  }
3395              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3396              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3397              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 2928  for (;;) Line 3402  for (;;)
3402            case PT_SC:            case PT_SC:
3403            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3404              {              {
3405              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3406                  {
3407                  SCHECK_PARTIAL();
3408                  RRETURN(MATCH_NOMATCH);
3409                  }
3410              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3411              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
3412              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 2948  for (;;) Line 3426  for (;;)
3426          {          {
3427          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3428            {            {
3429              if (eptr >= md->end_subject)
3430                {
3431                SCHECK_PARTIAL();
3432                RRETURN(MATCH_NOMATCH);
3433                }
3434            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3435            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
3436            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3437            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3438              {              {
3439              int len = 1;              int len = 1;
3440              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3441                {                else { GETCHARLEN(c, eptr, len); }
               GETCHARLEN(c, eptr, len);  
               }  
3442              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
3443              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3444              eptr += len;              eptr += len;
# Line 2976  for (;;) Line 3457  for (;;)
3457          case OP_ANY:          case OP_ANY:
3458          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3459            {            {
3460            if (eptr >= md->end_subject || IS_NEWLINE(eptr))            if (eptr >= md->end_subject)
3461                {
3462                SCHECK_PARTIAL();
3463              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3464                }
3465              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3466            eptr++;            eptr++;
3467            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3468            }            }
# Line 2986  for (;;) Line 3471  for (;;)
3471          case OP_ALLANY:          case OP_ALLANY:
3472          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3473            {            {
3474            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3475                {
3476                SCHECK_PARTIAL();
3477                RRETURN(MATCH_NOMATCH);
3478                }
3479            eptr++;            eptr++;
3480            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3481            }            }
3482          break;          break;
3483    
3484          case OP_ANYBYTE:          case OP_ANYBYTE:
3485            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3486          eptr += min;          eptr += min;
3487          break;          break;
3488    
3489          case OP_ANYNL:          case OP_ANYNL:
3490          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3491            {            {
3492            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3493                {
3494                SCHECK_PARTIAL();
3495                RRETURN(MATCH_NOMATCH);
3496                }
3497            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3498            switch(c)            switch(c)
3499              {              {
# Line 3025  for (;;) Line 3519  for (;;)
3519          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
3520          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3521            {            {
3522            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3523                {
3524                SCHECK_PARTIAL();
3525                RRETURN(MATCH_NOMATCH);
3526                }
3527            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3528            switch(c)            switch(c)
3529              {              {
# Line 3057  for (;;) Line 3555  for (;;)
3555          case OP_HSPACE:          case OP_HSPACE:
3556          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3557            {            {
3558            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3559                {
3560                SCHECK_PARTIAL();
3561                RRETURN(MATCH_NOMATCH);
3562                }
3563            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3564            switch(c)            switch(c)
3565              {              {
# Line 3089  for (;;) Line 3591  for (;;)
3591          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3592          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3593            {            {
3594            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3595                {
3596                SCHECK_PARTIAL();
3597                RRETURN(MATCH_NOMATCH);
3598                }
3599            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3600            switch(c)            switch(c)
3601              {              {
# Line 3109  for (;;) Line 3615  for (;;)
3615          case OP_VSPACE:          case OP_VSPACE:
3616          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3617            {            {
3618            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3619                {
3620                SCHECK_PARTIAL();
3621                RRETURN(MATCH_NOMATCH);
3622                }
3623            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3624            switch(c)            switch(c)
3625              {              {
# Line 3129  for (;;) Line 3639  for (;;)
3639          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3640          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3641            {            {
3642            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3643                {
3644                SCHECK_PARTIAL();
3645                RRETURN(MATCH_NOMATCH);
3646                }
3647            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3648            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3649              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 3139  for (;;) Line 3653  for (;;)
3653          case OP_DIGIT:          case OP_DIGIT:
3654          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3655            {            {
3656            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3657               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3658                SCHECK_PARTIAL();
3659                RRETURN(MATCH_NOMATCH);
3660                }
3661              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3662              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3663            /* 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 */
3664            }            }
# Line 3149  for (;;) Line 3667  for (;;)
3667          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3668          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3669            {            {
3670            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3671               (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0))              {
3672                SCHECK_PARTIAL();
3673                RRETURN(MATCH_NOMATCH);
3674                }
3675              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3676              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3677            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3678            }            }
# Line 3159  for (;;) Line 3681  for (;;)
3681          case OP_WHITESPACE:          case OP_WHITESPACE:
3682          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3683            {            {
3684            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3685               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3686                SCHECK_PARTIAL();
3687                RRETURN(MATCH_NOMATCH);
3688                }
3689              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3690              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3691            /* 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 */
3692            }            }
# Line 3169  for (;;) Line 3695  for (;;)
3695          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3696          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3697            {            {
3698            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3699               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))              {
3700                SCHECK_PARTIAL();
3701                RRETURN(MATCH_NOMATCH);
3702                }
3703              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3704              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3705            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3706            }            }
# Line 3179  for (;;) Line 3709  for (;;)
3709          case OP_WORDCHAR:          case OP_WORDCHAR:
3710          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3711            {            {
3712            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3713               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3714                SCHECK_PARTIAL();
3715                RRETURN(MATCH_NOMATCH);
3716                }
3717              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3718              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3719            /* 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 */
3720            }            }
# Line 3194  for (;;) Line 3728  for (;;)
3728  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3729    
3730        /* 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
3731        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. */  
3732    
3733        switch(ctype)        switch(ctype)
3734          {          {
3735          case OP_ANY:          case OP_ANY:
3736          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3737            {            {
3738              if (eptr >= md->end_subject)
3739                {
3740                SCHECK_PARTIAL();
3741                RRETURN(MATCH_NOMATCH);
3742                }
3743            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);            if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3744            eptr++;            eptr++;
3745            }            }
3746          break;          break;
3747    
3748          case OP_ALLANY:          case OP_ALLANY:
3749            if (eptr > md->end_subject - min)
3750              {
3751              SCHECK_PARTIAL();
3752              RRETURN(MATCH_NOMATCH);
3753              }
3754          eptr += min;          eptr += min;
3755          break;          break;
3756    
3757          case OP_ANYBYTE:          case OP_ANYBYTE:
3758            if (eptr > md->end_subject - min)
3759              {
3760              SCHECK_PARTIAL();
3761              RRETURN(MATCH_NOMATCH);
3762              }
3763          eptr += min;          eptr += min;
3764          break;          break;
3765    
         /* Because of the CRLF case, we can't assume the minimum number of  
         bytes are present in this case. */  
   
3766          case OP_ANYNL:          case OP_ANYNL:
3767          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3768            {            {
3769            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3770                {
3771                SCHECK_PARTIAL();
3772                RRETURN(MATCH_NOMATCH);
3773                }
3774            switch(*eptr++)            switch(*eptr++)
3775              {              {
3776              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3243  for (;;) Line 3792  for (;;)
3792          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
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: break;              default: break;
# Line 3258  for (;;) Line 3811  for (;;)
3811          case OP_HSPACE:          case OP_HSPACE:
3812          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3813            {            {
3814            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3815                {
3816                SCHECK_PARTIAL();
3817                RRETURN(MATCH_NOMATCH);
3818                }
3819            switch(*eptr++)            switch(*eptr++)
3820              {              {
3821              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3273  for (;;) Line 3830  for (;;)
3830          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3831          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3832            {            {
3833            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3834                {
3835                SCHECK_PARTIAL();
3836                RRETURN(MATCH_NOMATCH);
3837                }
3838            switch(*eptr++)            switch(*eptr++)
3839              {              {
3840              default: break;              default: break;
# Line 3290  for (;;) Line 3851  for (;;)
3851          case OP_VSPACE:          case OP_VSPACE:
3852          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3853            {            {
3854            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3855                {
3856                SCHECK_PARTIAL();
3857                RRETURN(MATCH_NOMATCH);
3858                }
3859            switch(*eptr++)            switch(*eptr++)
3860              {              {
3861              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 3306  for (;;) Line 3871  for (;;)
3871    
3872          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3873          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3874              {
3875              if (eptr >= md->end_subject)
3876                {
3877                SCHECK_PARTIAL();
3878                RRETURN(MATCH_NOMATCH);
3879                }
3880            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3881              }
3882          break;          break;
3883    
3884          case OP_DIGIT:          case OP_DIGIT:
3885          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3886              {
3887              if (eptr >= md->end_subject)
3888                {
3889                SCHECK_PARTIAL();
3890                RRETURN(MATCH_NOMATCH);
3891                }
3892            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3893              }
3894          break;          break;
3895    
3896          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3897          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3898              {
3899              if (eptr >= md->end_subject)
3900                {
3901                SCHECK_PARTIAL();
3902                RRETURN(MATCH_NOMATCH);
3903                }
3904            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3905              }
3906          break;          break;
3907    
3908          case OP_WHITESPACE:          case OP_WHITESPACE:
3909          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3910              {
3911              if (eptr >= md->end_subject)
3912                {
3913                SCHECK_PARTIAL();
3914                RRETURN(MATCH_NOMATCH);
3915                }
3916            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3917              }
3918          break;          break;
3919    
3920          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3921          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3922              {
3923              if (eptr >= md->end_subject)
3924                {
3925                SCHECK_PARTIAL();
3926                RRETURN(MATCH_NOMATCH);
3927                }
3928            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3929              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3930              }
3931          break;          break;
3932    
3933          case OP_WORDCHAR:          case OP_WORDCHAR:
3934          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3935              {
3936              if (eptr >= md->end_subject)
3937                {
3938                SCHECK_PARTIAL();
3939                RRETURN(MATCH_NOMATCH);
3940                }
3941            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3942              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3943              }
3944          break;          break;
3945    
3946          default:          default:
# Line 3361  for (;;) Line 3968  for (;;)
3968              {              {
3969              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3970              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3971              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3972                if (eptr >= md->end_subject)
3973                  {
3974                  SCHECK_PARTIAL();
3975                  RRETURN(MATCH_NOMATCH);
3976                  }
3977              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3978              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3979              }              }
# Line 3372  for (;;) Line 3984  for (;;)
3984              {              {
3985              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3986              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3987              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3988                if (eptr >= md->end_subject)
3989                  {
3990                  SCHECK_PARTIAL();
3991                  RRETURN(MATCH_NOMATCH);
3992                  }
3993              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3994              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
3995              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 3387  for (;;) Line 4004  for (;;)
4004              {              {
4005              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
4006              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4007              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
4008                if (eptr >= md->end_subject)
4009                  {
4010                  SCHECK_PARTIAL();
4011                  RRETURN(MATCH_NOMATCH);
4012                  }
4013              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
4014              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4015              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 3400  for (;;) Line 4022  for (;;)
4022              {              {
4023              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
4024              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4025              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
4026                if (eptr >= md->end_subject)
4027                  {
4028                  SCHECK_PARTIAL();
4029                  RRETURN(MATCH_NOMATCH);
4030                  }
4031              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
4032              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4033              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 3413  for (;;) Line 4040  for (;;)
4040              {              {
4041              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
4042              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4043              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
4044                if (eptr >= md->end_subject)
4045                  {
4046                  SCHECK_PARTIAL();
4047                  RRETURN(MATCH_NOMATCH);
4048                  }
4049              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
4050              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
4051              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 3435  for (;;) Line 4067  for (;;)
4067            {            {
4068            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
4069            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4070            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
4071              if (eptr >= md->end_subject)
4072                {
4073                SCHECK_PARTIAL();
4074                RRETURN(MATCH_NOMATCH);
4075                }
4076            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4077            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
4078            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
4079            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4080              {              {
4081              int len = 1;              int len = 1;
4082              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
4083                {                else { GETCHARLEN(c, eptr, len); }
               GETCHARLEN(c, eptr, len);  
               }  
4084              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4085              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4086              eptr += len;              eptr += len;
# Line 3464  for (;;) Line 4099  for (;;)
4099            {            {
4100            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
4101            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4102            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4103                 (ctype == OP_ANY && IS_NEWLINE(eptr)))            if (eptr >= md->end_subject)
4104                {
4105                SCHECK_PARTIAL();
4106                RRETURN(MATCH_NOMATCH);
4107                }
4108              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4109              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4110            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4111            switch(ctype)            switch(ctype)
4112              {              {
# Line 3623  for (;;) Line 4262  for (;;)
4262            {            {
4263            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4264            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4265            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4266                 (ctype == OP_ANY && IS_NEWLINE(eptr)))            if (eptr >= md->end_subject)
4267                {
4268                SCHECK_PARTIAL();
4269                RRETURN(MATCH_NOMATCH);
4270                }
4271              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4272              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4273            c = *eptr++;            c = *eptr++;
4274            switch(ctype)            switch(ctype)
4275              {              {
# Line 3751  for (;;) Line 4394  for (;;)
4394            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4395              {              {
4396              int len = 1;              int len = 1;
4397              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4398                  {
4399                  SCHECK_PARTIAL();
4400                  break;
4401                  }
4402              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4403              if (prop_fail_result) break;              if (prop_fail_result) break;
4404              eptr+= len;              eptr+= len;
# Line 3762  for (;;) Line 4409  for (;;)
4409            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4410              {              {
4411              int len = 1;              int len = 1;
4412              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4413                  {
4414                  SCHECK_PARTIAL();
4415                  break;
4416                  }
4417              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4418              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4419              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
# Line 3777  for (;;) Line 4428  for (;;)
4428            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4429              {              {
4430              int len = 1;              int len = 1;
4431              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4432                  {
4433                  SCHECK_PARTIAL();
4434                  break;
4435                  }
4436              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4437              prop_category = UCD_CATEGORY(c);              prop_category = UCD_CATEGORY(c);
4438              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
# Line 3790  for (;;) Line 4445  for (;;)
4445            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4446              {              {
4447              int len = 1;              int len = 1;
4448              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4449                  {
4450                  SCHECK_PARTIAL();
4451                  break;
4452                  }
4453              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4454              prop_chartype = UCD_CHARTYPE(c);              prop_chartype = UCD_CHARTYPE(c);
4455              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
# Line 3803  for (;;) Line 4462  for (;;)
4462            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4463              {              {
4464              int len = 1;              int len = 1;
4465              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4466                  {
4467                  SCHECK_PARTIAL();
4468                  break;
4469                  }
4470              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4471              prop_script = UCD_SCRIPT(c);              prop_script = UCD_SCRIPT(c);
4472              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
# Line 3832  for (;;) Line 4495  for (;;)
4495          {          {
4496          for (i = min; i < max; i++)          for (i = min; i < max; i++)
4497            {            {
4498            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
4499                {
4500                SCHECK_PARTIAL();
4501                break;
4502                }
4503            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4504            prop_category = UCD_CATEGORY(c);            prop_category = UCD_CATEGORY(c);
4505            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
# Line 3852  for (;;) Line 4519  for (;;)
4519          /* eptr is now past the end of the maximum run */          /* eptr is now past the end of the maximum run */
4520    
4521          if (possessive) continue;          if (possessive) continue;
4522    
4523          for(;;)          for(;;)
4524            {            {
4525            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
# Line 3887  for (;;) Line 4555  for (;;)
4555              {              {
4556              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4557                {                {
4558                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                if (eptr >= md->end_subject)
4559                    {
4560                    SCHECK_PARTIAL();
4561                    break;
4562                    }
4563                  if (IS_NEWLINE(eptr)) break;
4564                eptr++;                eptr++;
4565                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4566                }                }
# Line 3899  for (;;) Line 4572  for (;;)
4572              {              {
4573              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4574                {                {
4575                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                if (eptr >= md->end_subject)
4576                    {
4577                    SCHECK_PARTIAL();
4578                    break;
4579                    }
4580                  if (IS_NEWLINE(eptr)) break;
4581                eptr++;                eptr++;
4582                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4583                }                }
# Line 3911  for (;;) Line 4589  for (;;)
4589              {              {
4590              for (i = min; i < max; i++)              for (i = min; i < max; i++)
4591                {                {
4592                if (eptr >= md->end_subject) break;                if (eptr >= md->end_subject)
4593                    {
4594                    SCHECK_PARTIAL();
4595                    break;
4596                    }
4597                eptr++;                eptr++;
4598                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
4599                }                }
# Line 3924  for (;;) Line 4606  for (;;)
4606            case OP_ANYBYTE:            case OP_ANYBYTE:
4607            c = max - min;            c = max - min;
4608            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
4609              c = md->end_subject - eptr;              {
4610            eptr += c;              eptr = md->end_subject;
4611                SCHECK_PARTIAL();
4612                }
4613              else eptr += c;
4614            break;            break;
4615    
4616            case OP_ANYNL:            case OP_ANYNL:
4617            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4618              {              {
4619              int len = 1;              int len = 1;
4620              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4621                  {
4622                  SCHECK_PARTIAL();
4623                  break;
4624                  }
4625              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4626              if (c == 0x000d)              if (c == 0x000d)
4627                {                {
# Line 3957  for (;;) Line 4646  for (;;)
4646              {              {
4647              BOOL gotspace;              BOOL gotspace;
4648              int len = 1;              int len = 1;
4649              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4650                  {
4651                  SCHECK_PARTIAL();
4652                  break;
4653                  }
4654              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4655              switch(c)              switch(c)
4656                {                {
# Line 3995  for (;;) Line 4688  for (;;)
4688              {              {
4689              BOOL gotspace;              BOOL gotspace;
4690              int len = 1;              int len = 1;
4691              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4692                  {
4693                  SCHECK_PARTIAL();
4694                  break;
4695                  }
4696              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4697              switch(c)              switch(c)
4698                {                {
# Line 4019  for (;;) Line 4716  for (;;)
4716            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4717              {              {
4718              int len = 1;              int len = 1;
4719              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4720                  {
4721                  SCHECK_PARTIAL();
4722                  break;
4723                  }
4724              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4725              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_digit) != 0) break;
4726              eptr+= len;              eptr+= len;
# Line 4030  for (;;) Line 4731  for (;;)
4731            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4732              {              {
4733              int len = 1;              int len = 1;
4734              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4735                  {
4736                  SCHECK_PARTIAL();
4737                  break;
4738                  }
4739              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4740              if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;              if (c >= 256 ||(md->ctypes[c] & ctype_digit) == 0) break;
4741              eptr+= len;              eptr+= len;
# Line 4041  for (;;) Line 4746  for (;;)
4746            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4747              {              {
4748              int len = 1;              int len = 1;
4749              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4750                  {
4751                  SCHECK_PARTIAL();
4752                  break;
4753                  }
4754              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4755              if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_space) != 0) break;
4756              eptr+= len;              eptr+= len;
# Line 4052  for (;;) Line 4761  for (;;)
4761            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4762              {              {
4763              int len = 1;              int len = 1;
4764              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4765                  {
4766                  SCHECK_PARTIAL();
4767                  break;
4768                  }
4769              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4770              if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;              if (c >= 256 ||(md->ctypes[c] & ctype_space) == 0) break;
4771              eptr+= len;              eptr+= len;
# Line 4063  for (;;) Line 4776  for (;;)
4776            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4777              {              {
4778              int len = 1;              int len = 1;
4779              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4780                  {
4781                  SCHECK_PARTIAL();
4782                  break;
4783                  }
4784              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4785              if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;              if (c < 256 && (md->ctypes[c] & ctype_word) != 0) break;
4786              eptr+= len;              eptr+= len;
# Line 4074  for (;;) Line 4791  for (;;)
4791            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4792              {              {
4793              int len = 1;              int len = 1;
4794              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4795                  {
4796                  SCHECK_PARTIAL();
4797                  break;
4798                  }
4799              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4800              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;              if (c >= 256 || (md->ctypes[c] & ctype_word) == 0) break;
4801              eptr+= len;              eptr+= len;
# Line 4106  for (;;) Line 4827  for (;;)
4827            case OP_ANY:            case OP_ANY:
4828            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4829              {              {
4830              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;              if (eptr >= md->end_subject)
4831                  {
4832                  SCHECK_PARTIAL();
4833                  break;
4834                  }
4835                if (IS_NEWLINE(eptr)) break;
4836              eptr++;              eptr++;
4837              }              }
4838            break;            break;
# Line 4115  for (;;) Line 4841  for (;;)
4841            case OP_ANYBYTE:            case OP_ANYBYTE:
4842            c = max - min;            c = max - min;
4843            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
4844              c = md->end_subject - eptr;              {
4845            eptr += c;              eptr = md->end_subject;
4846                SCHECK_PARTIAL();
4847                }
4848              else eptr += c;
4849            break;            break;
4850    
4851            case OP_ANYNL:            case OP_ANYNL:
4852            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4853              {              {
4854              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4855                  {
4856                  SCHECK_PARTIAL();
4857                  break;
4858                  }
4859              c = *eptr;              c = *eptr;
4860              if (c == 0x000d)              if (c == 0x000d)
4861                {                {
# Line 4143  for (;;) Line 4876  for (;;)
4876            case OP_NOT_HSPACE:            case OP_NOT_HSPACE:
4877            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4878              {              {
4879              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4880                  {
4881                  SCHECK_PARTIAL();
4882                  break;
4883                  }
4884              c = *eptr;              c = *eptr;
4885              if (c == 0x09 || c == 0x20 || c == 0xa0) break;              if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4886              eptr++;              eptr++;
# Line 4153  for (;;) Line 4890  for (;;)
4890            case OP_HSPACE:            case OP_HSPACE:
4891            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4892              {              {
4893              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4894                  {
4895                  SCHECK_PARTIAL();
4896                  break;
4897                  }
4898              c = *eptr;              c = *eptr;
4899              if (c != 0x09 && c != 0x20 && c != 0xa0) break;              if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4900              eptr++;              eptr++;
# Line 4163  for (;;) Line 4904  for (;;)
4904            case OP_NOT_VSPACE:            case OP_NOT_VSPACE:
4905            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4906              {              {
4907              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4908                  {
4909                  SCHECK_PARTIAL();
4910                  break;
4911                  }
4912              c = *eptr;              c = *eptr;
4913              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)              if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4914                break;                break;
# Line 4174  for (;;) Line 4919  for (;;)
4919            case OP_VSPACE:            case OP_VSPACE:
4920            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4921              {              {
4922              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
4923                  {
4924                  SCHECK_PARTIAL();
4925                  break;
4926                  }
4927              c = *eptr;              c = *eptr;
4928              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)              if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4929                break;                break;
# Line 4185  for (;;) Line 4934  for (;;)
4934            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4935            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4936              {              {
4937              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) != 0)              if (eptr >= md->end_subject)
4938                  {
4939                  SCHECK_PARTIAL();
4940                break;                break;
4941                  }
4942                if ((md->ctypes[*eptr] & ctype_digit) != 0) break;
4943              eptr++;              eptr++;
4944              }              }
4945            break;            break;
# Line 4194  for (;;) Line 4947  for (;;)
4947            case OP_DIGIT:            case OP_DIGIT:
4948            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4949              {              {
4950              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_digit) == 0)              if (eptr >= md->end_subject)
4951                  {
4952                  SCHECK_PARTIAL();
4953                break;                break;
4954                  }
4955                if ((md->ctypes[*eptr] & ctype_digit) == 0) break;
4956              eptr++;              eptr++;
4957              }              }
4958            break;            break;
# Line 4203  for (;;) Line 4960  for (;;)
4960            case OP_NOT_WHITESPACE:            case OP_NOT_WHITESPACE:
4961            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4962              {              {
4963              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) != 0)              if (eptr >= md->end_subject)
4964                  {
4965                  SCHECK_PARTIAL();
4966                break;                break;
4967                  }
4968                if ((md->ctypes[*eptr] & ctype_space) != 0) break;
4969              eptr++;              eptr++;
4970              }              }
4971            break;            break;
# Line 4212  for (;;) Line 4973  for (;;)
4973            case OP_WHITESPACE:            case OP_WHITESPACE:
4974            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4975              {              {
4976              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_space) == 0)              if (eptr >= md->end_subject)
4977                  {
4978                  SCHECK_PARTIAL();
4979                break;                break;
4980                  }
4981                if ((md->ctypes[*eptr] & ctype_space) == 0) break;
4982              eptr++;              eptr++;
4983              }              }
4984            break;            break;
# Line 4221  for (;;) Line 4986  for (;;)
4986            case OP_NOT_WORDCHAR:            case OP_NOT_WORDCHAR:
4987            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4988              {              {
4989              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) != 0)              if (eptr >= md->end_subject)
4990                  {
4991                  SCHECK_PARTIAL();
4992                break;                break;
4993                  }
4994                if ((md->ctypes[*eptr] & ctype_word) != 0) break;
4995              eptr++;              eptr++;
4996              }              }
4997            break;            break;
# Line 4230  for (;;) Line 4999  for (;;)
4999            case OP_WORDCHAR:            case OP_WORDCHAR:
5000            for (i = min; i < max; i++)            for (i = min; i < max; i++)
5001              {              {
5002              if (eptr >= md->end_subject || (md->ctypes[*eptr] & ctype_word) == 0)              if (eptr >= md->end_subject)
5003                  {
5004                  SCHECK_PARTIAL();
5005                break;                break;
5006                  }
5007                if ((md->ctypes[*eptr] & ctype_word) == 0) break;
5008              eptr++;              eptr++;
5009              }              }
5010            break;            break;
# Line 4409  const uschar *tables; Line 5182  const uschar *tables;
5182  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
5183  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
5184  USPTR end_subject;  USPTR end_subject;
5185    USPTR start_partial = NULL;
5186  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
5187    
5188  pcre_study_data internal_study;  pcre_study_data internal_study;
# Line 4425  if (re == NULL || subject == NULL || Line 5199  if (re == NULL || subject == NULL ||
5199     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;     (offsets == NULL && offsetcount > 0)) return PCRE_ERROR_NULL;
5200  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;  if (offsetcount < 0) return PCRE_ERROR_BADCOUNT;
5201    
5202    /* This information is for finding all the numbers associated with a given
5203    name, for condition testing. */
5204    
5205    md->name_table = (uschar *)re + re->name_table_offset;
5206    md->name_count = re->name_count;
5207    md->name_entry_size = re->name_entry_size;
5208    
5209  /* Fish out the optional data from the extra_data structure, first setting  /* Fish out the optional data from the extra_data structure, first setting
5210  the default values. */  the default values. */
5211    
# Line 4492  md->jscript_compat = (re->options & PCRE Line 5273  md->jscript_compat = (re->options & PCRE
5273  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
5274  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
5275  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
5276  md->partial = (options & PCRE_PARTIAL) != 0;  md->notempty_atstart = (options & PCRE_NOTEMPTY_ATSTART) != 0;
5277    md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
5278                  ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
5279  md->hitend = FALSE;  md->hitend = FALSE;
5280    
5281  md->recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
# Line 4533  switch ((((options & PCRE_NEWLINE_BITS) Line 5316  switch ((((options & PCRE_NEWLINE_BITS)
5316          (pcre_uint32)options) & PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
5317    {    {
5318    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
5319    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
5320    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
5321    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
5322         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
5323    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
5324    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;    case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
5325    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
# Line 4566  else Line 5349  else
5349      }      }
5350    }    }
5351    
5352  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching was originally supported only for a restricted set of
5353  moment. */  regexes; from release 8.00 there are no restrictions, but the bits are still
5354    defined (though never set). So there's no harm in leaving this code. */
5355    
5356  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
5357    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
# Line 4578  back the character offset. */ Line 5362  back the character offset. */
5362  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5363  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
5364    {    {
5365    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((USPTR)subject, length) >= 0)
5366      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
5367    if (start_offset > 0 && start_offset < length)    if (start_offset > 0 && start_offset < length)
5368      {      {
5369      int tb = ((uschar *)subject)[start_offset];      int tb = ((USPTR)subject)[start_offset];
5370      if (tb > 127)      if (tb > 127)
5371        {        {
5372        tb &= 0xc0;        tb &= 0xc0;
# Line 4654  if (!anchored) Line 5438  if (!anchored)
5438      }      }
5439    else    else
5440      if (!startline && study != NULL &&      if (!startline && study != NULL &&
5441        (study->options & PCRE_STUDY_MAPPED) != 0)        (study->flags & PCRE_STUDY_MAPPED) != 0)
5442          start_bits = study->start_bits;          start_bits = study->start_bits;
5443    }    }
5444    
# Line 4688  for(;;) Line 5472  for(;;)
5472      while (iptr < iend) *iptr++ = -1;      while (iptr < iend) *iptr++ = -1;
5473      }      }
5474    
5475    /* 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
5476    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
5477    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
5478    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
5479    the match fails at the newline, later code breaks this loop. */    this loop. */
5480    
5481    if (firstline)    if (firstline)
5482      {      {
# Line 4712  for(;;) Line 5496  for(;;)
5496      end_subject = t;      end_subject = t;
5497      }      }
5498    
5499    /* Now advance to a unique first byte if there is one. */    /* There are some optimizations that avoid running the match if a known
5500      starting point is not found, or if a known later character is not present.
5501      However, there is an option that disables these, for testing and for ensuring
5502      that all callouts do actually occur. */
5503    
5504    if (first_byte >= 0)    if ((options & PCRE_NO_START_OPTIMIZE) == 0)
5505      {      {
5506      if (first_byte_caseless)      /* Advance to a unique first byte if there is one. */
       while (start_match < end_subject && md->lcc[*start_match] != first_byte)  
         start_match++;  
     else  
       while (start_match < end_subject && *start_match != first_byte)  
         start_match++;  
     }  
5507    
5508    /* Or to just after a linebreak for a multiline match */      if (first_byte >= 0)
5509          {
5510          if (first_byte_caseless)
5511            while (start_match < end_subject && md->lcc[*start_match] != first_byte)
5512              start_match++;
5513          else
5514            while (start_match < end_subject && *start_match != first_byte)
5515              start_match++;
5516          }
5517    
5518    else if (startline)      /* Or to just after a linebreak for a multiline match */
5519      {  
5520      if (start_match > md->start_subject + start_offset)      else if (startline)
5521        {        {
5522  #ifdef SUPPORT_UTF8        if (start_match > md->start_subject + start_offset)
       if (utf8)  
5523          {          {
5524          while (start_match < end_subject && !WAS_NEWLINE(start_match))  #ifdef SUPPORT_UTF8
5525            if (utf8)
5526            {            {
5527            start_match++;            while (start_match < end_subject && !WAS_NEWLINE(start_match))
5528            while(start_match < end_subject && (*start_match & 0xc0) == 0x80)              {
5529              start_match++;              start_match++;
5530                while(start_match < end_subject && (*start_match & 0xc0) == 0x80)
5531                  start_match++;
5532                }
5533            }            }
5534          }          else
       else  
5535  #endif  #endif
5536        while (start_match < end_subject && !WAS_NEWLINE(start_match))          while (start_match < end_subject && !WAS_NEWLINE(start_match))
5537          start_match++;            start_match++;
5538    
5539        /* 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,
5540        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.
5541        */          */
5542    
5543        if (start_match[-1] == '\r' &&          if (start_match[-1] == CHAR_CR &&
5544             (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&               (md->nltype == NLTYPE_ANY || md->nltype == NLTYPE_ANYCRLF) &&
5545             start_match < end_subject &&               start_match < end_subject &&
5546             *start_match == '\n')               *start_match == CHAR_NL)
5547          start_match++;            start_match++;
5548            }
5549        }        }
     }  
5550    
5551    /* Or to a non-unique first byte after study */      /* Or to a non-unique first byte after study */
5552    
5553    else if (start_bits != NULL)      else if (start_bits != NULL)
     {  
     while (start_match < end_subject)  
5554        {        {
5555        register unsigned int c = *start_match;        while (start_match < end_subject)
5556        if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;          {
5557          else break;          register unsigned int c = *start_match;
5558            if ((start_bits[c/8] & (1 << (c&7))) == 0) start_match++;
5559              else break;
5560            }
5561        }        }
5562      }      }   /* Starting optimizations */
5563    
5564    /* Restore fudged end_subject */    /* Restore fudged end_subject */
5565    
5566    end_subject = save_end_subject;    end_subject = save_end_subject;
5567    
5568  #ifdef DEBUG  /* Sigh. Some compilers never learn. */    /* The following two optimizations are disabled for partial matching or if
5569    printf(">>>> Match against: ");    disabling is explicitly requested. */
   pchars(start_match, end_subject - start_match, TRUE, md);  
   printf("\n");  
 #endif  
5570    
5571    /* 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)  
5572      {      {
5573      register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);      /* If the pattern was studied, a minimum subject length may be set. This is
5574        a lower bound; no actual string of that length may actually match the
5575        pattern. Although the value is, strictly, in characters, we treat it as
5576        bytes to avoid spending too much time in this optimization. */
5577    
5578      /* We don't need to repeat the search if we haven't yet reached the      if (study != NULL && (study->flags & PCRE_STUDY_MINLEN) != 0 &&
5579      place we found it at last time. */          (pcre_uint32)(end_subject - start_match) < study->minlength)
5580          {
5581          rc = MATCH_NOMATCH;
5582          break;
5583          }
5584    
5585        /* If req_byte is set, we know that that character must appear in the
5586        subject for the match to succeed. If the first character is set, req_byte
5587        must be later in the subject; otherwise the test starts at the match point.
5588        This optimization can save a huge amount of backtracking in patterns with
5589        nested unlimited repeats that aren't going to match. Writing separate code
5590        for cased/caseless versions makes it go faster, as does using an
5591        autoincrement and backing off on a match.
5592    
5593        HOWEVER: when the subject string is very, very long, searching to its end
5594        can take a long time, and give bad performance on quite ordinary patterns.
5595        This showed up when somebody was matching something like /^\d+C/ on a
5596        32-megabyte string... so we don't do this when the string is sufficiently
5597        long. */
5598    
5599      if (p > req_byte_ptr)      if (req_byte >= 0 && end_subject - start_match < REQ_BYTE_MAX)
5600        {        {
5601        if (req_byte_caseless)        register USPTR p = start_match + ((first_byte >= 0)? 1 : 0);
5602    
5603          /* We don't need to repeat the search if we haven't yet reached the
5604          place we found it at last time. */
5605    
5606          if (p > req_byte_ptr)
5607          {          {
5608          while (p < end_subject)          if (req_byte_caseless)
5609            {            {
5610            register int pp = *p++;            while (p < end_subject)
5611            if (pp == req_byte || pp == req_byte2) { p--; break; }              {
5612                register int pp = *p++;
5613                if (pp == req_byte || pp == req_byte2) { p--; break; }
5614                }
5615            }            }
5616          }          else
       else  
         {  
         while (p < end_subject)  
5617            {            {
5618            if (*p++ == req_byte) { p--; break; }            while (p < end_subject)
5619                {
5620                if (*p++ == req_byte) { p--; break; }
5621                }
5622            }            }
         }  
5623    
5624        /* If we can't find the required character, break the matching loop,          /* If we can't find the required character, break the matching loop,
5625        forcing a match failure. */          forcing a match failure. */
5626    
5627        if (p >= end_subject)          if (p >= end_subject)
5628          {            {
5629          rc = MATCH_NOMATCH;            rc = MATCH_NOMATCH;
5630          break;            break;
5631          }            }
5632    
5633        /* If we have found the required character, save the point where we          /* If we have found the required character, save the point where we
5634        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
5635        the start hasn't passed this character yet. */          the start hasn't passed this character yet. */
5636    
5637        req_byte_ptr = p;          req_byte_ptr = p;
5638            }
5639        }        }
5640      }      }
5641    
5642    /* OK, we can now run the match. */  #ifdef PCRE_DEBUG  /* Sigh. Some compilers never learn. */
5643      printf(">>>> Match against: ");
5644      pchars(start_match, end_subject - start_match, TRUE, md);
5645      printf("\n");
5646    #endif
5647    
5648      /* OK, we can now run the match. If "hitend" is set afterwards, remember the
5649      first starting point for which a partial match was found. */
5650    
5651    md->start_match_ptr = start_match;    md->start_match_ptr = start_match;
5652      md->start_used_ptr = start_match;
5653    md->match_call_count = 0;    md->match_call_count = 0;
5654    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);
5655      if (md->hitend && start_partial == NULL) start_partial = md->start_used_ptr;
5656    
5657    switch(rc)    switch(rc)
5658      {      {
# Line 4873  for(;;) Line 5682  for(;;)
5682      rc = MATCH_NOMATCH;      rc = MATCH_NOMATCH;
5683      goto ENDLOOP;      goto ENDLOOP;
5684    
5685      /* Any other return is some kind of error. */      /* Any other return is either a match, or some kind of error. */
5686    
5687      default:      default:
5688      goto ENDLOOP;      goto ENDLOOP;
# Line 4903  for(;;) Line 5712  for(;;)
5712    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
5713    or ANY or ANYCRLF, advance the match position by one more character. */    or ANY or ANYCRLF, advance the match position by one more character. */
5714    
5715    if (start_match[-1] == '\r' &&    if (start_match[-1] == CHAR_CR &&
5716        start_match < end_subject &&        start_match < end_subject &&
5717        *start_match == '\n' &&        *start_match == CHAR_NL &&
5718        (re->flags & PCRE_HASCRORLF) == 0 &&        (re->flags & PCRE_HASCRORLF) == 0 &&
5719          (md->nltype == NLTYPE_ANY ||          (md->nltype == NLTYPE_ANY ||
5720           md->nltype == NLTYPE_ANYCRLF ||           md->nltype == NLTYPE_ANYCRLF ||
# Line 4979  if (using_temporary_offsets) Line 5788  if (using_temporary_offsets)
5788    (pcre_free)(md->offset_vector);    (pcre_free)(md->offset_vector);
5789    }    }
5790    
5791  if (rc != MATCH_NOMATCH)  if (rc != MATCH_NOMATCH && rc != PCRE_ERROR_PARTIAL)
5792    {    {
5793    DPRINTF((">>>> error: returning %d\n", rc));    DPRINTF((">>>> error: returning %d\n", rc));
5794    return rc;    return rc;
5795    }    }
5796  else if (md->partial && md->hitend)  else if (start_partial != NULL)
5797    {    {
5798    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));    DPRINTF((">>>> returning PCRE_ERROR_PARTIAL\n"));
5799      if (offsetcount > 1)
5800        {
5801        offsets[0] = start_partial - (USPTR)subject;
5802        offsets[1] = end_subject - (USPTR)subject;
5803        }
5804    return PCRE_ERROR_PARTIAL;    return PCRE_ERROR_PARTIAL;
5805    }    }
5806  else  else

Legend:
Removed from v.371  
changed lines
  Added in v.482

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12