/[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 190 by ph10, Thu Jul 19 10:38:20 2007 UTC revision 550 by ph10, Sun Oct 10 16:24:11 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-2007 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 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45    #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49  #define NLBLOCK md             /* Block containing newline information */  #define NLBLOCK md             /* Block containing newline information */
50  #define PSSTART start_subject  /* Field containing processed string start */  #define PSSTART start_subject  /* Field containing processed string start */
51  #define PSEND   end_subject    /* Field containing processed string end */  #define PSEND   end_subject    /* Field containing processed string end */
# Line 53  possible. There are also some static sup Line 57  possible. There are also some static sup
57  #undef min  #undef min
58  #undef max  #undef max
59    
 /* The chain of eptrblocks for tail recursions uses memory in stack workspace,  
 obtained at top level, the size of which is defined by EPTR_WORK_SIZE. */  
   
 #define EPTR_WORK_SIZE (1000)  
   
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert     0x01  /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
 #define match_tail_recursed  0x04  /* Tail recursive call */  
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 70  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_ACCEPT       (-999)
75    #define MATCH_COMMIT       (-998)
76    #define MATCH_PRUNE        (-997)
77    #define MATCH_SKIP         (-996)
78    #define MATCH_SKIP_ARG     (-995)
79    #define MATCH_THEN         (-994)
80    
81    /* This is a convenience macro for code that occurs many times. */
82    
83    #define MRRETURN(ra) \
84      { \
85      md->mark = markptr; \
86      RRETURN(ra); \
87      }
88    
89  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
90  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
91  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 83  static const char rep_max[] = { 0, 0, 0, Line 99  static const char rep_max[] = { 0, 0, 0,
99    
100    
101    
102  #ifdef DEBUG  #ifdef PCRE_DEBUG
103  /*************************************************  /*************************************************
104  *        Debugging function to print chars       *  *        Debugging function to print chars       *
105  *************************************************/  *************************************************/
# Line 135  match_ref(int offset, register USPTR ept Line 151  match_ref(int offset, register USPTR ept
151  {  {
152  USPTR p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
153    
154  #ifdef DEBUG  #ifdef PCRE_DEBUG
155  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
156    printf("matching subject <null>");    printf("matching subject <null>");
157  else  else
# Line 152  printf("\n"); Line 168  printf("\n");
168    
169  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
170    
171  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
172    properly if Unicode properties are supported. Otherwise, we can check only
173    ASCII characters. */
174    
175  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
176    {    {
177    #ifdef SUPPORT_UTF8
178    #ifdef SUPPORT_UCP
179      if (md->utf8)
180        {
181        USPTR endptr = eptr + length;
182        while (eptr < endptr)
183          {
184          int c, d;
185          GETCHARINC(c, eptr);
186          GETCHARINC(d, p);
187          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
188          }
189        }
190      else
191    #endif
192    #endif
193    
194      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
195      is no UCP support. */
196    
197    while (length-- > 0)    while (length-- > 0)
198      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
199    }    }
200    
201    /* In the caseful case, we can just compare the bytes, whether or not we
202    are in UTF-8 mode. */
203    
204  else  else
205    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
206    
# Line 205  variable instead of being passed in the Line 247  variable instead of being passed in the
247  ****************************************************************************  ****************************************************************************
248  ***************************************************************************/  ***************************************************************************/
249    
250    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
251  /* Numbers for RMATCH calls */  below must be updated in sync.  */
252    
253  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
254         RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,         RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
255         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,         RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
256         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
257         RM41,  RM42, RM43, RM44, RM45, RM46, RM47 };         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
258           RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
259           RM61,  RM62 };
260    
261  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
262  versions and production versions. Note that the "rw" argument of RMATCH isn't  versions and production versions. Note that the "rw" argument of RMATCH isn't
263  actuall used in this definition. */  actually used in this definition. */
264    
265  #ifndef NO_RECURSE  #ifndef NO_RECURSE
266  #define REGISTER register  #define REGISTER register
267    
268  #ifdef DEBUG  #ifdef PCRE_DEBUG
269  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
270    { \    { \
271    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
272    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \
273    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
274    }    }
275  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 236  actuall used in this definition. */ Line 279  actuall used in this definition. */
279    }    }
280  #else  #else
281  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
282    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)
283  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
284  #endif  #endif
285    
# Line 252  argument of match(), which never changes Line 295  argument of match(), which never changes
295  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
296    {\    {\
297    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
298      if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
299    frame->Xwhere = rw; \    frame->Xwhere = rw; \
300    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
301    newframe->Xecode = rb;\    newframe->Xecode = rb;\
302    newframe->Xmstart = mstart;\    newframe->Xmstart = mstart;\
303      newframe->Xmarkptr = markptr;\
304    newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
305    newframe->Xims = re;\    newframe->Xims = re;\
306    newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
# Line 271  argument of match(), which never changes Line 316  argument of match(), which never changes
316    
317  #define RRETURN(ra)\  #define RRETURN(ra)\
318    {\    {\
319    heapframe *newframe = frame;\    heapframe *oldframe = frame;\
320    frame = newframe->Xprevframe;\    frame = oldframe->Xprevframe;\
321    (pcre_stack_free)(newframe);\    (pcre_stack_free)(oldframe);\
322    if (frame != NULL)\    if (frame != NULL)\
323      {\      {\
324      rrc = ra;\      rrc = ra;\
# Line 290  typedef struct heapframe { Line 335  typedef struct heapframe {
335    
336    /* Function arguments that may change */    /* Function arguments that may change */
337    
338    const uschar *Xeptr;    USPTR Xeptr;
339    const uschar *Xecode;    const uschar *Xecode;
340    const uschar *Xmstart;    USPTR Xmstart;
341      USPTR Xmarkptr;
342    int Xoffset_top;    int Xoffset_top;
343    long int Xims;    long int Xims;
344    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 301  typedef struct heapframe { Line 347  typedef struct heapframe {
347    
348    /* Function local variables */    /* Function local variables */
349    
350    const uschar *Xcallpat;    USPTR Xcallpat;
351    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
352    const uschar *Xdata;    USPTR Xcharptr;
353    const uschar *Xnext;  #endif
354    const uschar *Xpp;    USPTR Xdata;
355    const uschar *Xprev;    USPTR Xnext;
356    const uschar *Xsaved_eptr;    USPTR Xpp;
357      USPTR Xprev;
358      USPTR Xsaved_eptr;
359    
360    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
361    
# Line 328  typedef struct heapframe { Line 376  typedef struct heapframe {
376    uschar Xocchars[8];    uschar Xocchars[8];
377  #endif  #endif
378    
379      int Xcodelink;
380    int Xctype;    int Xctype;
381    unsigned int Xfc;    unsigned int Xfc;
382    int Xfi;    int Xfi;
# Line 363  typedef struct heapframe { Line 412  typedef struct heapframe {
412    
413  /* This function is called recursively in many circumstances. Whenever it  /* This function is called recursively in many circumstances. Whenever it
414  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
415  same response.  same response. */
416    
417    /* These macros pack up tests that are used for partial matching, and which
418    appears several times in the code. We set the "hit end" flag if the pointer is
419    at the end of the subject and also past the start of the subject (i.e.
420    something has been matched). For hard partial matching, we then return
421    immediately. The second one is used when we already know we are past the end of
422    the subject. */
423    
424    #define CHECK_PARTIAL()\
425      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
426        {\
427        md->hitend = TRUE;\
428        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\
429        }
430    
431    #define SCHECK_PARTIAL()\
432      if (md->partial != 0 && eptr > mstart)\
433        {\
434        md->hitend = TRUE;\
435        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\
436        }
437    
438  Performance note: It might be tempting to extract commonly used fields from the  
439  md structure (e.g. utf8, end_subject) into individual variables to improve  /* Performance note: It might be tempting to extract commonly used fields from
440    the md structure (e.g. utf8, end_subject) into individual variables to improve
441  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
442  made performance worse.  made performance worse.
443    
# Line 375  Arguments: Line 446  Arguments:
446     ecode       pointer to current position in compiled code     ecode       pointer to current position in compiled code
447     mstart      pointer to the current match start position (can be modified     mstart      pointer to the current match start position (can be modified
448                   by encountering \K)                   by encountering \K)
449       markptr     pointer to the most recent MARK name, or NULL
450     offset_top  current top pointer     offset_top  current top pointer
451     md          pointer to "static" info for the match     md          pointer to "static" info for the match
452     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 384  Arguments: Line 456  Arguments:
456                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
457                   match_cbegroup - this is the start of an unlimited repeat                   match_cbegroup - this is the start of an unlimited repeat
458                     group that can match an empty string                     group that can match an empty string
                  match_tail_recursed - this is a tail_recursed group  
459     rdepth      the recursion depth     rdepth      the recursion depth
460    
461  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
462                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
463                   a negative MATCH_xxx value for PRUNE, SKIP, etc
464                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
465                   (e.g. stopped by repeated call or recursion limit)                   (e.g. stopped by repeated call or recursion limit)
466  */  */
467    
468  static int  static int
469  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, const uschar *mstart,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
470    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    const uschar *markptr, int offset_top, match_data *md, unsigned long int ims,
471    int flags, unsigned int rdepth)    eptrblock *eptrb, int flags, unsigned int rdepth)
472  {  {
473  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
474  so they can be ordinary variables in all cases. Mark some of them with  so they can be ordinary variables in all cases. Mark some of them with
# Line 408  register unsigned int c; /* Character Line 480  register unsigned int c; /* Character
480  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
481    
482  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
483    int condcode;
484    
485  /* 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
486  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 416  heap whenever RMATCH() does a "recursion Line 489  heap whenever RMATCH() does a "recursion
489    
490  #ifdef NO_RECURSE  #ifdef NO_RECURSE
491  heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));  heapframe *frame = (pcre_stack_malloc)(sizeof(heapframe));
492    if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
493  frame->Xprevframe = NULL;            /* Marks the top level */  frame->Xprevframe = NULL;            /* Marks the top level */
494    
495  /* Copy in the original argument variables */  /* Copy in the original argument variables */
# Line 423  frame->Xprevframe = NULL; /* Line 497  frame->Xprevframe = NULL; /*
497  frame->Xeptr = eptr;  frame->Xeptr = eptr;
498  frame->Xecode = ecode;  frame->Xecode = ecode;
499  frame->Xmstart = mstart;  frame->Xmstart = mstart;
500    frame->Xmarkptr = markptr;
501  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
502  frame->Xims = ims;  frame->Xims = ims;
503  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 438  HEAP_RECURSE: Line 513  HEAP_RECURSE:
513  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
514  #define ecode              frame->Xecode  #define ecode              frame->Xecode
515  #define mstart             frame->Xmstart  #define mstart             frame->Xmstart
516    #define markptr            frame->Xmarkptr
517  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
518  #define ims                frame->Xims  #define ims                frame->Xims
519  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 450  HEAP_RECURSE: Line 526  HEAP_RECURSE:
526  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
527  #endif  #endif
528  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
529    #define codelink           frame->Xcodelink
530  #define data               frame->Xdata  #define data               frame->Xdata
531  #define next               frame->Xnext  #define next               frame->Xnext
532  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 530  int oclength; Line 607  int oclength;
607  uschar occhars[8];  uschar occhars[8];
608  #endif  #endif
609    
610    int codelink;
611  int ctype;  int ctype;
612  int length;  int length;
613  int max;  int max;
# Line 563  TAIL_RECURSE: Line 641  TAIL_RECURSE:
641  /* 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
642  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
643  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()
644  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
645  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
646  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,
647  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
# Line 586  original_ims = ims; /* Save for reset Line 664  original_ims = ims; /* Save for reset
664  string, the match_cbegroup flag is set. When this is the case, add the current  string, the match_cbegroup flag is set. When this is the case, add the current
665  subject pointer to the chain of such remembered pointers, to be checked when we  subject pointer to the chain of such remembered pointers, to be checked when we
666  hit the closing ket, in order to break infinite loops that match no characters.  hit the closing ket, in order to break infinite loops that match no characters.
667  When match() is called in other circumstances, don't add to the chain. If this  When match() is called in other circumstances, don't add to the chain. The
668  is a tail recursion, use a block from the workspace, as the one on the stack is  match_cbegroup flag must NOT be used with tail recursion, because the memory
669  already used. */  block that is used is on the stack, so a new one may be required for each
670    match(). */
671    
672  if ((flags & match_cbegroup) != 0)  if ((flags & match_cbegroup) != 0)
673    {    {
674    eptrblock *p;    newptrb.epb_saved_eptr = eptr;
675    if ((flags & match_tail_recursed) != 0)    newptrb.epb_prev = eptrb;
676      {    eptrb = &newptrb;
     if (md->eptrn >= EPTR_WORK_SIZE) RRETURN(PCRE_ERROR_NULLWSLIMIT);  
     p = md->eptrchain + md->eptrn++;  
     }  
   else p = &newptrb;  
   p->epb_saved_eptr = eptr;  
   p->epb_prev = eptrb;  
   eptrb = p;  
677    }    }
678    
679  /* Now start processing the opcodes. */  /* Now start processing the opcodes. */
# Line 611  for (;;) Line 683  for (;;)
683    minimize = possessive = FALSE;    minimize = possessive = FALSE;
684    op = *ecode;    op = *ecode;
685    
   /* 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;  
   
686    switch(op)    switch(op)
687      {      {
688        case OP_MARK:
689        markptr = ecode + 2;
690        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
691          ims, eptrb, flags, RM55);
692    
693        /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
694        argument, and we must check whether that argument matches this MARK's
695        argument. It is passed back in md->start_match_ptr (an overloading of that
696        variable). If it does match, we reset that variable to the current subject
697        position and return MATCH_SKIP. Otherwise, pass back the return code
698        unaltered. */
699    
700        if (rrc == MATCH_SKIP_ARG &&
701            strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
702          {
703          md->start_match_ptr = eptr;
704          RRETURN(MATCH_SKIP);
705          }
706    
707        if (md->mark == NULL) md->mark = markptr;
708        RRETURN(rrc);
709    
710        case OP_FAIL:
711        MRRETURN(MATCH_NOMATCH);
712    
713        case OP_COMMIT:
714        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
715          ims, eptrb, flags, RM52);
716        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
717        MRRETURN(MATCH_COMMIT);
718    
719        case OP_PRUNE:
720        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
721          ims, eptrb, flags, RM51);
722        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
723        MRRETURN(MATCH_PRUNE);
724    
725        case OP_PRUNE_ARG:
726        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
727          ims, eptrb, flags, RM56);
728        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
729        md->mark = ecode + 2;
730        RRETURN(MATCH_PRUNE);
731    
732        case OP_SKIP:
733        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
734          ims, eptrb, flags, RM53);
735        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
736        md->start_match_ptr = eptr;   /* Pass back current position */
737        MRRETURN(MATCH_SKIP);
738    
739        case OP_SKIP_ARG:
740        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
741          ims, eptrb, flags, RM57);
742        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
743    
744        /* Pass back the current skip name by overloading md->start_match_ptr and
745        returning the special MATCH_SKIP_ARG return code. This will either be
746        caught by a matching MARK, or get to the top, where it is treated the same
747        as PRUNE. */
748    
749        md->start_match_ptr = ecode + 2;
750        RRETURN(MATCH_SKIP_ARG);
751    
752        /* For THEN (and THEN_ARG) we pass back the address of the bracket or
753        the alt that is at the start of the current branch. This makes it possible
754        to skip back past alternatives that precede the THEN within the current
755        branch. */
756    
757        case OP_THEN:
758        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
759          ims, eptrb, flags, RM54);
760        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
761        md->start_match_ptr = ecode - GET(ecode, 1);
762        MRRETURN(MATCH_THEN);
763    
764        case OP_THEN_ARG:
765        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],
766          offset_top, md, ims, eptrb, flags, RM58);
767        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
768        md->start_match_ptr = ecode - GET(ecode, 1);
769        md->mark = ecode + LINK_SIZE + 2;
770        RRETURN(MATCH_THEN);
771    
772      /* Handle a capturing bracket. If there is space in the offset vector, save      /* Handle a capturing bracket. If there is space in the offset vector, save
773      the current subject position in the working slot at the top of the vector.      the current subject position in the working slot at the top of the vector.
774      We mustn't change the current values of the data slot, because they may be      We mustn't change the current values of the data slot, because they may be
# Line 640  for (;;) Line 788  for (;;)
788      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
789      offset = number << 1;      offset = number << 1;
790    
791  #ifdef DEBUG  #ifdef PCRE_DEBUG
792      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
793      printf("subject=");      printf("subject=");
794      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
# Line 655  for (;;) Line 803  for (;;)
803        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
804    
805        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
806        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] =
807            (int)(eptr - md->start_subject);
808    
809        flags = (op == OP_SCBRA)? match_cbegroup : 0;        flags = (op == OP_SCBRA)? match_cbegroup : 0;
810        do        do
811          {          {
812          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
813            ims, eptrb, flags, RM1);            ims, eptrb, flags, RM1);
814          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH &&
815                (rrc != MATCH_THEN || md->start_match_ptr != ecode))
816              RRETURN(rrc);
817          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
818          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
819          }          }
# Line 674  for (;;) Line 825  for (;;)
825        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
826        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
827    
828          if (rrc != MATCH_THEN) md->mark = markptr;
829        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
830        }        }
831    
832      /* Insufficient room for saving captured contents. Treat as a non-capturing      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
833      bracket. */      as a non-capturing bracket. */
834    
835        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
836        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
837    
838      DPRINTF(("insufficient capture room: treat as non-capturing\n"));      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
839    
840        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
841        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
842    
843      /* Non-capturing bracket. Loop for all the alternatives. When we get to the      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
844      final alternative within the brackets, we would return the result of a      final alternative within the brackets, we would return the result of a
845      recursive call to match() whatever happened. We can reduce stack usage by      recursive call to match() whatever happened. We can reduce stack usage by
846      turning this into a tail recursion. */      turning this into a tail recursion, except in the case when match_cbegroup
847        is set.*/
848    
849      case OP_BRA:      case OP_BRA:
850      case OP_SBRA:      case OP_SBRA:
# Line 693  for (;;) Line 852  for (;;)
852      flags = (op >= OP_SBRA)? match_cbegroup : 0;      flags = (op >= OP_SBRA)? match_cbegroup : 0;
853      for (;;)      for (;;)
854        {        {
855        if (ecode[GET(ecode, 1)] != OP_ALT)        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
856          {          {
857          ecode += _pcre_OP_lengths[*ecode];          if (flags == 0)    /* Not a possibly empty group */
858          flags |= match_tail_recursed;            {
859          DPRINTF(("bracket 0 tail recursion\n"));            ecode += _pcre_OP_lengths[*ecode];
860          goto TAIL_RECURSE;            DPRINTF(("bracket 0 tail recursion\n"));
861              goto TAIL_RECURSE;
862              }
863    
864            /* Possibly empty group; can't use tail recursion. */
865    
866            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
867              eptrb, flags, RM48);
868            if (rrc == MATCH_NOMATCH) md->mark = markptr;
869            RRETURN(rrc);
870          }          }
871    
872        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
# Line 706  for (;;) Line 874  for (;;)
874    
875        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
876          eptrb, flags, RM2);          eptrb, flags, RM2);
877        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH &&
878              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
879            RRETURN(rrc);
880        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
881        }        }
882      /* Control never reaches here. */      /* Control never reaches here. */
# Line 719  for (;;) Line 889  for (;;)
889    
890      case OP_COND:      case OP_COND:
891      case OP_SCOND:      case OP_SCOND:
892      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
893    
894        /* Because of the way auto-callout works during compile, a callout item is
895        inserted between OP_COND and an assertion condition. */
896    
897        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
898        {        {
899        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        if (pcre_callout != NULL)
900        condition = md->recursive != NULL &&          {
901          (offset == RREF_ANY || offset == md->recursive->group_num);          pcre_callout_block cb;
902        ecode += condition? 3 : GET(ecode, 1);          cb.version          = 1;   /* Version 1 of the callout block */
903            cb.callout_number   = ecode[LINK_SIZE+2];
904            cb.offset_vector    = md->offset_vector;
905            cb.subject          = (PCRE_SPTR)md->start_subject;
906            cb.subject_length   = (int)(md->end_subject - md->start_subject);
907            cb.start_match      = (int)(mstart - md->start_subject);
908            cb.current_position = (int)(eptr - md->start_subject);
909            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
910            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
911            cb.capture_top      = offset_top/2;
912            cb.capture_last     = md->capture_last;
913            cb.callout_data     = md->callout_data;
914            if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
915            if (rrc < 0) RRETURN(rrc);
916            }
917          ecode += _pcre_OP_lengths[OP_CALLOUT];
918          }
919    
920        condcode = ecode[LINK_SIZE+1];
921    
922        /* Now see what the actual condition is */
923    
924        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
925          {
926          if (md->recursive == NULL)                /* Not recursing => FALSE */
927            {
928            condition = FALSE;
929            ecode += GET(ecode, 1);
930            }
931          else
932            {
933            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
934            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
935    
936            /* If the test is for recursion into a specific subpattern, and it is
937            false, but the test was set up by name, scan the table to see if the
938            name refers to any other numbers, and test them. The condition is true
939            if any one is set. */
940    
941            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
942              {
943              uschar *slotA = md->name_table;
944              for (i = 0; i < md->name_count; i++)
945                {
946                if (GET2(slotA, 0) == recno) break;
947                slotA += md->name_entry_size;
948                }
949    
950              /* Found a name for the number - there can be only one; duplicate
951              names for different numbers are allowed, but not vice versa. First
952              scan down for duplicates. */
953    
954              if (i < md->name_count)
955                {
956                uschar *slotB = slotA;
957                while (slotB > md->name_table)
958                  {
959                  slotB -= md->name_entry_size;
960                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
961                    {
962                    condition = GET2(slotB, 0) == md->recursive->group_num;
963                    if (condition) break;
964                    }
965                  else break;
966                  }
967    
968                /* Scan up for duplicates */
969    
970                if (!condition)
971                  {
972                  slotB = slotA;
973                  for (i++; i < md->name_count; i++)
974                    {
975                    slotB += md->name_entry_size;
976                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
977                      {
978                      condition = GET2(slotB, 0) == md->recursive->group_num;
979                      if (condition) break;
980                      }
981                    else break;
982                    }
983                  }
984                }
985              }
986    
987            /* Chose branch according to the condition */
988    
989            ecode += condition? 3 : GET(ecode, 1);
990            }
991        }        }
992    
993      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
994        {        {
995        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
996        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
997    
998          /* If the numbered capture is unset, but the reference was by name,
999          scan the table to see if the name refers to any other numbers, and test
1000          them. The condition is true if any one is set. This is tediously similar
1001          to the code above, but not close enough to try to amalgamate. */
1002    
1003          if (!condition && condcode == OP_NCREF)
1004            {
1005            int refno = offset >> 1;
1006            uschar *slotA = md->name_table;
1007    
1008            for (i = 0; i < md->name_count; i++)
1009              {
1010              if (GET2(slotA, 0) == refno) break;
1011              slotA += md->name_entry_size;
1012              }
1013    
1014            /* Found a name for the number - there can be only one; duplicate names
1015            for different numbers are allowed, but not vice versa. First scan down
1016            for duplicates. */
1017    
1018            if (i < md->name_count)
1019              {
1020              uschar *slotB = slotA;
1021              while (slotB > md->name_table)
1022                {
1023                slotB -= md->name_entry_size;
1024                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1025                  {
1026                  offset = GET2(slotB, 0) << 1;
1027                  condition = offset < offset_top &&
1028                    md->offset_vector[offset] >= 0;
1029                  if (condition) break;
1030                  }
1031                else break;
1032                }
1033    
1034              /* Scan up for duplicates */
1035    
1036              if (!condition)
1037                {
1038                slotB = slotA;
1039                for (i++; i < md->name_count; i++)
1040                  {
1041                  slotB += md->name_entry_size;
1042                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1043                    {
1044                    offset = GET2(slotB, 0) << 1;
1045                    condition = offset < offset_top &&
1046                      md->offset_vector[offset] >= 0;
1047                    if (condition) break;
1048                    }
1049                  else break;
1050                  }
1051                }
1052              }
1053            }
1054    
1055          /* Chose branch according to the condition */
1056    
1057        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
1058        }        }
1059    
1060      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
1061        {        {
1062        condition = FALSE;        condition = FALSE;
1063        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 754  for (;;) Line 1077  for (;;)
1077          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1078          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1079          }          }
1080        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH &&
1081                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1082          {          {
1083          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1084          }          }
1085        else        else
1086          {          {
1087          condition = FALSE;          condition = FALSE;
1088          ecode += GET(ecode, 1);          ecode += codelink;
1089          }          }
1090        }        }
1091    
1092      /* We are now at the branch that is to be obeyed. As there is only one,      /* We are now at the branch that is to be obeyed. As there is only one,
1093      we can use tail recursion to avoid using another stack frame. If the second      we can use tail recursion to avoid using another stack frame, except when
1094      alternative doesn't exist, we can just plough on. */      match_cbegroup is required for an unlimited repeat of a possibly empty
1095        group. If the second alternative doesn't exist, we can just plough on. */
1096    
1097      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
1098        {        {
1099        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1100        flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);        if (op == OP_SCOND)        /* Possibly empty group */
1101        goto TAIL_RECURSE;          {
1102            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1103            RRETURN(rrc);
1104            }
1105          else                       /* Group must match something */
1106            {
1107            flags = 0;
1108            goto TAIL_RECURSE;
1109            }
1110        }        }
1111      else      else                         /* Condition false & no alternative */
1112        {        {
1113        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1114        }        }
1115      break;      break;
1116    
1117    
1118      /* End of the pattern. If we are in a top-level recursion, we should      /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1119      restore the offsets appropriately and continue from after the call. */      to close any currently open capturing brackets. */
1120    
1121        case OP_CLOSE:
1122        number = GET2(ecode, 1);
1123        offset = number << 1;
1124    
1125    #ifdef PCRE_DEBUG
1126          printf("end bracket %d at *ACCEPT", number);
1127          printf("\n");
1128    #endif
1129    
1130        md->capture_last = number;
1131        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1132          {
1133          md->offset_vector[offset] =
1134            md->offset_vector[md->offset_end - number];
1135          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1136          if (offset_top <= offset) offset_top = offset + 2;
1137          }
1138        ecode += 3;
1139        break;
1140    
1141    
1142        /* End of the pattern, either real or forced. If we are in a top-level
1143        recursion, we should restore the offsets appropriately and continue from
1144        after the call. */
1145    
1146        case OP_ACCEPT:
1147      case OP_END:      case OP_END:
1148      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
1149        {        {
# Line 793  for (;;) Line 1152  for (;;)
1152        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1153        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1154          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1155        mstart = rec->save_start;        offset_top = rec->save_offset_top;
1156        ims = original_ims;        ims = original_ims;
1157        ecode = rec->after_call;        ecode = rec->after_call;
1158        break;        break;
1159        }        }
1160    
1161      /* 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
1162      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
1163        the subject. In both cases, backtracking will then try other alternatives,
1164        if any. */
1165    
1166        if (eptr == mstart &&
1167            (md->notempty ||
1168              (md->notempty_atstart &&
1169                mstart == md->start_subject + md->start_offset)))
1170          MRRETURN(MATCH_NOMATCH);
1171    
1172        /* Otherwise, we have a match. */
1173    
     if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);  
1174      md->end_match_ptr = eptr;           /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
1175      md->end_offset_top = offset_top;    /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1176      md->start_match_ptr = mstart;  /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1177      RRETURN(MATCH_MATCH);  
1178        /* For some reason, the macros don't work properly if an expression is
1179        given as the argument to MRRETURN when the heap is in use. */
1180    
1181        rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1182        MRRETURN(rrc);
1183    
1184      /* Change option settings */      /* Change option settings */
1185    
# Line 828  for (;;) Line 1201  for (;;)
1201        {        {
1202        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1203          RM4);          RM4);
1204        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1205        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          {
1206            mstart = md->start_match_ptr;   /* In case \K reset it */
1207            break;
1208            }
1209          if (rrc != MATCH_NOMATCH &&
1210              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1211            RRETURN(rrc);
1212        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1213        }        }
1214      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1215      if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1216    
1217      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1218    
# Line 847  for (;;) Line 1226  for (;;)
1226      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1227      continue;      continue;
1228    
1229      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1230        PRUNE, or COMMIT means we must assume failure without checking subsequent
1231        branches. */
1232    
1233      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1234      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
# Line 855  for (;;) Line 1236  for (;;)
1236        {        {
1237        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1238          RM5);          RM5);
1239        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
1240        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1241            {
1242            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1243            break;
1244            }
1245          if (rrc != MATCH_NOMATCH &&
1246              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1247            RRETURN(rrc);
1248        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1249        }        }
1250      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 879  for (;;) Line 1267  for (;;)
1267        while (i-- > 0)        while (i-- > 0)
1268          {          {
1269          eptr--;          eptr--;
1270          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1271          BACKCHAR(eptr)          BACKCHAR(eptr);
1272          }          }
1273        }        }
1274      else      else
# Line 890  for (;;) Line 1278  for (;;)
1278    
1279        {        {
1280        eptr -= GET(ecode, 1);        eptr -= GET(ecode, 1);
1281        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1282        }        }
1283    
1284      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1285    
1286        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1287      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1288      break;      break;
1289    
# Line 910  for (;;) Line 1299  for (;;)
1299        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1300        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1301        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1302        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1303        cb.start_match      = mstart - md->start_subject;        cb.start_match      = (int)(mstart - md->start_subject);
1304        cb.current_position = eptr - md->start_subject;        cb.current_position = (int)(eptr - md->start_subject);
1305        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1306        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1307        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1308        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1309        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1310        if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
1311        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1312        }        }
1313      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 973  for (;;) Line 1362  for (;;)
1362    
1363        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1364              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1365        new_recursive.save_start = mstart;        new_recursive.save_offset_top = offset_top;
       mstart = eptr;  
1366    
1367        /* 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
1368        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 985  for (;;) Line 1373  for (;;)
1373          {          {
1374          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1375            md, ims, eptrb, flags, RM6);            md, ims, eptrb, flags, RM6);
1376          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1377            {            {
1378            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1379            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1380            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1381              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1382            RRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1383            }            }
1384          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH &&
1385                    (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1386            {            {
1387            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1388              if (new_recursive.offset_save != stacksave)
1389                (pcre_free)(new_recursive.offset_save);
1390            RRETURN(rrc);            RRETURN(rrc);
1391            }            }
1392    
# Line 1010  for (;;) Line 1401  for (;;)
1401        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1402        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1403          (pcre_free)(new_recursive.offset_save);          (pcre_free)(new_recursive.offset_save);
1404        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1405        }        }
1406      /* Control never reaches here */      /* Control never reaches here */
1407    
# Line 1019  for (;;) Line 1410  for (;;)
1410      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1411      Check the alternative branches in turn - the matching won't pass the KET      Check the alternative branches in turn - the matching won't pass the KET
1412      for this kind of subpattern. If any one branch matches, we carry on as at      for this kind of subpattern. If any one branch matches, we carry on as at
1413      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1414        the start-of-match value in case it was changed by \K. */
1415    
1416      case OP_ONCE:      case OP_ONCE:
1417      prev = ecode;      prev = ecode;
# Line 1027  for (;;) Line 1419  for (;;)
1419    
1420      do      do
1421        {        {
1422        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1423          eptrb, 0, RM7);        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1424        if (rrc == MATCH_MATCH) break;          {
1425        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          mstart = md->start_match_ptr;
1426            break;
1427            }
1428          if (rrc != MATCH_NOMATCH &&
1429              (rrc != MATCH_THEN || md->start_match_ptr != ecode))
1430            RRETURN(rrc);
1431        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1432        }        }
1433      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1073  for (;;) Line 1470  for (;;)
1470    
1471      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1472        {        {
1473        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
         RM8);  
1474        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1475        ecode = prev;        ecode = prev;
1476        flags = match_tail_recursed;        flags = 0;
1477        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1478        }        }
1479      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
# Line 1085  for (;;) Line 1481  for (;;)
1481        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1482        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1483        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1484        flags = match_tail_recursed;        flags = 0;
1485        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1486        }        }
1487      /* Control never gets here */      /* Control never gets here */
# Line 1097  for (;;) Line 1493  for (;;)
1493      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1494      break;      break;
1495    
1496      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1497      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1498      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1499      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1500      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1501    
1502      case OP_BRAZERO:      case OP_BRAZERO:
1503        {        {
# Line 1123  for (;;) Line 1519  for (;;)
1519        }        }
1520      break;      break;
1521    
1522        case OP_SKIPZERO:
1523          {
1524          next = ecode+1;
1525          do next += GET(next,1); while (*next == OP_ALT);
1526          ecode = next + 1 + LINK_SIZE;
1527          }
1528        break;
1529    
1530      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1531    
1532      case OP_KET:      case OP_KET:
# Line 1141  for (;;) Line 1545  for (;;)
1545        }        }
1546      else saved_eptr = NULL;      else saved_eptr = NULL;
1547    
1548      /* If we are at the end of an assertion group, stop matching and return      /* If we are at the end of an assertion group or an atomic group, stop
1549      MATCH_MATCH, but record the current high water mark for use by positive      matching and return MATCH_MATCH, but record the current high water mark for
1550      assertions. Do this also for the "once" (atomic) groups. */      use by positive assertions. We also need to record the match start in case
1551        it was changed by \K. */
1552    
1553      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1554          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1151  for (;;) Line 1556  for (;;)
1556        {        {
1557        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1558        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1559        RRETURN(MATCH_MATCH);        md->start_match_ptr = mstart;
1560          MRRETURN(MATCH_MATCH);
1561        }        }
1562    
1563      /* For capturing groups we have to check the group number back at the start      /* For capturing groups we have to check the group number back at the start
# Line 1165  for (;;) Line 1571  for (;;)
1571        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1572        offset = number << 1;        offset = number << 1;
1573    
1574  #ifdef DEBUG  #ifdef PCRE_DEBUG
1575        printf("end bracket %d", number);        printf("end bracket %d", number);
1576        printf("\n");        printf("\n");
1577  #endif  #endif
# Line 1175  for (;;) Line 1581  for (;;)
1581          {          {
1582          md->offset_vector[offset] =          md->offset_vector[offset] =
1583            md->offset_vector[md->offset_end - number];            md->offset_vector[md->offset_end - number];
1584          md->offset_vector[offset+1] = eptr - md->start_subject;          md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1585          if (offset_top <= offset) offset_top = offset + 2;          if (offset_top <= offset) offset_top = offset + 2;
1586          }          }
1587    
# Line 1187  for (;;) Line 1593  for (;;)
1593          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1594          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1595          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
         mstart = rec->save_start;  
1596          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1597            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1598            offset_top = rec->save_offset_top;
1599          ecode = rec->after_call;          ecode = rec->after_call;
1600          ims = original_ims;          ims = original_ims;
1601          break;          break;
# Line 1216  for (;;) Line 1622  for (;;)
1622    
1623      /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1624      preceding bracket, in the appropriate order. In the second case, we can use      preceding bracket, in the appropriate order. In the second case, we can use
1625      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1626        unlimited repeat of a group that can match an empty string. */
1627    
1628      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1629    
1630      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1631        {        {
1632        RMATCH(eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
         RM12);  
1633        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1634          if (flags != 0)    /* Could match an empty string */
1635            {
1636            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1637            RRETURN(rrc);
1638            }
1639        ecode = prev;        ecode = prev;
       flags |= match_tail_recursed;  
1640        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1641        }        }
1642      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
# Line 1234  for (;;) Line 1644  for (;;)
1644        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1645        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1646        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1647        flags = match_tail_recursed;        flags = 0;
1648        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1649        }        }
1650      /* Control never gets here */      /* Control never gets here */
# Line 1242  for (;;) Line 1652  for (;;)
1652      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1653    
1654      case OP_CIRC:      case OP_CIRC:
1655      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1656      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1657        {        {
1658        if (eptr != md->start_subject &&        if (eptr != md->start_subject &&
1659            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1660          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
1661        ecode++;        ecode++;
1662        break;        break;
1663        }        }
# Line 1256  for (;;) Line 1666  for (;;)
1666      /* Start of subject assertion */      /* Start of subject assertion */
1667    
1668      case OP_SOD:      case OP_SOD:
1669      if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1670      ecode++;      ecode++;
1671      break;      break;
1672    
1673      /* Start of match assertion */      /* Start of match assertion */
1674    
1675      case OP_SOM:      case OP_SOM:
1676      if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);
1677      ecode++;      ecode++;
1678      break;      break;
1679    
# Line 1281  for (;;) Line 1691  for (;;)
1691      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1692        {        {
1693        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1694          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
1695        else        else
1696          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) MRRETURN(MATCH_NOMATCH); }
1697        ecode++;        ecode++;
1698        break;        break;
1699        }        }
1700      else      else
1701        {        {
1702        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1703        if (!md->endonly)        if (!md->endonly)
1704          {          {
1705          if (eptr != md->end_subject &&          if (eptr != md->end_subject &&
1706              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1707            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
1708          ecode++;          ecode++;
1709          break;          break;
1710          }          }
# Line 1304  for (;;) Line 1714  for (;;)
1714      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1715    
1716      case OP_EOD:      case OP_EOD:
1717      if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1718      ecode++;      ecode++;
1719      break;      break;
1720    
# Line 1313  for (;;) Line 1723  for (;;)
1723      case OP_EODN:      case OP_EODN:
1724      if (eptr != md->end_subject &&      if (eptr != md->end_subject &&
1725          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1726        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1727      ecode++;      ecode++;
1728      break;      break;
1729    
# Line 1325  for (;;) Line 1735  for (;;)
1735    
1736        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1737        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
1738        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1739          partial matching. */
1740    
1741  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1742        if (utf8)        if (utf8)
1743          {          {
1744            /* Get status of previous character */
1745    
1746          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1747            {            {
1748            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1749            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1750              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1751            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1752    #ifdef SUPPORT_UCP
1753              if (md->use_ucp)
1754                {
1755                if (c == '_') prev_is_word = TRUE; else
1756                  {
1757                  int cat = UCD_CATEGORY(c);
1758                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1759                  }
1760                }
1761              else
1762    #endif
1763            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1764            }            }
1765          if (eptr >= md->end_subject) cur_is_word = FALSE; else  
1766            /* Get status of next character */
1767    
1768            if (eptr >= md->end_subject)
1769              {
1770              SCHECK_PARTIAL();
1771              cur_is_word = FALSE;
1772              }
1773            else
1774            {            {
1775            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1776    #ifdef SUPPORT_UCP
1777              if (md->use_ucp)
1778                {
1779                if (c == '_') cur_is_word = TRUE; else
1780                  {
1781                  int cat = UCD_CATEGORY(c);
1782                  cur_is_word = (cat == ucp_L || cat == ucp_N);
1783                  }
1784                }
1785              else
1786    #endif
1787            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1788            }            }
1789          }          }
1790        else        else
1791  #endif  #endif
1792    
1793        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
1794          consistency with the behaviour of \w we do use it in this case. */
1795    
1796          {          {
1797          prev_is_word = (eptr != md->start_subject) &&          /* Get status of previous character */
1798            ((md->ctypes[eptr[-1]] & ctype_word) != 0);  
1799          cur_is_word = (eptr < md->end_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1800            ((md->ctypes[*eptr] & ctype_word) != 0);            {
1801              if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1802    #ifdef SUPPORT_UCP
1803              if (md->use_ucp)
1804                {
1805                c = eptr[-1];
1806                if (c == '_') prev_is_word = TRUE; else
1807                  {
1808                  int cat = UCD_CATEGORY(c);
1809                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1810                  }
1811                }
1812              else
1813    #endif
1814              prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1815              }
1816    
1817            /* Get status of next character */
1818    
1819            if (eptr >= md->end_subject)
1820              {
1821              SCHECK_PARTIAL();
1822              cur_is_word = FALSE;
1823              }
1824            else
1825    #ifdef SUPPORT_UCP
1826            if (md->use_ucp)
1827              {
1828              c = *eptr;
1829              if (c == '_') cur_is_word = TRUE; else
1830                {
1831                int cat = UCD_CATEGORY(c);
1832                cur_is_word = (cat == ucp_L || cat == ucp_N);
1833                }
1834              }
1835            else
1836    #endif
1837            cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1838          }          }
1839    
1840        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
1841    
1842        if ((*ecode++ == OP_WORD_BOUNDARY)?        if ((*ecode++ == OP_WORD_BOUNDARY)?
1843             cur_is_word == prev_is_word : cur_is_word != prev_is_word)             cur_is_word == prev_is_word : cur_is_word != prev_is_word)
1844          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
1845        }        }
1846      break;      break;
1847    
1848      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1849    
1850      case OP_ANY:      case OP_ANY:
1851      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
1852        /* Fall through */
1853    
1854        case OP_ALLANY:
1855        if (eptr++ >= md->end_subject)
1856        {        {
1857        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);        SCHECK_PARTIAL();
1858          MRRETURN(MATCH_NOMATCH);
1859        }        }
1860      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1861      ecode++;      ecode++;
1862      break;      break;
1863    
# Line 1380  for (;;) Line 1865  for (;;)
1865      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1866    
1867      case OP_ANYBYTE:      case OP_ANYBYTE:
1868      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1869          {
1870          SCHECK_PARTIAL();
1871          MRRETURN(MATCH_NOMATCH);
1872          }
1873      ecode++;      ecode++;
1874      break;      break;
1875    
1876      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1877      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1878          {
1879          SCHECK_PARTIAL();
1880          MRRETURN(MATCH_NOMATCH);
1881          }
1882      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1883      if (      if (
1884  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1393  for (;;) Line 1886  for (;;)
1886  #endif  #endif
1887         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
1888         )         )
1889        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1890      ecode++;      ecode++;
1891      break;      break;
1892    
1893      case OP_DIGIT:      case OP_DIGIT:
1894      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1895          {
1896          SCHECK_PARTIAL();
1897          MRRETURN(MATCH_NOMATCH);
1898          }
1899      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1900      if (      if (
1901  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1406  for (;;) Line 1903  for (;;)
1903  #endif  #endif
1904         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
1905         )         )
1906        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1907      ecode++;      ecode++;
1908      break;      break;
1909    
1910      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1911      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1912          {
1913          SCHECK_PARTIAL();
1914          MRRETURN(MATCH_NOMATCH);
1915          }
1916      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1917      if (      if (
1918  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1419  for (;;) Line 1920  for (;;)
1920  #endif  #endif
1921         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
1922         )         )
1923        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1924      ecode++;      ecode++;
1925      break;      break;
1926    
1927      case OP_WHITESPACE:      case OP_WHITESPACE:
1928      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1929          {
1930          SCHECK_PARTIAL();
1931          MRRETURN(MATCH_NOMATCH);
1932          }
1933      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1934      if (      if (
1935  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1432  for (;;) Line 1937  for (;;)
1937  #endif  #endif
1938         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
1939         )         )
1940        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1941      ecode++;      ecode++;
1942      break;      break;
1943    
1944      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1945      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1946          {
1947          SCHECK_PARTIAL();
1948          MRRETURN(MATCH_NOMATCH);
1949          }
1950      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1951      if (      if (
1952  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1445  for (;;) Line 1954  for (;;)
1954  #endif  #endif
1955         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
1956         )         )
1957        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1958      ecode++;      ecode++;
1959      break;      break;
1960    
1961      case OP_WORDCHAR:      case OP_WORDCHAR:
1962      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1963          {
1964          SCHECK_PARTIAL();
1965          MRRETURN(MATCH_NOMATCH);
1966          }
1967      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1968      if (      if (
1969  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1458  for (;;) Line 1971  for (;;)
1971  #endif  #endif
1972         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
1973         )         )
1974        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1975      ecode++;      ecode++;
1976      break;      break;
1977    
1978      case OP_ANYNL:      case OP_ANYNL:
1979      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1980          {
1981          SCHECK_PARTIAL();
1982          MRRETURN(MATCH_NOMATCH);
1983          }
1984      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1985      switch(c)      switch(c)
1986        {        {
1987        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
1988        case 0x000d:        case 0x000d:
1989        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1990        break;        break;
1991    
1992        case 0x000a:        case 0x000a:
1993          break;
1994    
1995        case 0x000b:        case 0x000b:
1996        case 0x000c:        case 0x000c:
1997        case 0x0085:        case 0x0085:
1998        case 0x2028:        case 0x2028:
1999        case 0x2029:        case 0x2029:
2000          if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
2001        break;        break;
2002        }        }
2003      ecode++;      ecode++;
2004      break;      break;
2005    
2006      case OP_NOT_HSPACE:      case OP_NOT_HSPACE:
2007      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2008          {
2009          SCHECK_PARTIAL();
2010          MRRETURN(MATCH_NOMATCH);
2011          }
2012      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2013      switch(c)      switch(c)
2014        {        {
# Line 1507  for (;;) Line 2032  for (;;)
2032        case 0x202f:    /* NARROW NO-BREAK SPACE */        case 0x202f:    /* NARROW NO-BREAK SPACE */
2033        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2034        case 0x3000:    /* IDEOGRAPHIC SPACE */        case 0x3000:    /* IDEOGRAPHIC SPACE */
2035        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2036        }        }
2037      ecode++;      ecode++;
2038      break;      break;
2039    
2040      case OP_HSPACE:      case OP_HSPACE:
2041      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2042          {
2043          SCHECK_PARTIAL();
2044          MRRETURN(MATCH_NOMATCH);
2045          }
2046      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2047      switch(c)      switch(c)
2048        {        {
2049        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2050        case 0x09:      /* HT */        case 0x09:      /* HT */
2051        case 0x20:      /* SPACE */        case 0x20:      /* SPACE */
2052        case 0xa0:      /* NBSP */        case 0xa0:      /* NBSP */
# Line 1543  for (;;) Line 2072  for (;;)
2072      break;      break;
2073    
2074      case OP_NOT_VSPACE:      case OP_NOT_VSPACE:
2075      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2076          {
2077          SCHECK_PARTIAL();
2078          MRRETURN(MATCH_NOMATCH);
2079          }
2080      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2081      switch(c)      switch(c)
2082        {        {
# Line 1555  for (;;) Line 2088  for (;;)
2088        case 0x85:      /* NEL */        case 0x85:      /* NEL */
2089        case 0x2028:    /* LINE SEPARATOR */        case 0x2028:    /* LINE SEPARATOR */
2090        case 0x2029:    /* PARAGRAPH SEPARATOR */        case 0x2029:    /* PARAGRAPH SEPARATOR */
2091        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
2092        }        }
2093      ecode++;      ecode++;
2094      break;      break;
2095    
2096      case OP_VSPACE:      case OP_VSPACE:
2097      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2098          {
2099          SCHECK_PARTIAL();
2100          MRRETURN(MATCH_NOMATCH);
2101          }
2102      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2103      switch(c)      switch(c)
2104        {        {
2105        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
2106        case 0x0a:      /* LF */        case 0x0a:      /* LF */
2107        case 0x0b:      /* VT */        case 0x0b:      /* VT */
2108        case 0x0c:      /* FF */        case 0x0c:      /* FF */
# Line 1584  for (;;) Line 2121  for (;;)
2121    
2122      case OP_PROP:      case OP_PROP:
2123      case OP_NOTPROP:      case OP_NOTPROP:
2124      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2125          {
2126          SCHECK_PARTIAL();
2127          MRRETURN(MATCH_NOMATCH);
2128          }
2129      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2130        {        {
2131        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
2132    
2133        switch(ecode[1])        switch(ecode[1])
2134          {          {
2135          case PT_ANY:          case PT_ANY:
2136          if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);          if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);
2137          break;          break;
2138    
2139          case PT_LAMP:          case PT_LAMP:
2140          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
2141               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2142               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2143            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2144           break;          break;
2145    
2146          case PT_GC:          case PT_GC:
2147          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
2148            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2149          break;          break;
2150    
2151          case PT_PC:          case PT_PC:
2152          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2153            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2154          break;          break;
2155    
2156          case PT_SC:          case PT_SC:
2157          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2158            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2159            break;
2160    
2161            /* These are specials */
2162    
2163            case PT_ALNUM:
2164            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2165                 _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2166              MRRETURN(MATCH_NOMATCH);
2167            break;
2168    
2169            case PT_SPACE:    /* Perl space */
2170            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2171                 c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2172                   == (op == OP_NOTPROP))
2173              MRRETURN(MATCH_NOMATCH);
2174            break;
2175    
2176            case PT_PXSPACE:  /* POSIX space */
2177            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2178                 c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2179                 c == CHAR_FF || c == CHAR_CR)
2180                   == (op == OP_NOTPROP))
2181              MRRETURN(MATCH_NOMATCH);
2182            break;
2183    
2184            case PT_WORD:
2185            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2186                 _pcre_ucp_gentype[prop->chartype] == ucp_N ||
2187                 c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2188              MRRETURN(MATCH_NOMATCH);
2189          break;          break;
2190    
2191            /* This should never occur */
2192    
2193          default:          default:
2194          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
2195          }          }
# Line 1630  for (;;) Line 2202  for (;;)
2202      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2203    
2204      case OP_EXTUNI:      case OP_EXTUNI:
2205      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2206          {
2207          SCHECK_PARTIAL();
2208          MRRETURN(MATCH_NOMATCH);
2209          }
2210      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2211        {        {
2212        int chartype, script;        int category = UCD_CATEGORY(c);
2213        int category = _pcre_ucp_findprop(c, &chartype, &script);        if (category == ucp_M) MRRETURN(MATCH_NOMATCH);
       if (category == ucp_M) RRETURN(MATCH_NOMATCH);  
2214        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2215          {          {
2216          int len = 1;          int len = 1;
# Line 1643  for (;;) Line 2218  for (;;)
2218            {            {
2219            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
2220            }            }
2221          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
2222          if (category != ucp_M) break;          if (category != ucp_M) break;
2223          eptr += len;          eptr += len;
2224          }          }
# Line 1664  for (;;) Line 2239  for (;;)
2239      case OP_REF:      case OP_REF:
2240        {        {
2241        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2242        ecode += 3;                                 /* Advance past item */        ecode += 3;
2243    
2244          /* If the reference is unset, there are two possibilities:
2245    
2246        /* If the reference is unset, set the length to be longer than the amount        (a) In the default, Perl-compatible state, set the length to be longer
2247        of subject left; this ensures that every attempt at a match fails. We        than the amount of subject left; this ensures that every attempt at a
2248        can't just fail here, because of the possibility of quantifiers with zero        match fails. We can't just fail here, because of the possibility of
2249        minima. */        quantifiers with zero minima.
2250    
2251        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        (b) If the JavaScript compatibility flag is set, set the length to zero
2252          md->end_subject - eptr + 1 :        so that the back reference matches an empty string.
2253          md->offset_vector[offset+1] - md->offset_vector[offset];  
2254          Otherwise, set the length to the length of what was matched by the
2255          referenced subpattern. */
2256    
2257          if (offset >= offset_top || md->offset_vector[offset] < 0)
2258            length = (md->jscript_compat)? 0 : (int)(md->end_subject - eptr + 1);
2259          else
2260            length = md->offset_vector[offset+1] - md->offset_vector[offset];
2261    
2262        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
2263    
# Line 1702  for (;;) Line 2286  for (;;)
2286          break;          break;
2287    
2288          default:               /* No repeat follows */          default:               /* No repeat follows */
2289          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2290              {
2291              CHECK_PARTIAL();
2292              MRRETURN(MATCH_NOMATCH);
2293              }
2294          eptr += length;          eptr += length;
2295          continue;              /* With the main loop */          continue;              /* With the main loop */
2296          }          }
# Line 1718  for (;;) Line 2306  for (;;)
2306    
2307        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2308          {          {
2309          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2310              {
2311              CHECK_PARTIAL();
2312              MRRETURN(MATCH_NOMATCH);
2313              }
2314          eptr += length;          eptr += length;
2315          }          }
2316    
# Line 1735  for (;;) Line 2327  for (;;)
2327            {            {
2328            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2329            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2330            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2331              RRETURN(MATCH_NOMATCH);            if (!match_ref(offset, eptr, length, md, ims))
2332                {
2333                CHECK_PARTIAL();
2334                MRRETURN(MATCH_NOMATCH);
2335                }
2336            eptr += length;            eptr += length;
2337            }            }
2338          /* Control never gets here */          /* Control never gets here */
# Line 1749  for (;;) Line 2345  for (;;)
2345          pp = eptr;          pp = eptr;
2346          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2347            {            {
2348            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2349                {
2350                CHECK_PARTIAL();
2351                break;
2352                }
2353            eptr += length;            eptr += length;
2354            }            }
2355          while (eptr >= pp)          while (eptr >= pp)
# Line 1758  for (;;) Line 2358  for (;;)
2358            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2359            eptr -= length;            eptr -= length;
2360            }            }
2361          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2362          }          }
2363        }        }
2364      /* Control never gets here */      /* Control never gets here */
2365    
   
   
2366      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2367      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,
2368      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 1819  for (;;) Line 2417  for (;;)
2417          {          {
2418          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2419            {            {
2420            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2421                {
2422                SCHECK_PARTIAL();
2423                MRRETURN(MATCH_NOMATCH);
2424                }
2425            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2426            if (c > 255)            if (c > 255)
2427              {              {
2428              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2429              }              }
2430            else            else
2431              {              {
2432              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2433              }              }
2434            }            }
2435          }          }
# Line 1837  for (;;) Line 2439  for (;;)
2439          {          {
2440          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2441            {            {
2442            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2443                {
2444                SCHECK_PARTIAL();
2445                MRRETURN(MATCH_NOMATCH);
2446                }
2447            c = *eptr++;            c = *eptr++;
2448            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2449            }            }
2450          }          }
2451    
# Line 1861  for (;;) Line 2467  for (;;)
2467              {              {
2468              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2469              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2470              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2471                if (eptr >= md->end_subject)
2472                  {
2473                  SCHECK_PARTIAL();
2474                  MRRETURN(MATCH_NOMATCH);
2475                  }
2476              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2477              if (c > 255)              if (c > 255)
2478                {                {
2479                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2480                }                }
2481              else              else
2482                {                {
2483                if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);                if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2484                }                }
2485              }              }
2486            }            }
# Line 1881  for (;;) Line 2492  for (;;)
2492              {              {
2493              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2494              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2495              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2496                if (eptr >= md->end_subject)
2497                  {
2498                  SCHECK_PARTIAL();
2499                  MRRETURN(MATCH_NOMATCH);
2500                  }
2501              c = *eptr++;              c = *eptr++;
2502              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2503              }              }
2504            }            }
2505          /* Control never gets here */          /* Control never gets here */
# Line 1902  for (;;) Line 2518  for (;;)
2518            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2519              {              {
2520              int len = 1;              int len = 1;
2521              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2522                  {
2523                  SCHECK_PARTIAL();
2524                  break;
2525                  }
2526              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2527              if (c > 255)              if (c > 255)
2528                {                {
# Line 1928  for (;;) Line 2548  for (;;)
2548            {            {
2549            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2550              {              {
2551              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2552                  {
2553                  SCHECK_PARTIAL();
2554                  break;
2555                  }
2556              c = *eptr;              c = *eptr;
2557              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2558              eptr++;              eptr++;
# Line 1941  for (;;) Line 2565  for (;;)
2565              }              }
2566            }            }
2567    
2568          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2569          }          }
2570        }        }
2571      /* Control never gets here */      /* Control never gets here */
2572    
2573    
2574      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2575      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
2576        mode, because Unicode properties are supported in non-UTF-8 mode. */
2577    
2578  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2579      case OP_XCLASS:      case OP_XCLASS:
# Line 1989  for (;;) Line 2614  for (;;)
2614    
2615        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2616          {          {
2617          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2618          GETCHARINC(c, eptr);            {
2619          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            SCHECK_PARTIAL();
2620              MRRETURN(MATCH_NOMATCH);
2621              }
2622            GETCHARINCTEST(c, eptr);
2623            if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2624          }          }
2625    
2626        /* If max == min we can continue with the main loop without the        /* If max == min we can continue with the main loop without the
# Line 2008  for (;;) Line 2637  for (;;)
2637            {            {
2638            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2639            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2640            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2641            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2642            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);              {
2643                SCHECK_PARTIAL();
2644                MRRETURN(MATCH_NOMATCH);
2645                }
2646              GETCHARINCTEST(c, eptr);
2647              if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2648            }            }
2649          /* Control never gets here */          /* Control never gets here */
2650          }          }
# Line 2023  for (;;) Line 2657  for (;;)
2657          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2658            {            {
2659            int len = 1;            int len = 1;
2660            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2661            GETCHARLEN(c, eptr, len);              {
2662                SCHECK_PARTIAL();
2663                break;
2664                }
2665              GETCHARLENTEST(c, eptr, len);
2666            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2667            eptr += len;            eptr += len;
2668            }            }
# Line 2033  for (;;) Line 2671  for (;;)
2671            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2672            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2673            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2674            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2675            }            }
2676          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2677          }          }
2678    
2679        /* Control never gets here */        /* Control never gets here */
# Line 2051  for (;;) Line 2689  for (;;)
2689        length = 1;        length = 1;
2690        ecode++;        ecode++;
2691        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2692        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2693        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);          {
2694            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2695            MRRETURN(MATCH_NOMATCH);
2696            }
2697          while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);
2698        }        }
2699      else      else
2700  #endif  #endif
2701    
2702      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2703        {        {
2704        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2705        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);          {
2706            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2707            MRRETURN(MATCH_NOMATCH);
2708            }
2709          if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);
2710        ecode += 2;        ecode += 2;
2711        }        }
2712      break;      break;
# Line 2075  for (;;) Line 2721  for (;;)
2721        ecode++;        ecode++;
2722        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2723    
2724        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2725            {
2726            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2727            MRRETURN(MATCH_NOMATCH);
2728            }
2729    
2730        /* 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
2731        can use the fast lookup table. */        can use the fast lookup table. */
2732    
2733        if (fc < 128)        if (fc < 128)
2734          {          {
2735          if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2736          }          }
2737    
2738        /* Otherwise we must pick up the subject character */        /* Otherwise we must pick up the subject character */
# Line 2099  for (;;) Line 2749  for (;;)
2749          if (fc != dc)          if (fc != dc)
2750            {            {
2751  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2752            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2753  #endif  #endif
2754              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2755            }            }
2756          }          }
2757        }        }
# Line 2110  for (;;) Line 2760  for (;;)
2760    
2761      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2762        {        {
2763        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2764        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2765            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2766            MRRETURN(MATCH_NOMATCH);
2767            }
2768          if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2769        ecode += 2;        ecode += 2;
2770        }        }
2771      break;      break;
# Line 2164  for (;;) Line 2818  for (;;)
2818      case OP_MINQUERY:      case OP_MINQUERY:
2819      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2820      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2821    
2822      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2823      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2824      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2825    
2826      /* 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. */  
2827    
2828      REPEATCHAR:      REPEATCHAR:
2829  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2179  for (;;) Line 2832  for (;;)
2832        length = 1;        length = 1;
2833        charptr = ecode;        charptr = ecode;
2834        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2835        ecode += length;        ecode += length;
2836    
2837        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2190  for (;;) Line 2842  for (;;)
2842  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2843          unsigned int othercase;          unsigned int othercase;
2844          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2845              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2846            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2847          else oclength = 0;          else oclength = 0;
2848  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2849    
2850          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2851            {            {
2852            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2853                memcmp(eptr, charptr, length) == 0) eptr += length;
2854  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2855            /* Need braces because of following else */            else if (oclength > 0 &&
2856            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                     eptr <= md->end_subject - oclength &&
2857                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2858    #endif  /* SUPPORT_UCP */
2859            else            else
2860              {              {
2861              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2862              eptr += oclength;              MRRETURN(MATCH_NOMATCH);
2863              }              }
 #else   /* without SUPPORT_UCP */  
           else { RRETURN(MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2864            }            }
2865    
2866          if (min == max) continue;          if (min == max) continue;
# Line 2219  for (;;) Line 2871  for (;;)
2871              {              {
2872              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2873              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2874              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2875              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2876                  memcmp(eptr, charptr, length) == 0) eptr += length;
2877  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2878              /* Need braces because of following else */              else if (oclength > 0 &&
2879              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                       eptr <= md->end_subject - oclength &&
2880                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2881    #endif  /* SUPPORT_UCP */
2882              else              else
2883                {                {
2884                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2885                eptr += oclength;                MRRETURN(MATCH_NOMATCH);
2886                }                }
 #else   /* without SUPPORT_UCP */  
             else { RRETURN (MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2887              }              }
2888            /* Control never gets here */            /* Control never gets here */
2889            }            }
# Line 2241  for (;;) Line 2893  for (;;)
2893            pp = eptr;            pp = eptr;
2894            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2895              {              {
2896              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2897              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2898  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2899              else if (oclength == 0) break;              else if (oclength > 0 &&
2900                         eptr <= md->end_subject - oclength &&
2901                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2902    #endif  /* SUPPORT_UCP */
2903              else              else
2904                {                {
2905                if (memcmp(eptr, occhars, oclength) != 0) break;                CHECK_PARTIAL();
2906                eptr += oclength;                break;
2907                }                }
 #else   /* without SUPPORT_UCP */  
             else break;  
 #endif  /* SUPPORT_UCP */  
2908              }              }
2909    
2910            if (possessive) continue;            if (possessive) continue;
2911    
2912            for(;;)            for(;;)
2913             {              {
2914             RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2915             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2916             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
2917  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2918             eptr--;              eptr--;
2919             BACKCHAR(eptr);              BACKCHAR(eptr);
2920  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2921             eptr -= length;              eptr -= length;
2922  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2923             }              }
2924            }            }
2925          /* Control never gets here */          /* Control never gets here */
2926          }          }
# Line 2280  for (;;) Line 2933  for (;;)
2933  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2934    
2935      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2936        {  
2937        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2938    
2939      /* 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
2940      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 2301  for (;;) Line 2952  for (;;)
2952        {        {
2953        fc = md->lcc[fc];        fc = md->lcc[fc];
2954        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2955          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2956            if (eptr >= md->end_subject)
2957              {
2958              SCHECK_PARTIAL();
2959              MRRETURN(MATCH_NOMATCH);
2960              }
2961            if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2962            }
2963        if (min == max) continue;        if (min == max) continue;
2964        if (minimize)        if (minimize)
2965          {          {
# Line 2309  for (;;) Line 2967  for (;;)
2967            {            {
2968            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2969            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2970            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2971                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2972              RRETURN(MATCH_NOMATCH);              {
2973                SCHECK_PARTIAL();
2974                MRRETURN(MATCH_NOMATCH);
2975                }
2976              if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2977            }            }
2978          /* Control never gets here */          /* Control never gets here */
2979          }          }
# Line 2320  for (;;) Line 2982  for (;;)
2982          pp = eptr;          pp = eptr;
2983          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2984            {            {
2985            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2986                {
2987                SCHECK_PARTIAL();
2988                break;
2989                }
2990              if (fc != md->lcc[*eptr]) break;
2991            eptr++;            eptr++;
2992            }            }
2993    
2994          if (possessive) continue;          if (possessive) continue;
2995    
2996          while (eptr >= pp)          while (eptr >= pp)
2997            {            {
2998            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2999            eptr--;            eptr--;
3000            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3001            }            }
3002          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3003          }          }
3004        /* Control never gets here */        /* Control never gets here */
3005        }        }
# Line 2339  for (;;) Line 3008  for (;;)
3008    
3009      else      else
3010        {        {
3011        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
3012            {
3013            if (eptr >= md->end_subject)
3014              {
3015              SCHECK_PARTIAL();
3016              MRRETURN(MATCH_NOMATCH);
3017              }
3018            if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3019            }
3020    
3021        if (min == max) continue;        if (min == max) continue;
3022    
3023        if (minimize)        if (minimize)
3024          {          {
3025          for (fi = min;; fi++)          for (fi = min;; fi++)
3026            {            {
3027            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
3028            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3029            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3030              RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3031                {
3032                SCHECK_PARTIAL();
3033                MRRETURN(MATCH_NOMATCH);
3034                }
3035              if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3036            }            }
3037          /* Control never gets here */          /* Control never gets here */
3038          }          }
# Line 2357  for (;;) Line 3041  for (;;)
3041          pp = eptr;          pp = eptr;
3042          for (i = min; i < max; i++)          for (i = min; i < max; i++)
3043            {            {
3044            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
3045                {
3046                SCHECK_PARTIAL();
3047                break;
3048                }
3049              if (fc != *eptr) break;
3050            eptr++;            eptr++;
3051            }            }
3052          if (possessive) continue;          if (possessive) continue;
3053    
3054          while (eptr >= pp)          while (eptr >= pp)
3055            {            {
3056            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
3057            eptr--;            eptr--;
3058            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3059            }            }
3060          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3061          }          }
3062        }        }
3063      /* Control never gets here */      /* Control never gets here */
# Line 2376  for (;;) Line 3066  for (;;)
3066      checking can be multibyte. */      checking can be multibyte. */
3067    
3068      case OP_NOT:      case OP_NOT:
3069      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
3070          {
3071          SCHECK_PARTIAL();
3072          MRRETURN(MATCH_NOMATCH);
3073          }
3074      ecode++;      ecode++;
3075      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3076      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2385  for (;;) Line 3079  for (;;)
3079        if (c < 256)        if (c < 256)
3080  #endif  #endif
3081        c = md->lcc[c];        c = md->lcc[c];
3082        if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3083        }        }
3084      else      else
3085        {        {
3086        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3087        }        }
3088      break;      break;
3089    
# Line 2453  for (;;) Line 3147  for (;;)
3147      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3148      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
3149    
3150      /* 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. */  
3151    
3152      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3153      fc = *ecode++;      fc = *ecode++;
3154    
3155      /* 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 2483  for (;;) Line 3174  for (;;)
3174          register unsigned int d;          register unsigned int d;
3175          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3176            {            {
3177              if (eptr >= md->end_subject)
3178                {
3179                SCHECK_PARTIAL();
3180                MRRETURN(MATCH_NOMATCH);
3181                }
3182            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3183            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
3184            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3185            }            }
3186          }          }
3187        else        else
# Line 2494  for (;;) Line 3190  for (;;)
3190        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3191          {          {
3192          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3193            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            {
3194              if (eptr >= md->end_subject)
3195                {
3196                SCHECK_PARTIAL();
3197                MRRETURN(MATCH_NOMATCH);
3198                }
3199              if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3200              }
3201          }          }
3202    
3203        if (min == max) continue;        if (min == max) continue;
# Line 2510  for (;;) Line 3213  for (;;)
3213              {              {
3214              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3215              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3216                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3217                if (eptr >= md->end_subject)
3218                  {
3219                  SCHECK_PARTIAL();
3220                  MRRETURN(MATCH_NOMATCH);
3221                  }
3222              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3223              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3224              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3225              }              }
3226            }            }
3227          else          else
# Line 2524  for (;;) Line 3232  for (;;)
3232              {              {
3233              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3234              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3235              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3236                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3237                  {
3238                  SCHECK_PARTIAL();
3239                  MRRETURN(MATCH_NOMATCH);
3240                  }
3241                if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3242              }              }
3243            }            }
3244          /* Control never gets here */          /* Control never gets here */
# Line 2545  for (;;) Line 3258  for (;;)
3258            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3259              {              {
3260              int len = 1;              int len = 1;
3261              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3262                  {
3263                  SCHECK_PARTIAL();
3264                  break;
3265                  }
3266              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3267              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3268              if (fc == d) break;              if (fc == d) break;
# Line 2566  for (;;) Line 3283  for (;;)
3283            {            {
3284            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3285              {              {
3286              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3287                  {
3288                  SCHECK_PARTIAL();
3289                  break;
3290                  }
3291                if (fc == md->lcc[*eptr]) break;
3292              eptr++;              eptr++;
3293              }              }
3294            if (possessive) continue;            if (possessive) continue;
# Line 2578  for (;;) Line 3300  for (;;)
3300              }              }
3301            }            }
3302    
3303          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3304          }          }
3305        /* Control never gets here */        /* Control never gets here */
3306        }        }
# Line 2594  for (;;) Line 3316  for (;;)
3316          register unsigned int d;          register unsigned int d;
3317          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3318            {            {
3319              if (eptr >= md->end_subject)
3320                {
3321                SCHECK_PARTIAL();
3322                MRRETURN(MATCH_NOMATCH);
3323                }
3324            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3325            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3326            }            }
3327          }          }
3328        else        else
# Line 2603  for (;;) Line 3330  for (;;)
3330        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3331          {          {
3332          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3333            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            {
3334              if (eptr >= md->end_subject)
3335                {
3336                SCHECK_PARTIAL();
3337                MRRETURN(MATCH_NOMATCH);
3338                }
3339              if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3340              }
3341          }          }
3342    
3343        if (min == max) continue;        if (min == max) continue;
# Line 2619  for (;;) Line 3353  for (;;)
3353              {              {
3354              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3355              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3356                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3357                if (eptr >= md->end_subject)
3358                  {
3359                  SCHECK_PARTIAL();
3360                  MRRETURN(MATCH_NOMATCH);
3361                  }
3362              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3363              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3364              }              }
3365            }            }
3366          else          else
# Line 2632  for (;;) Line 3371  for (;;)
3371              {              {
3372              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3373              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3374              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3375                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3376                  {
3377                  SCHECK_PARTIAL();
3378                  MRRETURN(MATCH_NOMATCH);
3379                  }
3380                if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3381              }              }
3382            }            }
3383          /* Control never gets here */          /* Control never gets here */
# Line 2653  for (;;) Line 3397  for (;;)
3397            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3398              {              {
3399              int len = 1;              int len = 1;
3400              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3401                  {
3402                  SCHECK_PARTIAL();
3403                  break;
3404                  }
3405              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3406              if (fc == d) break;              if (fc == d) break;
3407              eptr += len;              eptr += len;
# Line 2673  for (;;) Line 3421  for (;;)
3421            {            {
3422            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3423              {              {
3424              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3425                  {
3426                  SCHECK_PARTIAL();
3427                  break;
3428                  }
3429                if (fc == *eptr) break;
3430              eptr++;              eptr++;
3431              }              }
3432            if (possessive) continue;            if (possessive) continue;
# Line 2685  for (;;) Line 3438  for (;;)
3438              }              }
3439            }            }
3440    
3441          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3442          }          }
3443        }        }
3444      /* Control never gets here */      /* Control never gets here */
# Line 2767  for (;;) Line 3520  for (;;)
3520    
3521      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3522      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
3523      (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  
3524      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
3525      and single-bytes. */      and single-bytes. */
3526    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3527      if (min > 0)      if (min > 0)
3528        {        {
3529  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2782  for (;;) Line 3532  for (;;)
3532          switch(prop_type)          switch(prop_type)
3533            {            {
3534            case PT_ANY:            case PT_ANY:
3535            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
3536            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3537              {              {
3538              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3539                  {
3540                  SCHECK_PARTIAL();
3541                  MRRETURN(MATCH_NOMATCH);
3542                  }
3543              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3544              }              }
3545            break;            break;
# Line 2793  for (;;) Line 3547  for (;;)
3547            case PT_LAMP:            case PT_LAMP:
3548            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3549              {              {
3550              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3551                  {
3552                  SCHECK_PARTIAL();
3553                  MRRETURN(MATCH_NOMATCH);
3554                  }
3555              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3556              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3557              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3558                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3559                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3560                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3561              }              }
3562            break;            break;
3563    
3564            case PT_GC:            case PT_GC:
3565            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3566              {              {
3567              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3568                  {
3569                  SCHECK_PARTIAL();
3570                  MRRETURN(MATCH_NOMATCH);
3571                  }
3572              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3573              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3574              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3575                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3576              }              }
3577            break;            break;
3578    
3579            case PT_PC:            case PT_PC:
3580            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3581              {              {
3582              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3583                  {
3584                  SCHECK_PARTIAL();
3585                  MRRETURN(MATCH_NOMATCH);
3586                  }
3587              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3588              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3589              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3590                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3591              }              }
3592            break;            break;
3593    
3594            case PT_SC:            case PT_SC:
3595            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3596              {              {
3597              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3598                  {
3599                  SCHECK_PARTIAL();
3600                  MRRETURN(MATCH_NOMATCH);
3601                  }
3602              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
3603              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3604              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3605                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3606                }
3607              break;
3608    
3609              case PT_ALNUM:
3610              for (i = 1; i <= min; i++)
3611                {
3612                if (eptr >= md->end_subject)
3613                  {
3614                  SCHECK_PARTIAL();
3615                  MRRETURN(MATCH_NOMATCH);
3616                  }
3617                GETCHARINCTEST(c, eptr);
3618                prop_category = UCD_CATEGORY(c);
3619                if ((prop_category == ucp_L || prop_category == ucp_N)
3620                       == prop_fail_result)
3621                  MRRETURN(MATCH_NOMATCH);
3622                }
3623              break;
3624    
3625              case PT_SPACE:    /* Perl space */
3626              for (i = 1; i <= min; i++)
3627                {
3628                if (eptr >= md->end_subject)
3629                  {
3630                  SCHECK_PARTIAL();
3631                  MRRETURN(MATCH_NOMATCH);
3632                  }
3633                GETCHARINCTEST(c, eptr);
3634                prop_category = UCD_CATEGORY(c);
3635                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3636                     c == CHAR_FF || c == CHAR_CR)
3637                       == prop_fail_result)
3638                  MRRETURN(MATCH_NOMATCH);
3639                }
3640              break;
3641    
3642              case PT_PXSPACE:  /* POSIX space */
3643              for (i = 1; i <= min; i++)
3644                {
3645                if (eptr >= md->end_subject)
3646                  {
3647                  SCHECK_PARTIAL();
3648                  MRRETURN(MATCH_NOMATCH);
3649                  }
3650                GETCHARINCTEST(c, eptr);
3651                prop_category = UCD_CATEGORY(c);
3652                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3653                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3654                       == prop_fail_result)
3655                  MRRETURN(MATCH_NOMATCH);
3656                }
3657              break;
3658    
3659              case PT_WORD:
3660              for (i = 1; i <= min; i++)
3661                {
3662                if (eptr >= md->end_subject)
3663                  {
3664                  SCHECK_PARTIAL();
3665                  MRRETURN(MATCH_NOMATCH);
3666                  }
3667                GETCHARINCTEST(c, eptr);
3668                prop_category = UCD_CATEGORY(c);
3669                if ((prop_category == ucp_L || prop_category == ucp_N ||
3670                     c == CHAR_UNDERSCORE)
3671                       == prop_fail_result)
3672                  MRRETURN(MATCH_NOMATCH);
3673              }              }
3674            break;            break;
3675    
3676              /* This should not occur */
3677    
3678            default:            default:
3679            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
3680            }            }
# Line 2848  for (;;) Line 3687  for (;;)
3687          {          {
3688          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3689            {            {
3690              if (eptr >= md->end_subject)
3691                {
3692                SCHECK_PARTIAL();
3693                MRRETURN(MATCH_NOMATCH);
3694                }
3695            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3696            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3697            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
3698            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3699              {              {
3700              int len = 1;              int len = 1;
3701              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3702                {                else { GETCHARLEN(c, eptr, len); }
3703                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3704              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3705              eptr += len;              eptr += len;
3706              }              }
# Line 2876  for (;;) Line 3718  for (;;)
3718          case OP_ANY:          case OP_ANY:
3719          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3720            {            {
3721            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3722                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))              {
3723              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3724                MRRETURN(MATCH_NOMATCH);
3725                }
3726              if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
3727              eptr++;
3728              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3729              }
3730            break;
3731    
3732            case OP_ALLANY:
3733            for (i = 1; i <= min; i++)
3734              {
3735              if (eptr >= md->end_subject)
3736                {
3737                SCHECK_PARTIAL();
3738                MRRETURN(MATCH_NOMATCH);
3739                }
3740            eptr++;            eptr++;
3741            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3742            }            }
3743          break;          break;
3744    
3745          case OP_ANYBYTE:          case OP_ANYBYTE:
3746            if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);
3747          eptr += min;          eptr += min;
3748          break;          break;
3749    
3750          case OP_ANYNL:          case OP_ANYNL:
3751          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3752            {            {
3753            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3754                {
3755                SCHECK_PARTIAL();
3756                MRRETURN(MATCH_NOMATCH);
3757                }
3758            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3759            switch(c)            switch(c)
3760              {              {
3761              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3762              case 0x000d:              case 0x000d:
3763              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3764              break;              break;
3765    
3766              case 0x000a:              case 0x000a:
3767                break;
3768    
3769              case 0x000b:              case 0x000b:
3770              case 0x000c:              case 0x000c:
3771              case 0x0085:              case 0x0085:
3772              case 0x2028:              case 0x2028:
3773              case 0x2029:              case 0x2029:
3774                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
3775              break;              break;
3776              }              }
3777            }            }
# Line 2913  for (;;) Line 3780  for (;;)
3780          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
3781          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3782            {            {
3783            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3784                {
3785                SCHECK_PARTIAL();
3786                MRRETURN(MATCH_NOMATCH);
3787                }
3788            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3789            switch(c)            switch(c)
3790              {              {
# Line 2937  for (;;) Line 3808  for (;;)
3808              case 0x202f:    /* NARROW NO-BREAK SPACE */              case 0x202f:    /* NARROW NO-BREAK SPACE */
3809              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3810              case 0x3000:    /* IDEOGRAPHIC SPACE */              case 0x3000:    /* IDEOGRAPHIC SPACE */
3811              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3812              }              }
3813            }            }
3814          break;          break;
# Line 2945  for (;;) Line 3816  for (;;)
3816          case OP_HSPACE:          case OP_HSPACE:
3817          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3818            {            {
3819            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3820                {
3821                SCHECK_PARTIAL();
3822                MRRETURN(MATCH_NOMATCH);
3823                }
3824            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3825            switch(c)            switch(c)
3826              {              {
3827              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3828              case 0x09:      /* HT */              case 0x09:      /* HT */
3829              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
3830              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
# Line 2977  for (;;) Line 3852  for (;;)
3852          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
3853          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3854            {            {
3855            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3856                {
3857                SCHECK_PARTIAL();
3858                MRRETURN(MATCH_NOMATCH);
3859                }
3860            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3861            switch(c)            switch(c)
3862              {              {
# Line 2989  for (;;) Line 3868  for (;;)
3868              case 0x85:      /* NEL */              case 0x85:      /* NEL */
3869              case 0x2028:    /* LINE SEPARATOR */              case 0x2028:    /* LINE SEPARATOR */
3870              case 0x2029:    /* PARAGRAPH SEPARATOR */              case 0x2029:    /* PARAGRAPH SEPARATOR */
3871              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3872              }              }
3873            }            }
3874          break;          break;
# Line 2997  for (;;) Line 3876  for (;;)
3876          case OP_VSPACE:          case OP_VSPACE:
3877          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3878            {            {
3879            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3880                {
3881                SCHECK_PARTIAL();
3882                MRRETURN(MATCH_NOMATCH);
3883                }
3884            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3885            switch(c)            switch(c)
3886              {              {
3887              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3888              case 0x0a:      /* LF */              case 0x0a:      /* LF */
3889              case 0x0b:      /* VT */              case 0x0b:      /* VT */
3890              case 0x0c:      /* FF */              case 0x0c:      /* FF */
# Line 3017  for (;;) Line 3900  for (;;)
3900          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3901          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3902            {            {
3903            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3904                {
3905                SCHECK_PARTIAL();
3906                MRRETURN(MATCH_NOMATCH);
3907                }
3908            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3909            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3910              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3911            }            }
3912          break;          break;
3913    
3914          case OP_DIGIT:          case OP_DIGIT:
3915          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3916            {            {
3917            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3918               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3919              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3920                MRRETURN(MATCH_NOMATCH);
3921                }
3922              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3923                MRRETURN(MATCH_NOMATCH);
3924            /* 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 */
3925            }            }
3926          break;          break;
# Line 3037  for (;;) Line 3928  for (;;)
3928          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3929          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3930            {            {
3931            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3932               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3933              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3934            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              MRRETURN(MATCH_NOMATCH);
3935                }
3936              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3937                MRRETURN(MATCH_NOMATCH);
3938              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3939            }            }
3940          break;          break;
3941    
3942          case OP_WHITESPACE:          case OP_WHITESPACE:
3943          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3944            {            {
3945            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3946               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3947              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3948                MRRETURN(MATCH_NOMATCH);
3949                }
3950              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3951                MRRETURN(MATCH_NOMATCH);
3952            /* 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 */
3953            }            }
3954          break;          break;
# Line 3057  for (;;) Line 3956  for (;;)
3956          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3957          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3958            {            {
3959            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3960               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))              {
3961              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3962            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              MRRETURN(MATCH_NOMATCH);
3963                }
3964              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3965                MRRETURN(MATCH_NOMATCH);
3966              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3967            }            }
3968          break;          break;
3969    
3970          case OP_WORDCHAR:          case OP_WORDCHAR:
3971          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3972            {            {
3973            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3974               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3975              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3976                MRRETURN(MATCH_NOMATCH);
3977                }
3978              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3979                MRRETURN(MATCH_NOMATCH);
3980            /* 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 */
3981            }            }
3982          break;          break;
# Line 3082  for (;;) Line 3989  for (;;)
3989  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3990    
3991        /* 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
3992        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. */  
3993    
3994        switch(ctype)        switch(ctype)
3995          {          {
3996          case OP_ANY:          case OP_ANY:
3997          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3998            {            {
3999            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
4000              {              {
4001              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
4002              eptr++;              MRRETURN(MATCH_NOMATCH);
4003              }              }
4004              if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
4005              eptr++;
4006            }            }
         else eptr += min;  
4007          break;          break;
4008    
4009          case OP_ANYBYTE:          case OP_ALLANY:
4010            if (eptr > md->end_subject - min)
4011              {
4012              SCHECK_PARTIAL();
4013              MRRETURN(MATCH_NOMATCH);
4014              }
4015          eptr += min;          eptr += min;
4016          break;          break;
4017    
4018          /* Because of the CRLF case, we can't assume the minimum number of          case OP_ANYBYTE:
4019          bytes are present in this case. */          if (eptr > md->end_subject - min)
4020              {
4021              SCHECK_PARTIAL();
4022              MRRETURN(MATCH_NOMATCH);
4023              }
4024            eptr += min;
4025            break;
4026    
4027          case OP_ANYNL:          case OP_ANYNL:
4028          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4029            {            {
4030            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
4031                {
4032                SCHECK_PARTIAL();
4033                MRRETURN(MATCH_NOMATCH);
4034                }
4035            switch(*eptr++)            switch(*eptr++)
4036              {              {
4037              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4038              case 0x000d:              case 0x000d:
4039              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4040              break;              break;
4041              case 0x000a:              case 0x000a:
4042                break;
4043    
4044              case 0x000b:              case 0x000b:
4045              case 0x000c:              case 0x000c:
4046              case 0x0085:              case 0x0085:
4047                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
4048              break;              break;
4049              }              }
4050            }            }
# Line 3128  for (;;) Line 4053  for (;;)
4053          case OP_NOT_HSPACE:          case OP_NOT_HSPACE:
4054          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4055            {            {
4056            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
4057                {
4058                SCHECK_PARTIAL();
4059                MRRETURN(MATCH_NOMATCH);
4060                }
4061            switch(*eptr++)            switch(*eptr++)
4062              {              {
4063              default: break;              default: break;
4064              case 0x09:      /* HT */              case 0x09:      /* HT */
4065              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4066              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
4067              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4068              }              }
4069            }            }
4070          break;          break;
# Line 3143  for (;;) Line 4072  for (;;)
4072          case OP_HSPACE:          case OP_HSPACE:
4073          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4074            {            {
4075            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
4076                {
4077                SCHECK_PARTIAL();
4078                MRRETURN(MATCH_NOMATCH);
4079                }
4080            switch(*eptr++)            switch(*eptr++)
4081              {              {
4082              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4083              case 0x09:      /* HT */              case 0x09:      /* HT */
4084              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4085              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
# Line 3158  for (;;) Line 4091  for (;;)
4091          case OP_NOT_VSPACE:          case OP_NOT_VSPACE:
4092          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4093            {            {
4094            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
4095                {
4096                SCHECK_PARTIAL();
4097                MRRETURN(MATCH_NOMATCH);
4098                }
4099            switch(*eptr++)            switch(*eptr++)
4100              {              {
4101              default: break;              default: break;
# Line 3167  for (;;) Line 4104  for (;;)
4104              case 0x0c:      /* FF */              case 0x0c:      /* FF */
4105              case 0x0d:      /* CR */              case 0x0d:      /* CR */
4106              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4107              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4108              }              }
4109            }            }
4110          break;          break;
# Line 3175  for (;;) Line 4112  for (;;)
4112          case OP_VSPACE:          case OP_VSPACE:
4113          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4114            {            {
4115            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
4116                {
4117                SCHECK_PARTIAL();
4118                MRRETURN(MATCH_NOMATCH);
4119                }
4120            switch(*eptr++)            switch(*eptr++)
4121              {              {
4122              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4123              case 0x0a:      /* LF */              case 0x0a:      /* LF */
4124              case 0x0b:      /* VT */              case 0x0b:      /* VT */
4125              case 0x0c:      /* FF */              case 0x0c:      /* FF */
# Line 3191  for (;;) Line 4132  for (;;)
4132    
4133          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
4134          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4135            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            {
4136              if (eptr >= md->end_subject)
4137                {
4138                SCHECK_PARTIAL();
4139                MRRETURN(MATCH_NOMATCH);
4140                }
4141              if ((md->ctypes[*eptr++] & ctype_digit) != 0) MRRETURN(MATCH_NOMATCH);
4142              }
4143          break;          break;
4144    
4145          case OP_DIGIT:          case OP_DIGIT:
4146          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4147            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            {
4148              if (eptr >= md->end_subject)
4149                {
4150                SCHECK_PARTIAL();
4151                MRRETURN(MATCH_NOMATCH);
4152                }
4153              if ((md->ctypes[*eptr++] & ctype_digit) == 0) MRRETURN(MATCH_NOMATCH);
4154              }
4155          break;          break;
4156    
4157          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
4158          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4159            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            {
4160              if (eptr >= md->end_subject)
4161                {
4162                SCHECK_PARTIAL();
4163                MRRETURN(MATCH_NOMATCH);
4164                }
4165              if ((md->ctypes[*eptr++] & ctype_space) != 0) MRRETURN(MATCH_NOMATCH);
4166              }
4167          break;          break;
4168    
4169          case OP_WHITESPACE:          case OP_WHITESPACE:
4170          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4171            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            {
4172          break;            if (eptr >= md->end_subject)
4173                {
4174                SCHECK_PARTIAL();
4175                MRRETURN(MATCH_NOMATCH);
4176                }
4177              if ((md->ctypes[*eptr++] & ctype_space) == 0) MRRETURN(MATCH_NOMATCH);
4178              }
4179            break;
4180    
4181          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
4182          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4183              {
4184              if (eptr >= md->end_subject)
4185                {
4186                SCHECK_PARTIAL();
4187                MRRETURN(MATCH_NOMATCH);
4188                }
4189            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
4190              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4191              }
4192          break;          break;
4193    
4194          case OP_WORDCHAR:          case OP_WORDCHAR:
4195          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4196              {
4197              if (eptr >= md->end_subject)
4198                {
4199                SCHECK_PARTIAL();
4200                MRRETURN(MATCH_NOMATCH);
4201                }
4202            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
4203              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4204              }
4205          break;          break;
4206    
4207          default:          default:
# Line 3246  for (;;) Line 4229  for (;;)
4229              {              {
4230              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
4231              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4232              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4233              GETCHARINC(c, eptr);              if (eptr >= md->end_subject)
4234              if (prop_fail_result) RRETURN(MATCH_NOMATCH);                {
4235                  SCHECK_PARTIAL();
4236                  MRRETURN(MATCH_NOMATCH);
4237                  }
4238                GETCHARINCTEST(c, eptr);
4239                if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
4240              }              }
4241            /* Control never gets here */            /* Control never gets here */
4242    
# Line 3257  for (;;) Line 4245  for (;;)
4245              {              {
4246              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
4247              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4248              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4249              GETCHARINC(c, eptr);              if (eptr >= md->end_subject)
4250              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                {
4251                  SCHECK_PARTIAL();
4252                  MRRETURN(MATCH_NOMATCH);
4253                  }
4254                GETCHARINCTEST(c, eptr);
4255                prop_chartype = UCD_CHARTYPE(c);
4256              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4257                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
4258                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
4259                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4260              }              }
4261            /* Control never gets here */            /* Control never gets here */
4262    
# Line 3272  for (;;) Line 4265  for (;;)
4265              {              {
4266              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
4267              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4268              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4269              GETCHARINC(c, eptr);              if (eptr >= md->end_subject)
4270              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                {
4271                  SCHECK_PARTIAL();
4272                  MRRETURN(MATCH_NOMATCH);
4273                  }
4274                GETCHARINCTEST(c, eptr);
4275                prop_category = UCD_CATEGORY(c);
4276              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4277                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4278              }              }
4279            /* Control never gets here */            /* Control never gets here */
4280    
# Line 3285  for (;;) Line 4283  for (;;)
4283              {              {
4284              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
4285              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4286              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4287              GETCHARINC(c, eptr);              if (eptr >= md->end_subject)
4288              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                {
4289                  SCHECK_PARTIAL();
4290                  MRRETURN(MATCH_NOMATCH);
4291                  }
4292                GETCHARINCTEST(c, eptr);
4293                prop_chartype = UCD_CHARTYPE(c);
4294              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4295                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4296              }              }
4297            /* Control never gets here */            /* Control never gets here */
4298    
# Line 3298  for (;;) Line 4301  for (;;)
4301              {              {
4302              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
4303              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4304              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4305              GETCHARINC(c, eptr);              if (eptr >= md->end_subject)
4306              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                {
4307                  SCHECK_PARTIAL();
4308                  MRRETURN(MATCH_NOMATCH);
4309                  }
4310                GETCHARINCTEST(c, eptr);
4311                prop_script = UCD_SCRIPT(c);
4312              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
4313                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
4314                }
4315              /* Control never gets here */
4316    
4317              case PT_ALNUM:
4318              for (fi = min;; fi++)
4319                {
4320                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM59);
4321                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4322                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4323                if (eptr >= md->end_subject)
4324                  {
4325                  SCHECK_PARTIAL();
4326                  MRRETURN(MATCH_NOMATCH);
4327                  }
4328                GETCHARINCTEST(c, eptr);
4329                prop_category = UCD_CATEGORY(c);
4330                if ((prop_category == ucp_L || prop_category == ucp_N)
4331                       == prop_fail_result)
4332                  MRRETURN(MATCH_NOMATCH);
4333                }
4334              /* Control never gets here */
4335    
4336              case PT_SPACE:    /* Perl space */
4337              for (fi = min;; fi++)
4338                {
4339                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM60);
4340                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4341                if (fi >= max) MRRETURN(MATCH_NOMATCH);
4342                if (eptr >= md->end_subject)
4343                  {
4344                  SCHECK_PARTIAL();
4345                  MRRETURN(MATCH_NOMATCH);
4346                  }
4347                GETCHARINCTEST(c, eptr);
4348                prop_category = UCD_CATEGORY(c);
4349                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4350                     c == CHAR_FF || c == CHAR_CR)
4351                       == prop_fail_result)
4352                  MRRETURN(MATCH_NOMATCH);
4353                }
4354