/[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 144 by ph10, Mon Apr 2 13:32:07 2007 UTC revision 518 by ph10, Tue May 18 15:47:01 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 188  calls by keeping local variables that ne Line 230  calls by keeping local variables that ne
230  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
231  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
232  always used to.  always used to.
233    
234    The original heap-recursive code used longjmp(). However, it seems that this
235    can be very slow on some operating systems. Following a suggestion from Stan
236    Switzer, the use of longjmp() has been abolished, at the cost of having to
237    provide a unique number for each call to RMATCH. There is no way of generating
238    a sequence of numbers at compile time in C. I have given them names, to make
239    them stand out more clearly.
240    
241    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
242    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
243    tests. Furthermore, not using longjmp() means that local dynamic variables
244    don't have indeterminate values; this has meant that the frame size can be
245    reduced because the result can be "passed back" by straight setting of the
246    variable instead of being passed in the frame.
247  ****************************************************************************  ****************************************************************************
248  ***************************************************************************/  ***************************************************************************/
249    
250    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
251    below must be updated in sync.  */
252    
253    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
254           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
255           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
256           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
257           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
258           RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58 };
259    
260  /* 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
261  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
262    actually used in this definition. */
263    
264  #ifndef NO_RECURSE  #ifndef NO_RECURSE
265  #define REGISTER register  #define REGISTER register
266  #ifdef DEBUG  
267  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #ifdef PCRE_DEBUG
268    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
269    { \    { \
270    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \
272    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
273    }    }
274  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 210  versions and production versions. */ Line 277  versions and production versions. */
277    return ra; \    return ra; \
278    }    }
279  #else  #else
280  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
281    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)
282  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
283  #endif  #endif
284    
285  #else  #else
286    
287    
288  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
289  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
290  match(), which never changes. */  argument of match(), which never changes. */
291    
292  #define REGISTER  #define REGISTER
293    
294  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
295    {\    {\
296    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
297    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
298      {\    newframe->Xeptr = ra;\
299      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
300      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
301      newframe->Xoffset_top = rc;\    newframe->Xmarkptr = markptr;\
302      newframe->Xims = re;\    newframe->Xoffset_top = rc;\
303      newframe->Xeptrb = rf;\    newframe->Xims = re;\
304      newframe->Xflags = rg;\    newframe->Xeptrb = rf;\
305      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xflags = rg;\
306      newframe->Xprevframe = frame;\    newframe->Xrdepth = frame->Xrdepth + 1;\
307      frame = newframe;\    newframe->Xprevframe = frame;\
308      DPRINTF(("restarting from line %d\n", __LINE__));\    frame = newframe;\
309      goto HEAP_RECURSE;\    DPRINTF(("restarting from line %d\n", __LINE__));\
310      }\    goto HEAP_RECURSE;\
311    else\    L_##rw:\
312      {\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
313    }    }
314    
315  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 256  match(), which never changes. */ Line 319  match(), which never changes. */
319    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
320    if (frame != NULL)\    if (frame != NULL)\
321      {\      {\
322      frame->Xresult = ra;\      rrc = ra;\
323      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
324      }\      }\
325    return ra;\    return ra;\
326    }    }
# Line 271  typedef struct heapframe { Line 333  typedef struct heapframe {
333    
334    /* Function arguments that may change */    /* Function arguments that may change */
335    
336    const uschar *Xeptr;    USPTR Xeptr;
337    const uschar *Xecode;    const uschar *Xecode;
338      USPTR Xmstart;
339      USPTR Xmarkptr;
340    int Xoffset_top;    int Xoffset_top;
341    long int Xims;    long int Xims;
342    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 281  typedef struct heapframe { Line 345  typedef struct heapframe {
345    
346    /* Function local variables */    /* Function local variables */
347    
348    const uschar *Xcallpat;    USPTR Xcallpat;
349    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
350    const uschar *Xdata;    USPTR Xcharptr;
351    const uschar *Xnext;  #endif
352    const uschar *Xpp;    USPTR Xdata;
353    const uschar *Xprev;    USPTR Xnext;
354    const uschar *Xsaved_eptr;    USPTR Xpp;
355      USPTR Xprev;
356      USPTR Xsaved_eptr;
357    
358    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
359    
# Line 308  typedef struct heapframe { Line 374  typedef struct heapframe {
374    uschar Xocchars[8];    uschar Xocchars[8];
375  #endif  #endif
376    
377      int Xcodelink;
378    int Xctype;    int Xctype;
379    unsigned int Xfc;    unsigned int Xfc;
380    int Xfi;    int Xfi;
# Line 323  typedef struct heapframe { Line 390  typedef struct heapframe {
390    
391    eptrblock Xnewptrb;    eptrblock Xnewptrb;
392    
393    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
394    
395    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
396    
397  } heapframe;  } heapframe;
398    
# Line 344  typedef struct heapframe { Line 410  typedef struct heapframe {
410    
411  /* This function is called recursively in many circumstances. Whenever it  /* This function is called recursively in many circumstances. Whenever it
412  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
413  same response.  same response. */
414    
415  Performance note: It might be tempting to extract commonly used fields from the  /* These macros pack up tests that are used for partial matching, and which
416  md structure (e.g. utf8, end_subject) into individual variables to improve  appears several times in the code. We set the "hit end" flag if the pointer is
417    at the end of the subject and also past the start of the subject (i.e.
418    something has been matched). For hard partial matching, we then return
419    immediately. The second one is used when we already know we are past the end of
420    the subject. */
421    
422    #define CHECK_PARTIAL()\
423      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
424        {\
425        md->hitend = TRUE;\
426        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\
427        }
428    
429    #define SCHECK_PARTIAL()\
430      if (md->partial != 0 && eptr > mstart)\
431        {\
432        md->hitend = TRUE;\
433        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\
434        }
435    
436    
437    /* Performance note: It might be tempting to extract commonly used fields from
438    the md structure (e.g. utf8, end_subject) into individual variables to improve
439  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
440  made performance worse.  made performance worse.
441    
442  Arguments:  Arguments:
443     eptr        pointer to current character in subject     eptr        pointer to current character in subject
444     ecode       pointer to current position in compiled code     ecode       pointer to current position in compiled code
445       mstart      pointer to the current match start position (can be modified
446                     by encountering \K)
447       markptr     pointer to the most recent MARK name, or NULL
448     offset_top  current top pointer     offset_top  current top pointer
449     md          pointer to "static" info for the match     md          pointer to "static" info for the match
450     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 363  Arguments: Line 454  Arguments:
454                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
455                   match_cbegroup - this is the start of an unlimited repeat                   match_cbegroup - this is the start of an unlimited repeat
456                     group that can match an empty string                     group that can match an empty string
                  match_tail_recursed - this is a tail_recursed group  
457     rdepth      the recursion depth     rdepth      the recursion depth
458    
459  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
460                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
461                   a negative MATCH_xxx value for PRUNE, SKIP, etc
462                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
463                   (e.g. stopped by repeated call or recursion limit)                   (e.g. stopped by repeated call or recursion limit)
464  */  */
465    
466  static int  static int
467  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
468    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,
469    int flags, unsigned int rdepth)    eptrblock *eptrb, int flags, unsigned int rdepth)
470  {  {
471  /* 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,
472  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 387  register unsigned int c;   /* Character Line 478  register unsigned int c;   /* Character
478  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
479    
480  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
481    int condcode;
482    
483  /* 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
484  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 401  frame->Xprevframe = NULL;            /* Line 493  frame->Xprevframe = NULL;            /*
493    
494  frame->Xeptr = eptr;  frame->Xeptr = eptr;
495  frame->Xecode = ecode;  frame->Xecode = ecode;
496    frame->Xmstart = mstart;
497    frame->Xmarkptr = markptr;
498  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
499  frame->Xims = ims;  frame->Xims = ims;
500  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 415  HEAP_RECURSE: Line 509  HEAP_RECURSE:
509    
510  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
511  #define ecode              frame->Xecode  #define ecode              frame->Xecode
512    #define mstart             frame->Xmstart
513    #define markptr            frame->Xmarkptr
514  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
515  #define ims                frame->Xims  #define ims                frame->Xims
516  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 427  HEAP_RECURSE: Line 523  HEAP_RECURSE:
523  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
524  #endif  #endif
525  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
526    #define codelink           frame->Xcodelink
527  #define data               frame->Xdata  #define data               frame->Xdata
528  #define next               frame->Xnext  #define next               frame->Xnext
529  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 507  int oclength; Line 604  int oclength;
604  uschar occhars[8];  uschar occhars[8];
605  #endif  #endif
606    
607    int codelink;
608  int ctype;  int ctype;
609  int length;  int length;
610  int max;  int max;
# Line 540  TAIL_RECURSE: Line 638  TAIL_RECURSE:
638  /* 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
639  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
640  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()
641  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
642  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
643  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,
644  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
645    
646    #ifdef SUPPORT_UTF8
647    utf8 = md->utf8;       /* Local copy of the flag */
648    #else
649    utf8 = FALSE;
650    #endif
651    
652  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
653  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
654    
# Line 553  if (rdepth >= md->match_limit_recursion) Line 657  if (rdepth >= md->match_limit_recursion)
657    
658  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
659    
 #ifdef SUPPORT_UTF8  
 utf8 = md->utf8;       /* Local copy of the flag */  
 #else  
 utf8 = FALSE;  
 #endif  
   
660  /* At the start of a group with an unlimited repeat that may match an empty  /* At the start of a group with an unlimited repeat that may match an empty
661  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
662  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
663  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.
664  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
665  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
666  already used. */  block that is used is on the stack, so a new one may be required for each
667    match(). */
668    
669  if ((flags & match_cbegroup) != 0)  if ((flags & match_cbegroup) != 0)
670    {    {
671    eptrblock *p;    newptrb.epb_saved_eptr = eptr;
672    if ((flags & match_tail_recursed) != 0)    newptrb.epb_prev = eptrb;
673      {    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;  
674    }    }
675    
676  /* Now start processing the opcodes. */  /* Now start processing the opcodes. */
# Line 588  for (;;) Line 680  for (;;)
680    minimize = possessive = FALSE;    minimize = possessive = FALSE;
681    op = *ecode;    op = *ecode;
682    
   /* 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 > md->start_match)  
     md->hitend = TRUE;  
   
683    switch(op)    switch(op)
684      {      {
685        case OP_MARK:
686        markptr = ecode + 2;
687        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
688          ims, eptrb, flags, RM55);
689    
690        /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
691        argument, and we must check whether that argument matches this MARK's
692        argument. It is passed back in md->start_match_ptr (an overloading of that
693        variable). If it does match, we reset that variable to the current subject
694        position and return MATCH_SKIP. Otherwise, pass back the return code
695        unaltered. */
696    
697        if (rrc == MATCH_SKIP_ARG &&
698            strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
699          {
700          md->start_match_ptr = eptr;
701          RRETURN(MATCH_SKIP);
702          }
703    
704        if (md->mark == NULL) md->mark = markptr;
705        RRETURN(rrc);
706    
707        case OP_FAIL:
708        MRRETURN(MATCH_NOMATCH);
709    
710        case OP_COMMIT:
711        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
712          ims, eptrb, flags, RM52);
713        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
714        MRRETURN(MATCH_COMMIT);
715    
716        case OP_PRUNE:
717        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
718          ims, eptrb, flags, RM51);
719        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
720        MRRETURN(MATCH_PRUNE);
721    
722        case OP_PRUNE_ARG:
723        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
724          ims, eptrb, flags, RM56);
725        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
726        md->mark = ecode + 2;
727        RRETURN(MATCH_PRUNE);
728    
729        case OP_SKIP:
730        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
731          ims, eptrb, flags, RM53);
732        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
733        md->start_match_ptr = eptr;   /* Pass back current position */
734        MRRETURN(MATCH_SKIP);
735    
736        case OP_SKIP_ARG:
737        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
738          ims, eptrb, flags, RM57);
739        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
740    
741        /* Pass back the current skip name by overloading md->start_match_ptr and
742        returning the special MATCH_SKIP_ARG return code. This will either be
743        caught by a matching MARK, or get to the top, where it is treated the same
744        as PRUNE. */
745    
746        md->start_match_ptr = ecode + 2;
747        RRETURN(MATCH_SKIP_ARG);
748    
749        case OP_THEN:
750        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
751          ims, eptrb, flags, RM54);
752        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
753        MRRETURN(MATCH_THEN);
754    
755        case OP_THEN_ARG:
756        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
757          ims, eptrb, flags, RM58);
758        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
759        md->mark = ecode + 2;
760        RRETURN(MATCH_THEN);
761    
762      /* 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
763      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.
764      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 617  for (;;) Line 778  for (;;)
778      number = GET2(ecode, 1+LINK_SIZE);      number = GET2(ecode, 1+LINK_SIZE);
779      offset = number << 1;      offset = number << 1;
780    
781  #ifdef DEBUG  #ifdef PCRE_DEBUG
782      printf("start bracket %d\n", number);      printf("start bracket %d\n", number);
783      printf("subject=");      printf("subject=");
784      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
# Line 637  for (;;) Line 798  for (;;)
798        flags = (op == OP_SCBRA)? match_cbegroup : 0;        flags = (op == OP_SCBRA)? match_cbegroup : 0;
799        do        do
800          {          {
801          RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
802            ims, eptrb, flags);            ims, eptrb, flags, RM1);
803          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
804          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
805          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
806          }          }
# Line 651  for (;;) Line 812  for (;;)
812        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
813        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
814    
815          if (rrc != MATCH_THEN) md->mark = markptr;
816        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
817        }        }
818    
819      /* Insufficient room for saving captured contents. Treat as a non-capturing      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
820      bracket. */      as a non-capturing bracket. */
821    
822        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
823        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
824    
825      DPRINTF(("insufficient capture room: treat as non-capturing\n"));      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
826    
827        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
828        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
829    
830      /* 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
831      final alternative within the brackets, we would return the result of a      final alternative within the brackets, we would return the result of a
832      recursive call to match() whatever happened. We can reduce stack usage by      recursive call to match() whatever happened. We can reduce stack usage by
833      turning this into a tail recursion. */      turning this into a tail recursion, except in the case when match_cbegroup
834        is set.*/
835    
836      case OP_BRA:      case OP_BRA:
837      case OP_SBRA:      case OP_SBRA:
# Line 670  for (;;) Line 839  for (;;)
839      flags = (op >= OP_SBRA)? match_cbegroup : 0;      flags = (op >= OP_SBRA)? match_cbegroup : 0;
840      for (;;)      for (;;)
841        {        {
842        if (ecode[GET(ecode, 1)] != OP_ALT)        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
843          {          {
844          ecode += _pcre_OP_lengths[*ecode];          if (flags == 0)    /* Not a possibly empty group */
845          flags |= match_tail_recursed;            {
846          DPRINTF(("bracket 0 tail recursion\n"));            ecode += _pcre_OP_lengths[*ecode];
847          goto TAIL_RECURSE;            DPRINTF(("bracket 0 tail recursion\n"));
848              goto TAIL_RECURSE;
849              }
850    
851            /* Possibly empty group; can't use tail recursion. */
852    
853            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
854              eptrb, flags, RM48);
855            if (rrc == MATCH_NOMATCH) md->mark = markptr;
856            RRETURN(rrc);
857          }          }
858    
859        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
860        otherwise return. */        otherwise return. */
861    
862        RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
863          eptrb, flags);          eptrb, flags, RM2);
864        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
865        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
866        }        }
867      /* Control never reaches here. */      /* Control never reaches here. */
# Line 696  for (;;) Line 874  for (;;)
874    
875      case OP_COND:      case OP_COND:
876      case OP_SCOND:      case OP_SCOND:
877      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
878    
879        /* Because of the way auto-callout works during compile, a callout item is
880        inserted between OP_COND and an assertion condition. */
881    
882        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
883        {        {
884        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        if (pcre_callout != NULL)
885        condition = md->recursive != NULL &&          {
886          (offset == RREF_ANY || offset == md->recursive->group_num);          pcre_callout_block cb;
887        ecode += condition? 3 : GET(ecode, 1);          cb.version          = 1;   /* Version 1 of the callout block */
888            cb.callout_number   = ecode[LINK_SIZE+2];
889            cb.offset_vector    = md->offset_vector;
890            cb.subject          = (PCRE_SPTR)md->start_subject;
891            cb.subject_length   = md->end_subject - md->start_subject;
892            cb.start_match      = mstart - md->start_subject;
893            cb.current_position = eptr - md->start_subject;
894            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
895            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
896            cb.capture_top      = offset_top/2;
897            cb.capture_last     = md->capture_last;
898            cb.callout_data     = md->callout_data;
899            if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
900            if (rrc < 0) RRETURN(rrc);
901            }
902          ecode += _pcre_OP_lengths[OP_CALLOUT];
903          }
904    
905        condcode = ecode[LINK_SIZE+1];
906    
907        /* Now see what the actual condition is */
908    
909        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
910          {
911          if (md->recursive == NULL)                /* Not recursing => FALSE */
912            {
913            condition = FALSE;
914            ecode += GET(ecode, 1);
915            }
916          else
917            {
918            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
919            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
920    
921            /* If the test is for recursion into a specific subpattern, and it is
922            false, but the test was set up by name, scan the table to see if the
923            name refers to any other numbers, and test them. The condition is true
924            if any one is set. */
925    
926            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
927              {
928              uschar *slotA = md->name_table;
929              for (i = 0; i < md->name_count; i++)
930                {
931                if (GET2(slotA, 0) == recno) break;
932                slotA += md->name_entry_size;
933                }
934    
935              /* Found a name for the number - there can be only one; duplicate
936              names for different numbers are allowed, but not vice versa. First
937              scan down for duplicates. */
938    
939              if (i < md->name_count)
940                {
941                uschar *slotB = slotA;
942                while (slotB > md->name_table)
943                  {
944                  slotB -= md->name_entry_size;
945                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
946                    {
947                    condition = GET2(slotB, 0) == md->recursive->group_num;
948                    if (condition) break;
949                    }
950                  else break;
951                  }
952    
953                /* Scan up for duplicates */
954    
955                if (!condition)
956                  {
957                  slotB = slotA;
958                  for (i++; i < md->name_count; i++)
959                    {
960                    slotB += md->name_entry_size;
961                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
962                      {
963                      condition = GET2(slotB, 0) == md->recursive->group_num;
964                      if (condition) break;
965                      }
966                    else break;
967                    }
968                  }
969                }
970              }
971    
972            /* Chose branch according to the condition */
973    
974            ecode += condition? 3 : GET(ecode, 1);
975            }
976        }        }
977    
978      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
979        {        {
980        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
981        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
982    
983          /* If the numbered capture is unset, but the reference was by name,
984          scan the table to see if the name refers to any other numbers, and test
985          them. The condition is true if any one is set. This is tediously similar
986          to the code above, but not close enough to try to amalgamate. */
987    
988          if (!condition && condcode == OP_NCREF)
989            {
990            int refno = offset >> 1;
991            uschar *slotA = md->name_table;
992    
993            for (i = 0; i < md->name_count; i++)
994              {
995              if (GET2(slotA, 0) == refno) break;
996              slotA += md->name_entry_size;
997              }
998    
999            /* Found a name for the number - there can be only one; duplicate names
1000            for different numbers are allowed, but not vice versa. First scan down
1001            for duplicates. */
1002    
1003            if (i < md->name_count)
1004              {
1005              uschar *slotB = slotA;
1006              while (slotB > md->name_table)
1007                {
1008                slotB -= md->name_entry_size;
1009                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1010                  {
1011                  offset = GET2(slotB, 0) << 1;
1012                  condition = offset < offset_top &&
1013                    md->offset_vector[offset] >= 0;
1014                  if (condition) break;
1015                  }
1016                else break;
1017                }
1018    
1019              /* Scan up for duplicates */
1020    
1021              if (!condition)
1022                {
1023                slotB = slotA;
1024                for (i++; i < md->name_count; i++)
1025                  {
1026                  slotB += md->name_entry_size;
1027                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1028                    {
1029                    offset = GET2(slotB, 0) << 1;
1030                    condition = offset < offset_top &&
1031                      md->offset_vector[offset] >= 0;
1032                    if (condition) break;
1033                    }
1034                  else break;
1035                  }
1036                }
1037              }
1038            }
1039    
1040          /* Chose branch according to the condition */
1041    
1042        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
1043        }        }
1044    
1045      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
1046        {        {
1047        condition = FALSE;        condition = FALSE;
1048        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 723  for (;;) Line 1054  for (;;)
1054    
1055      else      else
1056        {        {
1057        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
1058            match_condassert);            match_condassert, RM3);
1059        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
1060          {          {
1061          condition = TRUE;          condition = TRUE;
1062          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1063          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1064          }          }
1065        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1066          {          {
1067          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1068          }          }
1069        else        else
1070          {          {
1071          condition = FALSE;          condition = FALSE;
1072          ecode += GET(ecode, 1);          ecode += codelink;
1073          }          }
1074        }        }
1075    
1076      /* 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,
1077      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
1078      alternative doesn't exist, we can just plough on. */      match_cbegroup is required for an unlimited repeat of a possibly empty
1079        group. If the second alternative doesn't exist, we can just plough on. */
1080    
1081      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
1082        {        {
1083        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1084        flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);        if (op == OP_SCOND)        /* Possibly empty group */
1085        goto TAIL_RECURSE;          {
1086            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1087            RRETURN(rrc);
1088            }
1089          else                       /* Group must match something */
1090            {
1091            flags = 0;
1092            goto TAIL_RECURSE;
1093            }
1094        }        }
1095      else      else                         /* Condition false & no alternative */
1096        {        {
1097        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1098        }        }
1099      break;      break;
1100    
1101    
1102      /* 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,
1103      restore the offsets appropriately and continue from after the call. */      to close any currently open capturing brackets. */
1104    
1105        case OP_CLOSE:
1106        number = GET2(ecode, 1);
1107        offset = number << 1;
1108    
1109    #ifdef PCRE_DEBUG
1110          printf("end bracket %d at *ACCEPT", number);
1111          printf("\n");
1112    #endif
1113    
1114        md->capture_last = number;
1115        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1116          {
1117          md->offset_vector[offset] =
1118            md->offset_vector[md->offset_end - number];
1119          md->offset_vector[offset+1] = eptr - md->start_subject;
1120          if (offset_top <= offset) offset_top = offset + 2;
1121          }
1122        ecode += 3;
1123        break;
1124    
1125    
1126        /* End of the pattern, either real or forced. If we are in a top-level
1127        recursion, we should restore the offsets appropriately and continue from
1128        after the call. */
1129    
1130        case OP_ACCEPT:
1131      case OP_END:      case OP_END:
1132      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
1133        {        {
# Line 770  for (;;) Line 1136  for (;;)
1136        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1137        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1138          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1139        md->start_match = rec->save_start;        offset_top = rec->save_offset_top;
1140        ims = original_ims;        ims = original_ims;
1141        ecode = rec->after_call;        ecode = rec->after_call;
1142        break;        break;
1143        }        }
1144    
1145      /* 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
1146      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
1147        the subject. In both cases, backtracking will then try other alternatives,
1148        if any. */
1149    
1150        if (eptr == mstart &&
1151            (md->notempty ||
1152              (md->notempty_atstart &&
1153                mstart == md->start_subject + md->start_offset)))
1154          MRRETURN(MATCH_NOMATCH);
1155    
1156        /* Otherwise, we have a match. */
1157    
1158        md->end_match_ptr = eptr;           /* Record where we ended */
1159        md->end_offset_top = offset_top;    /* and how many extracts were taken */
1160        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1161    
1162      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      /* For some reason, the macros don't work properly if an expression is
1163      md->end_match_ptr = eptr;          /* Record where we ended */      given as the argument to MRRETURN when the heap is in use. */
1164      md->end_offset_top = offset_top;   /* and how many extracts were taken */  
1165      RRETURN(MATCH_MATCH);      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1166        MRRETURN(rrc);
1167    
1168      /* Change option settings */      /* Change option settings */
1169    
# Line 802  for (;;) Line 1183  for (;;)
1183      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1184      do      do
1185        {        {
1186        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1187        if (rrc == MATCH_MATCH) break;          RM4);
1188        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1189            {
1190            mstart = md->start_match_ptr;   /* In case \K reset it */
1191            break;
1192            }
1193          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1194        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1195        }        }
1196      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1197      if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1198    
1199      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1200    
# Line 822  for (;;) Line 1208  for (;;)
1208      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1209      continue;      continue;
1210    
1211      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1212        PRUNE, or COMMIT means we must assume failure without checking subsequent
1213        branches. */
1214    
1215      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1216      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1217      do      do
1218        {        {
1219        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1220        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);          RM5);
1221        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
1222          if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1223            {
1224            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1225            break;
1226            }
1227          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1228        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1229        }        }
1230      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 853  for (;;) Line 1247  for (;;)
1247        while (i-- > 0)        while (i-- > 0)
1248          {          {
1249          eptr--;          eptr--;
1250          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1251          BACKCHAR(eptr)          BACKCHAR(eptr);
1252          }          }
1253        }        }
1254      else      else
# Line 864  for (;;) Line 1258  for (;;)
1258    
1259        {        {
1260        eptr -= GET(ecode, 1);        eptr -= GET(ecode, 1);
1261        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1262        }        }
1263    
1264      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1265    
1266        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1267      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1268      break;      break;
1269    
# Line 885  for (;;) Line 1280  for (;;)
1280        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1281        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1282        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1283        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1284        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1285        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1286        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1287        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1288        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1289        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1290        if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
1291        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1292        }        }
1293      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 947  for (;;) Line 1342  for (;;)
1342    
1343        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1344              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1345        new_recursive.save_start = md->start_match;        new_recursive.save_offset_top = offset_top;
       md->start_match = eptr;  
1346    
1347        /* 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
1348        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 957  for (;;) Line 1351  for (;;)
1351        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1352        do        do
1353          {          {
1354          RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1355            md, ims, eptrb, flags);            md, ims, eptrb, flags, RM6);
1356          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1357            {            {
1358            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1359            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1360            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1361              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1362            RRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1363            }            }
1364          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1365            {            {
1366            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1367              if (new_recursive.offset_save != stacksave)
1368                (pcre_free)(new_recursive.offset_save);
1369            RRETURN(rrc);            RRETURN(rrc);
1370            }            }
1371    
# Line 984  for (;;) Line 1380  for (;;)
1380        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1381        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1382          (pcre_free)(new_recursive.offset_save);          (pcre_free)(new_recursive.offset_save);
1383        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1384        }        }
1385      /* Control never reaches here */      /* Control never reaches here */
1386    
# Line 993  for (;;) Line 1389  for (;;)
1389      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1390      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
1391      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
1392      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1393        the start-of-match value in case it was changed by \K. */
1394    
1395      case OP_ONCE:      case OP_ONCE:
1396      prev = ecode;      prev = ecode;
# Line 1001  for (;;) Line 1398  for (;;)
1398    
1399      do      do
1400        {        {
1401        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1402          eptrb, 0);        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1403        if (rrc == MATCH_MATCH) break;          {
1404        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          mstart = md->start_match_ptr;
1405            break;
1406            }
1407          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1408        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1409        }        }
1410      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1047  for (;;) Line 1447  for (;;)
1447    
1448      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1449        {        {
1450        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1451        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1452        ecode = prev;        ecode = prev;
1453        flags = match_tail_recursed;        flags = 0;
1454        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1455        }        }
1456      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1457        {        {
1458        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1459        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1460        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1461        flags = match_tail_recursed;        flags = 0;
1462        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1463        }        }
1464      /* Control never gets here */      /* Control never gets here */
# Line 1070  for (;;) Line 1470  for (;;)
1470      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1471      break;      break;
1472    
1473      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1474      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
1475      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
1476      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
1477      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1478    
1479      case OP_BRAZERO:      case OP_BRAZERO:
1480        {        {
1481        next = ecode+1;        next = ecode+1;
1482        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1483        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1484        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1485        ecode = next + 1 + LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
# Line 1090  for (;;) Line 1490  for (;;)
1490        {        {
1491        next = ecode+1;        next = ecode+1;
1492        do next += GET(next, 1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1493        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
1494        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1495        ecode++;        ecode++;
1496        }        }
1497      break;      break;
1498    
1499        case OP_SKIPZERO:
1500          {
1501          next = ecode+1;
1502          do next += GET(next,1); while (*next == OP_ALT);
1503          ecode = next + 1 + LINK_SIZE;
1504          }
1505        break;
1506    
1507      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1508    
1509      case OP_KET:      case OP_KET:
# Line 1114  for (;;) Line 1522  for (;;)
1522        }        }
1523      else saved_eptr = NULL;      else saved_eptr = NULL;
1524    
1525      /* 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
1526      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
1527      assertions. Do this also for the "once" (atomic) groups. */      use by positive assertions. We also need to record the match start in case
1528        it was changed by \K. */
1529    
1530      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1531          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1124  for (;;) Line 1533  for (;;)
1533        {        {
1534        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1535        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1536        RRETURN(MATCH_MATCH);        md->start_match_ptr = mstart;
1537          MRRETURN(MATCH_MATCH);
1538        }        }
1539    
1540      /* 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 1138  for (;;) Line 1548  for (;;)
1548        number = GET2(prev, 1+LINK_SIZE);        number = GET2(prev, 1+LINK_SIZE);
1549        offset = number << 1;        offset = number << 1;
1550    
1551  #ifdef DEBUG  #ifdef PCRE_DEBUG
1552        printf("end bracket %d", number);        printf("end bracket %d", number);
1553        printf("\n");        printf("\n");
1554  #endif  #endif
# Line 1160  for (;;) Line 1570  for (;;)
1570          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1571          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1572          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
         md->start_match = rec->save_start;  
1573          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1574            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1575            offset_top = rec->save_offset_top;
1576          ecode = rec->after_call;          ecode = rec->after_call;
1577          ims = original_ims;          ims = original_ims;
1578          break;          break;
# Line 1189  for (;;) Line 1599  for (;;)
1599    
1600      /* 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
1601      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
1602      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1603        unlimited repeat of a group that can match an empty string. */
1604    
1605      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1606    
1607      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1608        {        {
1609        RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1610        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1611          if (flags != 0)    /* Could match an empty string */
1612            {
1613            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1614            RRETURN(rrc);
1615            }
1616        ecode = prev;        ecode = prev;
       flags |= match_tail_recursed;  
1617        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1618        }        }
1619      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1620        {        {
1621        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1622        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1623        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1624        flags = match_tail_recursed;        flags = 0;
1625        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1626        }        }
1627      /* Control never gets here */      /* Control never gets here */
# Line 1214  for (;;) Line 1629  for (;;)
1629      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1630    
1631      case OP_CIRC:      case OP_CIRC:
1632      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1633      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1634        {        {
1635        if (eptr != md->start_subject &&        if (eptr != md->start_subject &&
1636            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1637          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
1638        ecode++;        ecode++;
1639        break;        break;
1640        }        }
# Line 1228  for (;;) Line 1643  for (;;)
1643      /* Start of subject assertion */      /* Start of subject assertion */
1644    
1645      case OP_SOD:      case OP_SOD:
1646      if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1647      ecode++;      ecode++;
1648      break;      break;
1649    
1650      /* Start of match assertion */      /* Start of match assertion */
1651    
1652      case OP_SOM:      case OP_SOM:
1653      if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);
1654        ecode++;
1655        break;
1656    
1657        /* Reset the start of match point */
1658    
1659        case OP_SET_SOM:
1660        mstart = eptr;
1661      ecode++;      ecode++;
1662      break;      break;
1663    
# Line 1246  for (;;) Line 1668  for (;;)
1668      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1669        {        {
1670        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1671          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
1672        else        else
1673          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) MRRETURN(MATCH_NOMATCH); }
1674        ecode++;        ecode++;
1675        break;        break;
1676        }        }
1677      else      else
1678        {        {
1679        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1680        if (!md->endonly)        if (!md->endonly)
1681          {          {
1682          if (eptr != md->end_subject &&          if (eptr != md->end_subject &&
1683              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1684            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
1685          ecode++;          ecode++;
1686          break;          break;
1687          }          }
# Line 1269  for (;;) Line 1691  for (;;)
1691      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1692    
1693      case OP_EOD:      case OP_EOD:
1694      if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1695      ecode++;      ecode++;
1696      break;      break;
1697    
# Line 1278  for (;;) Line 1700  for (;;)
1700      case OP_EODN:      case OP_EODN:
1701      if (eptr != md->end_subject &&      if (eptr != md->end_subject &&
1702          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1703        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1704      ecode++;      ecode++;
1705      break;      break;
1706    
# Line 1290  for (;;) Line 1712  for (;;)
1712    
1713        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1714        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
1715        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1716          partial matching. */
1717    
1718  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1719        if (utf8)        if (utf8)
1720          {          {
1721            /* Get status of previous character */
1722    
1723          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1724            {            {
1725            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1726            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1727              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1728            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1729    #ifdef SUPPORT_UCP
1730              if (md->use_ucp)
1731                {
1732                if (c == '_') prev_is_word = TRUE; else
1733                  {
1734                  int cat = UCD_CATEGORY(c);
1735                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1736                  }
1737                }
1738              else
1739    #endif
1740            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1741            }            }
1742          if (eptr >= md->end_subject) cur_is_word = FALSE; else  
1743            /* Get status of next character */
1744    
1745            if (eptr >= md->end_subject)
1746              {
1747              SCHECK_PARTIAL();
1748              cur_is_word = FALSE;
1749              }
1750            else
1751            {            {
1752            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1753    #ifdef SUPPORT_UCP
1754              if (md->use_ucp)
1755                {
1756                if (c == '_') cur_is_word = TRUE; else
1757                  {
1758                  int cat = UCD_CATEGORY(c);
1759                  cur_is_word = (cat == ucp_L || cat == ucp_N);
1760                  }
1761                }
1762              else
1763    #endif
1764            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1765            }            }
1766          }          }
1767        else        else
1768  #endif  #endif
1769    
1770        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
1771          consistency with the behaviour of \w we do use it in this case. */
1772    
1773          {          {
1774          prev_is_word = (eptr != md->start_subject) &&          /* Get status of previous character */
1775            ((md->ctypes[eptr[-1]] & ctype_word) != 0);  
1776          cur_is_word = (eptr < md->end_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1777            ((md->ctypes[*eptr] & ctype_word) != 0);            {
1778              if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1779    #ifdef SUPPORT_UCP
1780              if (md->use_ucp)
1781                {
1782                c = eptr[-1];
1783                if (c == '_') prev_is_word = TRUE; else
1784                  {
1785                  int cat = UCD_CATEGORY(c);
1786                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1787                  }
1788                }
1789              else
1790    #endif
1791              prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1792              }
1793    
1794            /* Get status of next character */
1795    
1796            if (eptr >= md->end_subject)
1797              {
1798              SCHECK_PARTIAL();
1799              cur_is_word = FALSE;
1800              }
1801            else
1802    #ifdef SUPPORT_UCP
1803            if (md->use_ucp)
1804              {
1805              c = *eptr;
1806              if (c == '_') cur_is_word = TRUE; else
1807                {
1808                int cat = UCD_CATEGORY(c);
1809                cur_is_word = (cat == ucp_L || cat == ucp_N);
1810                }
1811              }
1812            else
1813    #endif
1814            cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1815          }          }
1816    
1817        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
1818    
1819        if ((*ecode++ == OP_WORD_BOUNDARY)?        if ((*ecode++ == OP_WORD_BOUNDARY)?
1820             cur_is_word == prev_is_word : cur_is_word != prev_is_word)             cur_is_word == prev_is_word : cur_is_word != prev_is_word)
1821          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
1822        }        }
1823      break;      break;
1824    
1825      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1826    
1827      case OP_ANY:      case OP_ANY:
1828      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
1829        /* Fall through */
1830    
1831        case OP_ALLANY:
1832        if (eptr++ >= md->end_subject)
1833        {        {
1834        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);        SCHECK_PARTIAL();
1835          MRRETURN(MATCH_NOMATCH);
1836        }        }
1837      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++;  
1838      ecode++;      ecode++;
1839      break;      break;
1840    
# Line 1345  for (;;) Line 1842  for (;;)
1842      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1843    
1844      case OP_ANYBYTE:      case OP_ANYBYTE:
1845      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1846          {
1847          SCHECK_PARTIAL();
1848          MRRETURN(MATCH_NOMATCH);
1849          }
1850      ecode++;      ecode++;
1851      break;      break;
1852    
1853      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1854      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1855          {
1856          SCHECK_PARTIAL();
1857          MRRETURN(MATCH_NOMATCH);
1858          }
1859      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1860      if (      if (
1861  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1358  for (;;) Line 1863  for (;;)
1863  #endif  #endif
1864         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
1865         )         )
1866        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1867      ecode++;      ecode++;
1868      break;      break;
1869    
1870      case OP_DIGIT:      case OP_DIGIT:
1871      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1872          {
1873          SCHECK_PARTIAL();
1874          MRRETURN(MATCH_NOMATCH);
1875          }
1876      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1877      if (      if (
1878  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1371  for (;;) Line 1880  for (;;)
1880  #endif  #endif
1881         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
1882         )         )
1883        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1884      ecode++;      ecode++;
1885      break;      break;
1886    
1887      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1888      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1889          {
1890          SCHECK_PARTIAL();
1891          MRRETURN(MATCH_NOMATCH);
1892          }
1893      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1894      if (      if (
1895  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1384  for (;;) Line 1897  for (;;)
1897  #endif  #endif
1898         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
1899         )         )
1900        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1901      ecode++;      ecode++;
1902      break;      break;
1903    
1904      case OP_WHITESPACE:      case OP_WHITESPACE:
1905      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1906          {
1907          SCHECK_PARTIAL();
1908          MRRETURN(MATCH_NOMATCH);
1909          }
1910      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1911      if (      if (
1912  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1397  for (;;) Line 1914  for (;;)
1914  #endif  #endif
1915         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
1916         )         )
1917        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1918      ecode++;      ecode++;
1919      break;      break;
1920    
1921      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1922      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1923          {
1924          SCHECK_PARTIAL();
1925          MRRETURN(MATCH_NOMATCH);
1926          }
1927      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1928      if (      if (
1929  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1410  for (;;) Line 1931  for (;;)
1931  #endif  #endif
1932         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
1933         )         )
1934        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1935      ecode++;      ecode++;
1936      break;      break;
1937    
1938      case OP_WORDCHAR:      case OP_WORDCHAR:
1939      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1940          {
1941          SCHECK_PARTIAL();
1942          MRRETURN(MATCH_NOMATCH);
1943          }
1944      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1945      if (      if (
1946  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1423  for (;;) Line 1948  for (;;)
1948  #endif  #endif
1949         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
1950         )         )
1951        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1952      ecode++;      ecode++;
1953      break;      break;
1954    
1955      case OP_ANYNL:      case OP_ANYNL:
1956      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1957          {
1958          SCHECK_PARTIAL();
1959          MRRETURN(MATCH_NOMATCH);
1960          }
1961      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1962      switch(c)      switch(c)
1963        {        {
1964        default: RRETURN(MATCH_NOMATCH);        default: MRRETURN(MATCH_NOMATCH);
1965        case 0x000d:        case 0x000d:
1966        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1967        break;        break;
1968    
1969        case 0x000a:        case 0x000a:
1970          break;
1971    
1972        case 0x000b:        case 0x000b:
1973        case 0x000c:        case 0x000c:
1974        case 0x0085:        case 0x0085:
1975        case 0x2028:        case 0x2028:
1976        case 0x2029:        case 0x2029:
1977          if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
1978          break;
1979          }
1980        ecode++;
1981        break;
1982    
1983        case OP_NOT_HSPACE:
1984        if (eptr >= md->end_subject)
1985          {
1986          SCHECK_PARTIAL();
1987          MRRETURN(MATCH_NOMATCH);
1988          }
1989        GETCHARINCTEST(c, eptr);
1990        switch(c)
1991          {
1992          default: break;
1993          case 0x09:      /* HT */
1994          case 0x20:      /* SPACE */
1995          case 0xa0:      /* NBSP */
1996          case 0x1680:    /* OGHAM SPACE MARK */
1997          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1998          case 0x2000:    /* EN QUAD */
1999          case 0x2001:    /* EM QUAD */
2000          case 0x2002:    /* EN SPACE */
2001          case 0x2003:    /* EM SPACE */
2002          case 0x2004:    /* THREE-PER-EM SPACE */
2003          case 0x2005:    /* FOUR-PER-EM SPACE */
2004          case 0x2006:    /* SIX-PER-EM SPACE */
2005          case 0x2007:    /* FIGURE SPACE */
2006          case 0x2008:    /* PUNCTUATION SPACE */
2007          case 0x2009:    /* THIN SPACE */
2008          case 0x200A:    /* HAIR SPACE */
2009          case 0x202f:    /* NARROW NO-BREAK SPACE */
2010          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2011          case 0x3000:    /* IDEOGRAPHIC SPACE */
2012          MRRETURN(MATCH_NOMATCH);
2013          }
2014        ecode++;
2015        break;
2016    
2017        case OP_HSPACE:
2018        if (eptr >= md->end_subject)
2019          {
2020          SCHECK_PARTIAL();
2021          MRRETURN(MATCH_NOMATCH);
2022          }
2023        GETCHARINCTEST(c, eptr);
2024        switch(c)
2025          {
2026          default: MRRETURN(MATCH_NOMATCH);
2027          case 0x09:      /* HT */
2028          case 0x20:      /* SPACE */
2029          case 0xa0:      /* NBSP */
2030          case 0x1680:    /* OGHAM SPACE MARK */
2031          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2032          case 0x2000:    /* EN QUAD */
2033          case 0x2001:    /* EM QUAD */
2034          case 0x2002:    /* EN SPACE */
2035          case 0x2003:    /* EM SPACE */
2036          case 0x2004:    /* THREE-PER-EM SPACE */
2037          case 0x2005:    /* FOUR-PER-EM SPACE */
2038          case 0x2006:    /* SIX-PER-EM SPACE */
2039          case 0x2007:    /* FIGURE SPACE */
2040          case 0x2008:    /* PUNCTUATION SPACE */
2041          case 0x2009:    /* THIN SPACE */
2042          case 0x200A:    /* HAIR SPACE */
2043          case 0x202f:    /* NARROW NO-BREAK SPACE */
2044          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2045          case 0x3000:    /* IDEOGRAPHIC SPACE */
2046          break;
2047          }
2048        ecode++;
2049        break;
2050    
2051        case OP_NOT_VSPACE:
2052        if (eptr >= md->end_subject)
2053          {
2054          SCHECK_PARTIAL();
2055          MRRETURN(MATCH_NOMATCH);
2056          }
2057        GETCHARINCTEST(c, eptr);
2058        switch(c)
2059          {
2060          default: break;
2061          case 0x0a:      /* LF */
2062          case 0x0b:      /* VT */
2063          case 0x0c:      /* FF */
2064          case 0x0d:      /* CR */
2065          case 0x85:      /* NEL */
2066          case 0x2028:    /* LINE SEPARATOR */
2067          case 0x2029:    /* PARAGRAPH SEPARATOR */
2068          MRRETURN(MATCH_NOMATCH);
2069          }
2070        ecode++;
2071        break;
2072    
2073        case OP_VSPACE:
2074        if (eptr >= md->end_subject)
2075          {
2076          SCHECK_PARTIAL();
2077          MRRETURN(MATCH_NOMATCH);
2078          }
2079        GETCHARINCTEST(c, eptr);
2080        switch(c)
2081          {
2082          default: MRRETURN(MATCH_NOMATCH);
2083          case 0x0a:      /* LF */
2084          case 0x0b:      /* VT */
2085          case 0x0c:      /* FF */
2086          case 0x0d:      /* CR */
2087          case 0x85:      /* NEL */
2088          case 0x2028:    /* LINE SEPARATOR */
2089          case 0x2029:    /* PARAGRAPH SEPARATOR */
2090        break;        break;
2091        }        }
2092      ecode++;      ecode++;
# Line 1453  for (;;) Line 2098  for (;;)
2098    
2099      case OP_PROP:      case OP_PROP:
2100      case OP_NOTPROP:      case OP_NOTPROP:
2101      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2102          {
2103          SCHECK_PARTIAL();
2104          MRRETURN(MATCH_NOMATCH);
2105          }
2106      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2107        {        {
2108        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
2109    
2110        switch(ecode[1])        switch(ecode[1])
2111          {          {
2112          case PT_ANY:          case PT_ANY:
2113          if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);          if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);
2114          break;          break;
2115    
2116          case PT_LAMP:          case PT_LAMP:
2117          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
2118               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2119               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2120            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2121           break;          break;
2122    
2123          case PT_GC:          case PT_GC:
2124          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
2125            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2126          break;          break;
2127    
2128          case PT_PC:          case PT_PC:
2129          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2130            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2131          break;          break;
2132    
2133          case PT_SC:          case PT_SC:
2134          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2135            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2136          break;          break;
2137    
2138            /* These are specials */
2139    
2140            case PT_ALNUM:
2141            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2142                 _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2143              MRRETURN(MATCH_NOMATCH);
2144            break;
2145    
2146            case PT_SPACE:    /* Perl space */
2147            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2148                 c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2149                   == (op == OP_NOTPROP))
2150              MRRETURN(MATCH_NOMATCH);
2151            break;
2152    
2153            case PT_PXSPACE:  /* POSIX space */
2154            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2155                 c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2156                 c == CHAR_FF || c == CHAR_CR)
2157                   == (op == OP_NOTPROP))
2158              MRRETURN(MATCH_NOMATCH);
2159            break;
2160    
2161            case PT_WORD:
2162            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2163                 _pcre_ucp_gentype[prop->chartype] == ucp_N ||
2164                 c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2165              MRRETURN(MATCH_NOMATCH);
2166            break;
2167    
2168            /* This should never occur */
2169    
2170          default:          default:
2171          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
# Line 1499  for (;;) Line 2179  for (;;)
2179      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2180    
2181      case OP_EXTUNI:      case OP_EXTUNI:
2182      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2183          {
2184          SCHECK_PARTIAL();
2185          MRRETURN(MATCH_NOMATCH);
2186          }
2187      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2188        {        {
2189        int chartype, script;        int category = UCD_CATEGORY(c);
2190        int category = _pcre_ucp_findprop(c, &chartype, &script);        if (category == ucp_M) MRRETURN(MATCH_NOMATCH);
       if (category == ucp_M) RRETURN(MATCH_NOMATCH);  
2191        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2192          {          {
2193          int len = 1;          int len = 1;
# Line 1512  for (;;) Line 2195  for (;;)
2195            {            {
2196            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
2197            }            }
2198          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
2199          if (category != ucp_M) break;          if (category != ucp_M) break;
2200          eptr += len;          eptr += len;
2201          }          }
# Line 1533  for (;;) Line 2216  for (;;)
2216      case OP_REF:      case OP_REF:
2217        {        {
2218        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2219        ecode += 3;                                 /* Advance past item */        ecode += 3;
2220    
2221          /* If the reference is unset, there are two possibilities:
2222    
2223        /* 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
2224        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
2225        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
2226        minima. */        quantifiers with zero minima.
2227    
2228        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        (b) If the JavaScript compatibility flag is set, set the length to zero
2229          md->end_subject - eptr + 1 :        so that the back reference matches an empty string.
2230          md->offset_vector[offset+1] - md->offset_vector[offset];  
2231          Otherwise, set the length to the length of what was matched by the
2232          referenced subpattern. */
2233    
2234          if (offset >= offset_top || md->offset_vector[offset] < 0)
2235            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
2236          else
2237            length = md->offset_vector[offset+1] - md->offset_vector[offset];
2238    
2239        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
2240    
# Line 1571  for (;;) Line 2263  for (;;)
2263          break;          break;
2264    
2265          default:               /* No repeat follows */          default:               /* No repeat follows */
2266          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2267              {
2268              CHECK_PARTIAL();
2269              MRRETURN(MATCH_NOMATCH);
2270              }
2271          eptr += length;          eptr += length;
2272          continue;              /* With the main loop */          continue;              /* With the main loop */
2273          }          }
# Line 1587  for (;;) Line 2283  for (;;)
2283    
2284        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2285          {          {
2286          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2287              {
2288              CHECK_PARTIAL();
2289              MRRETURN(MATCH_NOMATCH);
2290              }
2291          eptr += length;          eptr += length;
2292          }          }
2293    
# Line 1602  for (;;) Line 2302  for (;;)
2302          {          {
2303          for (fi = min;; fi++)          for (fi = min;; fi++)
2304            {            {
2305            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2306            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2307            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2308              RRETURN(MATCH_NOMATCH);            if (!match_ref(offset, eptr, length, md, ims))
2309                {
2310                CHECK_PARTIAL();
2311                MRRETURN(MATCH_NOMATCH);
2312                }
2313            eptr += length;            eptr += length;
2314            }            }
2315          /* Control never gets here */          /* Control never gets here */
# Line 1618  for (;;) Line 2322  for (;;)
2322          pp = eptr;          pp = eptr;
2323          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2324            {            {
2325            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2326                {
2327                CHECK_PARTIAL();
2328                break;
2329                }
2330            eptr += length;            eptr += length;
2331            }            }
2332          while (eptr >= pp)          while (eptr >= pp)
2333            {            {
2334            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2335            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2336            eptr -= length;            eptr -= length;
2337            }            }
2338          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2339          }          }
2340        }        }
2341      /* Control never gets here */      /* Control never gets here */
2342    
   
   
2343      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2344      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,
2345      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 1688  for (;;) Line 2394  for (;;)
2394          {          {
2395          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2396            {            {
2397            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2398                {
2399                SCHECK_PARTIAL();
2400                MRRETURN(MATCH_NOMATCH);
2401                }
2402            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2403            if (c > 255)            if (c > 255)
2404              {              {
2405              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2406              }              }
2407            else            else
2408              {              {
2409              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2410              }              }
2411            }            }
2412          }          }
# Line 1706  for (;;) Line 2416  for (;;)
2416          {          {
2417          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2418            {            {
2419            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2420                {
2421                SCHECK_PARTIAL();
2422                MRRETURN(MATCH_NOMATCH);
2423                }
2424            c = *eptr++;            c = *eptr++;
2425            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2426            }            }
2427          }          }
2428    
# Line 1728  for (;;) Line 2442  for (;;)
2442            {            {
2443            for (fi = min;; fi++)            for (fi = min;; fi++)
2444              {              {
2445              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2446              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2447              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2448                if (eptr >= md->end_subject)
2449                  {
2450                  SCHECK_PARTIAL();
2451                  MRRETURN(MATCH_NOMATCH);
2452                  }
2453              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2454              if (c > 255)              if (c > 255)
2455                {                {
2456                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2457                }                }
2458              else              else
2459                {                {
2460                if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);                if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2461                }                }
2462              }              }
2463            }            }
# Line 1748  for (;;) Line 2467  for (;;)
2467            {            {
2468            for (fi = min;; fi++)            for (fi = min;; fi++)
2469              {              {
2470              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2471              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2472              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2473                if (eptr >= md->end_subject)
2474                  {
2475                  SCHECK_PARTIAL();
2476                  MRRETURN(MATCH_NOMATCH);
2477                  }
2478              c = *eptr++;              c = *eptr++;
2479              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2480              }              }
2481            }            }
2482          /* Control never gets here */          /* Control never gets here */
# Line 1771  for (;;) Line 2495  for (;;)
2495            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2496              {              {
2497              int len = 1;              int len = 1;
2498              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2499                  {
2500                  SCHECK_PARTIAL();
2501                  break;
2502                  }
2503              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2504              if (c > 255)              if (c > 255)
2505                {                {
# Line 1785  for (;;) Line 2513  for (;;)
2513              }              }
2514            for (;;)            for (;;)
2515              {              {
2516              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2517              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2518              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2519              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1797  for (;;) Line 2525  for (;;)
2525            {            {
2526            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2527              {              {
2528              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2529                  {
2530                  SCHECK_PARTIAL();
2531                  break;
2532                  }
2533              c = *eptr;              c = *eptr;
2534              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2535              eptr++;              eptr++;
2536              }              }
2537            while (eptr >= pp)            while (eptr >= pp)
2538              {              {
2539              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2540              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2541              eptr--;              eptr--;
2542              }              }
2543            }            }
2544    
2545          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2546          }          }
2547        }        }
2548      /* Control never gets here */      /* Control never gets here */
2549    
2550    
2551      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2552      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
2553        mode, because Unicode properties are supported in non-UTF-8 mode. */
2554    
2555  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2556      case OP_XCLASS:      case OP_XCLASS:
# Line 1858  for (;;) Line 2591  for (;;)
2591    
2592        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2593          {          {
2594          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2595          GETCHARINC(c, eptr);            {
2596          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            SCHECK_PARTIAL();
2597              MRRETURN(MATCH_NOMATCH);
2598              }
2599            GETCHARINCTEST(c, eptr);
2600            if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2601          }          }
2602    
2603        /* 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 1875  for (;;) Line 2612  for (;;)
2612          {          {
2613          for (fi = min;; fi++)          for (fi = min;; fi++)
2614            {            {
2615            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2616            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2617            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2618            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2619            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);              {
2620                SCHECK_PARTIAL();
2621                MRRETURN(MATCH_NOMATCH);
2622                }
2623              GETCHARINCTEST(c, eptr);
2624              if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2625            }            }
2626          /* Control never gets here */          /* Control never gets here */
2627          }          }
# Line 1892  for (;;) Line 2634  for (;;)
2634          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2635            {            {
2636            int len = 1;            int len = 1;
2637            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2638            GETCHARLEN(c, eptr, len);              {
2639                SCHECK_PARTIAL();
2640                break;
2641                }
2642              GETCHARLENTEST(c, eptr, len);
2643            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2644            eptr += len;            eptr += len;
2645            }            }
2646          for(;;)          for(;;)
2647            {            {
2648            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2649            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2650            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2651            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2652            }            }
2653          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2654          }          }
2655    
2656        /* Control never gets here */        /* Control never gets here */
# Line 1920  for (;;) Line 2666  for (;;)
2666        length = 1;        length = 1;
2667        ecode++;        ecode++;
2668        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2669        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2670        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);          {
2671            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2672            MRRETURN(MATCH_NOMATCH);
2673            }
2674          while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);
2675        }        }
2676      else      else
2677  #endif  #endif
2678    
2679      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2680        {        {
2681        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2682        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);          {
2683            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2684            MRRETURN(MATCH_NOMATCH);
2685            }
2686          if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);
2687        ecode += 2;        ecode += 2;
2688        }        }
2689      break;      break;
# Line 1944  for (;;) Line 2698  for (;;)
2698        ecode++;        ecode++;
2699        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2700    
2701        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2702            {
2703            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2704            MRRETURN(MATCH_NOMATCH);
2705            }
2706    
2707        /* 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
2708        can use the fast lookup table. */        can use the fast lookup table. */
2709    
2710        if (fc < 128)        if (fc < 128)
2711          {          {
2712          if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2713          }          }
2714    
2715        /* Otherwise we must pick up the subject character */        /* Otherwise we must pick up the subject character */
# Line 1968  for (;;) Line 2726  for (;;)
2726          if (fc != dc)          if (fc != dc)
2727            {            {
2728  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2729            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2730  #endif  #endif
2731              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2732            }            }
2733          }          }
2734        }        }
# Line 1979  for (;;) Line 2737  for (;;)
2737    
2738      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2739        {        {
2740        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2741        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2742            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2743            MRRETURN(MATCH_NOMATCH);
2744            }
2745          if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2746        ecode += 2;        ecode += 2;
2747        }        }
2748      break;      break;
# Line 2033  for (;;) Line 2795  for (;;)
2795      case OP_MINQUERY:      case OP_MINQUERY:
2796      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2797      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2798    
2799      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2800      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2801      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2802    
2803      /* 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. */  
2804    
2805      REPEATCHAR:      REPEATCHAR:
2806  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2048  for (;;) Line 2809  for (;;)
2809        length = 1;        length = 1;
2810        charptr = ecode;        charptr = ecode;
2811        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2812        ecode += length;        ecode += length;
2813    
2814        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2059  for (;;) Line 2819  for (;;)
2819  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2820          unsigned int othercase;          unsigned int othercase;
2821          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2822              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2823            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2824          else oclength = 0;          else oclength = 0;
2825  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2826    
2827          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2828            {            {
2829            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2830                memcmp(eptr, charptr, length) == 0) eptr += length;
2831  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2832            /* Need braces because of following else */            else if (oclength > 0 &&
2833            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                     eptr <= md->end_subject - oclength &&
2834                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2835    #endif  /* SUPPORT_UCP */
2836            else            else
2837              {              {
2838              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2839              eptr += oclength;              MRRETURN(MATCH_NOMATCH);
2840              }              }
 #else   /* without SUPPORT_UCP */  
           else { RRETURN(MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2841            }            }
2842    
2843          if (min == max) continue;          if (min == max) continue;
# Line 2086  for (;;) Line 2846  for (;;)
2846            {            {
2847            for (fi = min;; fi++)            for (fi = min;; fi++)
2848              {              {
2849              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2850              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2851              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
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            /* Control never gets here */            /* Control never gets here */
2866            }            }
# Line 2110  for (;;) Line 2870  for (;;)
2870            pp = eptr;            pp = eptr;
2871            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2872              {              {
2873              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2874              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2875  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2876              else if (oclength == 0) break;              else if (oclength > 0 &&
2877                         eptr <= md->end_subject - oclength &&
2878                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2879    #endif  /* SUPPORT_UCP */
2880              else              else
2881                {                {
2882                if (memcmp(eptr, occhars, oclength) != 0) break;                CHECK_PARTIAL();
2883                eptr += oclength;                break;
2884                }                }
 #else   /* without SUPPORT_UCP */  
             else break;  
 #endif  /* SUPPORT_UCP */  
2885              }              }
2886    
2887            if (possessive) continue;            if (possessive) continue;
2888    
2889            for(;;)            for(;;)
2890             {              {
2891             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2892             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2893             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
2894  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2895             eptr--;              eptr--;
2896             BACKCHAR(eptr);              BACKCHAR(eptr);
2897  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2898             eptr -= length;              eptr -= length;
2899  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2900             }              }
2901            }            }
2902          /* Control never gets here */          /* Control never gets here */
2903          }          }
# Line 2149  for (;;) Line 2910  for (;;)
2910  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2911    
2912      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2913        {  
2914        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2915    
2916      /* 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
2917      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 2170  for (;;) Line 2929  for (;;)
2929        {        {
2930        fc = md->lcc[fc];        fc = md->lcc[fc];
2931        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2932          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2933            if (eptr >= md->end_subject)
2934              {
2935              SCHECK_PARTIAL();
2936              MRRETURN(MATCH_NOMATCH);
2937              }
2938            if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2939            }
2940        if (min == max) continue;        if (min == max) continue;
2941        if (minimize)        if (minimize)
2942          {          {
2943          for (fi = min;; fi++)          for (fi = min;; fi++)
2944            {            {
2945            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2946            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2947            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2948                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2949              RRETURN(MATCH_NOMATCH);              {
2950                SCHECK_PARTIAL();
2951                MRRETURN(MATCH_NOMATCH);
2952                }
2953              if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2954            }            }
2955          /* Control never gets here */          /* Control never gets here */
2956          }          }
# Line 2189  for (;;) Line 2959  for (;;)
2959          pp = eptr;          pp = eptr;
2960          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2961            {            {
2962            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2963                {
2964                SCHECK_PARTIAL();
2965                break;
2966                }
2967              if (fc != md->lcc[*eptr]) break;
2968            eptr++;            eptr++;
2969            }            }
2970    
2971          if (possessive) continue;          if (possessive) continue;
2972    
2973          while (eptr >= pp)          while (eptr >= pp)
2974            {            {
2975            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2976            eptr--;            eptr--;
2977            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2978            }            }
2979          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2980          }          }
2981        /* Control never gets here */        /* Control never gets here */
2982        }        }
# Line 2208  for (;;) Line 2985  for (;;)
2985    
2986      else      else
2987        {        {
2988        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2989            {
2990            if (eptr >= md->end_subject)
2991              {
2992              SCHECK_PARTIAL();
2993              MRRETURN(MATCH_NOMATCH);
2994              }
2995            if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
2996            }
2997    
2998        if (min == max) continue;        if (min == max) continue;
2999    
3000        if (minimize)        if (minimize)
3001          {          {
3002          for (fi = min;; fi++)          for (fi = min;; fi++)
3003            {            {
3004            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
3005            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3006            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3007              RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3008                {
3009                SCHECK_PARTIAL();
3010                MRRETURN(MATCH_NOMATCH);
3011                }
3012              if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3013            }            }
3014          /* Control never gets here */          /* Control never gets here */
3015          }          }
# Line 2226  for (;;) Line 3018  for (;;)
3018          pp = eptr;          pp = eptr;
3019          for (i = min; i < max; i++)          for (i = min; i < max; i++)
3020            {            {
3021            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
3022                {
3023                SCHECK_PARTIAL();
3024                break;
3025                }
3026              if (fc != *eptr) break;
3027            eptr++;            eptr++;
3028            }            }
3029          if (possessive) continue;          if (possessive) continue;
3030    
3031          while (eptr >= pp)          while (eptr >= pp)
3032            {            {
3033            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
3034            eptr--;            eptr--;
3035            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3036            }            }
3037          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3038          }          }
3039        }        }
3040      /* Control never gets here */      /* Control never gets here */
# Line 2245  for (;;) Line 3043  for (;;)
3043      checking can be multibyte. */      checking can be multibyte. */
3044    
3045      case OP_NOT:      case OP_NOT:
3046      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
3047          {
3048          SCHECK_PARTIAL();
3049          MRRETURN(MATCH_NOMATCH);
3050          }
3051      ecode++;      ecode++;
3052      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3053      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2254  for (;;) Line 3056  for (;;)
3056        if (c < 256)        if (c < 256)
3057  #endif  #endif
3058        c = md->lcc[c];        c = md->lcc[c];
3059        if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3060        }        }
3061      else      else
3062        {        {
3063        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3064        }        }
3065      break;      break;
3066    
# Line 2322  for (;;) Line 3124  for (;;)
3124      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3125      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
3126    
3127      /* 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. */  
3128    
3129      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3130      fc = *ecode++;      fc = *ecode++;
3131    
3132      /* 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 2352  for (;;) Line 3151  for (;;)
3151          register unsigned int d;          register unsigned int d;
3152          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3153            {            {
3154              if (eptr >= md->end_subject)
3155                {
3156                SCHECK_PARTIAL();
3157                MRRETURN(MATCH_NOMATCH);
3158                }
3159            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3160            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
3161            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3162            }            }
3163          }          }
3164        else        else
# Line 2363  for (;;) Line 3167  for (;;)
3167        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3168          {          {
3169          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3170            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            {
3171              if (eptr >= md->end_subject)
3172                {
3173                SCHECK_PARTIAL();
3174                MRRETURN(MATCH_NOMATCH);
3175                }
3176              if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3177              }
3178          }          }
3179    
3180        if (min == max) continue;        if (min == max) continue;
# Line 2377  for (;;) Line 3188  for (;;)
3188            register unsigned int d;            register unsigned int d;
3189            for (fi = min;; fi++)            for (fi = min;; fi++)
3190              {              {
3191              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3192              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3193                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3194                if (eptr >= md->end_subject)
3195                  {
3196                  SCHECK_PARTIAL();
3197                  MRRETURN(MATCH_NOMATCH);
3198                  }
3199              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3200              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3201              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3202              }              }
3203            }            }
3204          else          else
# Line 2391  for (;;) Line 3207  for (;;)
3207            {            {
3208            for (fi = min;; fi++)            for (fi = min;; fi++)
3209              {              {
3210              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3211              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3212              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3213                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3214                  {
3215                  SCHECK_PARTIAL();
3216                  MRRETURN(MATCH_NOMATCH);
3217                  }
3218                if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3219              }              }
3220            }            }
3221          /* Control never gets here */          /* Control never gets here */
# Line 2414  for (;;) Line 3235  for (;;)
3235            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3236              {              {
3237              int len = 1;              int len = 1;
3238              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3239                  {
3240                  SCHECK_PARTIAL();
3241                  break;
3242                  }
3243              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3244              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3245              if (fc == d) break;              if (fc == d) break;
# Line 2423  for (;;) Line 3248  for (;;)
3248          if (possessive) continue;          if (possessive) continue;
3249          for(;;)          for(;;)
3250              {              {
3251              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
3252              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3253              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3254              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2435  for (;;) Line 3260  for (;;)
3260            {            {
3261            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3262              {              {
3263              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3264                  {
3265                  SCHECK_PARTIAL();
3266                  break;
3267                  }
3268                if (fc == md->lcc[*eptr]) break;
3269              eptr++;              eptr++;
3270              }              }
3271            if (possessive) continue;            if (possessive) continue;
3272            while (eptr >= pp)            while (eptr >= pp)
3273              {              {
3274              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
3275              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3276              eptr--;              eptr--;
3277              }              }
3278            }            }
3279    
3280          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3281          }          }
3282        /* Control never gets here */        /* Control never gets here */
3283        }        }
# Line 2463  for (;;) Line 3293  for (;;)
3293          register unsigned int d;          register unsigned int d;
3294          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3295            {            {
3296              if (eptr >= md->end_subject)
3297                {
3298                SCHECK_PARTIAL();
3299                MRRETURN(MATCH_NOMATCH);
3300                }
3301            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3302            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3303            }            }
3304          }          }
3305        else        else
# Line 2472  for (;;) Line 3307  for (;;)
3307        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3308          {          {
3309          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3310            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            {
3311              if (eptr >= md->end_subject)
3312                {
3313                SCHECK_PARTIAL();
3314                MRRETURN(MATCH_NOMATCH);
3315                }
3316              if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3317              }
3318          }          }
3319    
3320        if (min == max) continue;        if (min == max) continue;
# Line 2486  for (;;) Line 3328  for (;;)
3328            register unsigned int d;            register unsigned int d;
3329            for (fi = min;; fi++)            for (fi = min;; fi++)
3330              {              {
3331              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3332              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3333                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3334                if (eptr >= md->end_subject)
3335                  {
3336                  SCHECK_PARTIAL();
3337                  MRRETURN(MATCH_NOMATCH);
3338                  }
3339              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3340              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3341              }              }
3342            }            }
3343          else          else
# Line 2499  for (;;) Line 3346  for (;;)
3346            {            {
3347            for (fi = min;; fi++)            for (fi = min;; fi++)
3348              {              {
3349              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3350              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3351              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3352                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3353                  {
3354                  SCHECK_PARTIAL();
3355                  MRRETURN(MATCH_NOMATCH);
3356                  }
3357                if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3358              }              }
3359            }            }
3360          /* Control never gets here */          /* Control never gets here */
# Line 2522  for (;;) Line 3374  for (;;)
3374            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3375              {              {
3376              int len = 1;              int len = 1;
3377              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3378                  {
3379                  SCHECK_PARTIAL();
3380                  break;
3381                  }
3382              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3383              if (fc == d) break;              if (fc == d) break;
3384              eptr += len;              eptr += len;
# Line 2530  for (;;) Line 3386  for (;;)
3386            if (possessive) continue;            if (possessive) continue;
3387            for(;;)            for(;;)
3388              {              {
3389              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3390              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3391              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3392              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2542  for (;;) Line 3398  for (;;)
3398            {            {
3399            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3400              {              {
3401              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3402                  {
3403                  SCHECK_PARTIAL();
3404                  break;
3405                  }
3406                if (fc == *eptr) break;
3407              eptr++;              eptr++;
3408              }              }
3409            if (possessive) continue;            if (possessive) continue;
3410            while (eptr >= pp)            while (eptr >= pp)
3411              {              {
3412              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3413              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3414              eptr--;              eptr--;
3415              }              }
3416            }            }
3417    
3418          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3419          }          }
3420        }        }
3421      /* Control never gets here */      /* Control never gets here */
# Line 2636  for (;;) Line 3497  for (;;)
3497    
3498      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3499      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
3500      (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  
3501      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
3502      and single-bytes. */      and single-bytes. */
3503    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3504      if (min > 0)      if (min > 0)
3505        {        {
3506  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2651  for (;;) Line 3509  for (;;)
3509          switch(prop_type)          switch(prop_type)
3510            {            {
3511            case PT_ANY:            case PT_ANY:
3512            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
3513            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3514              {              {
3515              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3516              GETCHARINC(c, eptr);                {
3517                  SCHECK_PARTIAL();
3518                  MRRETURN(MATCH_NOMATCH);
3519                  }
3520                GETCHARINCTEST(c, eptr);
3521              }              }
3522            break;            break;
3523    
3524            case PT_LAMP:            case PT_LAMP:
3525            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3526              {              {
3527              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3528              GETCHARINC(c, eptr);                {
3529              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3530                  MRRETURN(MATCH_NOMATCH);
3531                  }
3532                GETCHARINCTEST(c, eptr);
3533                prop_chartype = UCD_CHARTYPE(c);
3534              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3535                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3536                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3537                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3538              }              }
3539            break;            break;
3540    
3541            case PT_GC:            case PT_GC:
3542            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3543              {              {
3544              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3545              GETCHARINC(c, eptr);                {
3546              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3547                  MRRETURN(MATCH_NOMATCH);
3548                  }
3549                GETCHARINCTEST(c, eptr);
3550                prop_category = UCD_CATEGORY(c);
3551              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3552                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3553              }              }
3554            break;            break;
3555    
3556            case PT_PC:            case PT_PC:
3557            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3558              {              {
3559              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3560              GETCHARINC(c, eptr);                {
3561              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3562                  MRRETURN(MATCH_NOMATCH);
3563                  }
3564                GETCHARINCTEST(c, eptr);
3565                prop_chartype = UCD_CHARTYPE(c);
3566              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3567                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3568              }              }
3569            break;            break;
3570    
3571            case PT_SC:            case PT_SC:
3572            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3573              {              {
3574              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3575              GETCHARINC(c, eptr);                {
3576              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3577                  MRRETURN(MATCH_NOMATCH);
3578                  }
3579                GETCHARINCTEST(c, eptr);
3580                prop_script = UCD_SCRIPT(c);
3581              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3582                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3583                }
3584              break;
3585    
3586              case PT_ALNUM:
3587              for (i = 1; i <= min; i++)
3588                {
3589                if (eptr >= md->end_subject)
3590                  {
3591                  SCHECK_PARTIAL();
3592                  MRRETURN(MATCH_NOMATCH);
3593                  }
3594                GETCHARINCTEST(c, eptr);
3595                prop_category = UCD_CATEGORY(c);
3596                if ((prop_category == ucp_L || prop_category == ucp_N)
3597                       == prop_fail_result)
3598                  MRRETURN(MATCH_NOMATCH);
3599                }
3600              break;
3601    
3602              case PT_SPACE:    /* Perl space */
3603              for (i = 1; i <= min; i++)
3604                {
3605                if (eptr >= md->end_subject)
3606                  {
3607                  SCHECK_PARTIAL();
3608                  MRRETURN(MATCH_NOMATCH);
3609                  }
3610                GETCHARINCTEST(c, eptr);
3611                prop_category = UCD_CATEGORY(c);
3612                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3613                     c == CHAR_FF || c == CHAR_CR)
3614                       == prop_fail_result)
3615                  MRRETURN(MATCH_NOMATCH);
3616                }
3617              break;
3618    
3619              case PT_PXSPACE:  /* POSIX space */
3620              for (i = 1; i <= min; i++)
3621                {
3622                if (eptr >= md->end_subject)
3623                  {
3624                  SCHECK_PARTIAL();
3625                  MRRETURN(MATCH_NOMATCH);
3626                  }
3627                GETCHARINCTEST(c, eptr);
3628                prop_category = UCD_CATEGORY(c);
3629                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3630                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3631                       == prop_fail_result)
3632                  MRRETURN(MATCH_NOMATCH);
3633                }
3634              break;
3635    
3636              case PT_WORD:
3637              for (i = 1; i <= min; i++)
3638                {
3639                if (eptr >= md->end_subject)
3640                  {
3641                  SCHECK_PARTIAL();
3642                  MRRETURN(MATCH_NOMATCH);
3643                  }
3644                GETCHARINCTEST(c, eptr);
3645                prop_category = UCD_CATEGORY(c);
3646                if ((prop_category == ucp_L || prop_category == ucp_N ||
3647                     c == CHAR_UNDERSCORE)
3648                       == prop_fail_result)
3649                  MRRETURN(MATCH_NOMATCH);
3650              }              }
3651            break;            break;
3652    
3653              /* This should not occur */
3654    
3655            default:            default:
3656            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
# Line 2717  for (;;) Line 3664  for (;;)
3664          {          {
3665          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3666            {            {
3667              if (eptr >= md->end_subject)
3668                {
3669                SCHECK_PARTIAL();
3670                MRRETURN(MATCH_NOMATCH);
3671                }
3672            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3673            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3674            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
3675            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3676              {              {
3677              int len = 1;              int len = 1;
3678              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3679                {                else { GETCHARLEN(c, eptr, len); }
3680                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3681              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3682              eptr += len;              eptr += len;
3683              }              }
# Line 2745  for (;;) Line 3695  for (;;)
3695          case OP_ANY:          case OP_ANY:
3696          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3697            {            {
3698            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3699                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))              {
3700              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3701                MRRETURN(MATCH_NOMATCH);
3702                }
3703              if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
3704              eptr++;
3705              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3706              }
3707            break;
3708    
3709            case OP_ALLANY:
3710            for (i = 1; i <= min; i++)
3711              {
3712              if (eptr >= md->end_subject)
3713                {
3714                SCHECK_PARTIAL();
3715                MRRETURN(MATCH_NOMATCH);
3716                }
3717            eptr++;            eptr++;
3718            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3719            }            }
3720          break;          break;
3721    
3722          case OP_ANYBYTE:          case OP_ANYBYTE:
3723            if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);
3724          eptr += min;          eptr += min;
3725          break;          break;
3726    
3727          case OP_ANYNL:          case OP_ANYNL:
3728          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3729            {            {
3730            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3731                {
3732                SCHECK_PARTIAL();
3733                MRRETURN(MATCH_NOMATCH);
3734                }
3735            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3736            switch(c)            switch(c)
3737              {              {
3738              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
3739              case 0x000d:              case 0x000d:
3740              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3741              break;              break;
3742    
3743              case 0x000a:              case 0x000a:
3744                break;
3745    
3746              case 0x000b:              case 0x000b:
3747              case 0x000c:              case 0x000c:
3748              case 0x0085:              case 0x0085:
3749              case 0x2028:              case 0x2028:
3750              case 0x2029:              case 0x2029:
3751                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
3752                break;
3753                }
3754              }
3755            break;
3756    
3757            case OP_NOT_HSPACE:
3758            for (i = 1; i <= min; i++)
3759              {
3760              if (eptr >= md->end_subject)
3761                {
3762                SCHECK_PARTIAL();
3763                MRRETURN(MATCH_NOMATCH);
3764                }
3765              GETCHARINC(c, eptr);
3766              switch(c)
3767                {
3768                default: break;
3769                case 0x09:      /* HT */
3770                case 0x20:      /* SPACE */
3771                case 0xa0:      /* NBSP */
3772                case 0x1680:    /* OGHAM SPACE MARK */
3773                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3774                case 0x2000:    /* EN QUAD */
3775                case 0x2001:    /* EM QUAD */
3776                case 0x2002:    /* EN SPACE */
3777                case 0x2003:    /* EM SPACE */
3778                case 0x2004:    /* THREE-PER-EM SPACE */
3779                case 0x2005:    /* FOUR-PER-EM SPACE */
3780                case 0x2006:    /* SIX-PER-EM SPACE */
3781                case 0x2007:    /* FIGURE SPACE */
3782                case 0x2008:    /* PUNCTUATION SPACE */
3783                case 0x2009:    /* THIN SPACE */
3784                case 0x200A:    /* HAIR SPACE */
3785                case 0x202f:    /* NARROW NO-BREAK SPACE */
3786                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3787                case 0x3000:    /* IDEOGRAPHIC SPACE */
3788                MRRETURN(MATCH_NOMATCH);
3789                }
3790              }
3791            break;
3792    
3793            case OP_HSPACE:
3794            for (i = 1; i <= min; i++)
3795              {
3796              if (eptr >= md->end_subject)
3797                {
3798                SCHECK_PARTIAL();
3799                MRRETURN(MATCH_NOMATCH);
3800                }
3801              GETCHARINC(c, eptr);
3802              switch(c)
3803                {
3804                default: MRRETURN(MATCH_NOMATCH);
3805                case 0x09:      /* HT */
3806                case 0x20:      /* SPACE */
3807                case 0xa0:      /* NBSP */
3808                case 0x1680:    /* OGHAM SPACE MARK */
3809                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3810                case 0x2000:    /* EN QUAD */
3811                case 0x2001:    /* EM QUAD */
3812                case 0x2002:    /* EN SPACE */
3813                case 0x2003:    /* EM SPACE */
3814                case 0x2004:    /* THREE-PER-EM SPACE */
3815                case 0x2005:    /* FOUR-PER-EM SPACE */
3816                case 0x2006:    /* SIX-PER-EM SPACE */
3817                case 0x2007:    /* FIGURE SPACE */
3818                case 0x2008:    /* PUNCTUATION SPACE */
3819                case 0x2009:    /* THIN SPACE */
3820                case 0x200A:    /* HAIR SPACE */
3821                case 0x202f:    /* NARROW NO-BREAK SPACE */
3822                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3823                case 0x3000:    /* IDEOGRAPHIC SPACE */
3824                break;
3825                }
3826              }
3827            break;
3828    
3829            case OP_NOT_VSPACE:
3830            for (i = 1; i <= min; i++)
3831              {
3832              if (eptr >= md->end_subject)
3833                {
3834                SCHECK_PARTIAL();
3835                MRRETURN(MATCH_NOMATCH);
3836                }
3837              GETCHARINC(c, eptr);
3838              switch(c)
3839                {
3840                default: break;
3841                case 0x0a:      /* LF */
3842                case 0x0b:      /* VT */
3843                case 0x0c:      /* FF */
3844                case 0x0d:      /* CR */
3845                case 0x85:      /* NEL */
3846                case 0x2028:    /* LINE SEPARATOR */
3847                case 0x2029:    /* PARAGRAPH SEPARATOR */
3848                MRRETURN(MATCH_NOMATCH);
3849                }
3850              }
3851            break;
3852    
3853            case OP_VSPACE:
3854            for (i = 1; i <= min; i++)
3855              {
3856              if (eptr >= md->end_subject)
3857                {
3858                SCHECK_PARTIAL();
3859                MRRETURN(MATCH_NOMATCH);
3860                }
3861              GETCHARINC(c, eptr);
3862              switch(c)
3863                {
3864                default: MRRETURN(MATCH_NOMATCH);
3865                case 0x0a:      /* LF */
3866                case 0x0b:      /* VT */
3867                case 0x0c:      /* FF */
3868                case 0x0d:      /* CR */
3869                case 0x85:      /* NEL */
3870                case 0x2028:    /* LINE SEPARATOR */
3871                case 0x2029:    /* PARAGRAPH SEPARATOR */
3872              break;              break;
3873              }              }
3874            }            }
# Line 2782  for (;;) Line 3877  for (;;)
3877          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3878          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3879            {            {
3880            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3881                {
3882                SCHECK_PARTIAL();
3883                MRRETURN(MATCH_NOMATCH);
3884                }
3885            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3886            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3887              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
3888            }            }
3889          break;          break;
3890    
3891          case OP_DIGIT:          case OP_DIGIT:
3892          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3893            {            {
3894            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3895               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3896              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3897                MRRETURN(MATCH_NOMATCH);
3898                }
3899              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3900                MRRETURN(MATCH_NOMATCH);
3901            /* 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 */
3902            }            }
3903          break;          break;
# Line 2802  for (;;) Line 3905  for (;;)
3905          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3906          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3907            {            {
3908            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3909               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3910              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3911            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              MRRETURN(MATCH_NOMATCH);
3912                }
3913              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3914                MRRETURN(MATCH_NOMATCH);
3915              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3916            }            }
3917          break;          break;
3918    
3919          case OP_WHITESPACE:          case OP_WHITESPACE:
3920          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3921            {            {
3922            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3923               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3924              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3925                MRRETURN(MATCH_NOMATCH);
3926                }
3927              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3928                MRRETURN(MATCH_NOMATCH);
3929            /* 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 */
3930            }            }
3931          break;          break;
# Line 2822  for (;;) Line 3933  for (;;)
3933          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3934          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3935            {            {
3936            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3937               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))              {
3938              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3939            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              MRRETURN(MATCH_NOMATCH);
3940                }
3941              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3942                MRRETURN(MATCH_NOMATCH);
3943              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3944            }            }
3945          break;          break;
3946    
3947          case OP_WORDCHAR:          case OP_WORDCHAR:
3948          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3949            {            {
3950            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3951               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3952              RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3953                MRRETURN(MATCH_NOMATCH);
3954                }
3955              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3956                MRRETURN(MATCH_NOMATCH);
3957            /* 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 */
3958            }            }
3959          break;          break;
# Line 2847  for (;;) Line 3966  for (;;)
3966  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3967    
3968        /* 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
3969        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. */  
3970    
3971        switch(ctype)        switch(ctype)
3972          {          {
3973          case OP_ANY:          case OP_ANY:
3974          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3975            {            {
3976            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3977              {              {
3978              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3979              eptr++;              MRRETURN(MATCH_NOMATCH);
3980              }              }
3981              if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
3982              eptr++;
3983            }            }
         else eptr += min;  
3984          break;          break;
3985    
3986          case OP_ANYBYTE:          case OP_ALLANY:
3987            if (eptr > md->end_subject - min)
3988              {
3989              SCHECK_PARTIAL();
3990              MRRETURN(MATCH_NOMATCH);
3991              }
3992          eptr += min;          eptr += min;
3993          break;          break;
3994    
3995          /* Because of the CRLF case, we can't assume the minimum number of          case OP_ANYBYTE:
3996          bytes are present in this case. */          if (eptr > md->end_subject - min)
3997              {
3998              SCHECK_PARTIAL();
3999              MRRETURN(MATCH_NOMATCH);
4000              }
4001            eptr += min;
4002            break;
4003    
4004          case OP_ANYNL:          case OP_ANYNL:
4005          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4006            {            {
4007            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
4008                {
4009                SCHECK_PARTIAL();
4010                MRRETURN(MATCH_NOMATCH);
4011                }
4012            switch(*eptr++)            switch(*eptr++)
4013              {              {
4014              default: RRETURN(MATCH_NOMATCH);              default: MRRETURN(MATCH_NOMATCH);
4015              case 0x000d:              case 0x000d:
4016              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4017              break;              break;
4018              case 0x000a:              case 0x000a:
4019                break;
4020    
4021              case 0x000b:              case 0x000b:
4022              case 0x000c:              case 0x000c:
4023              case 0x0085:              case 0x0085:
4024                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
4025                break;
4026                }
4027              }
4028            break;
4029    
4030            case OP_NOT_HSPACE:
4031            for (i = 1; i <= min; i++)
4032              {
4033              if (eptr >= md->end_subject)
4034                {
4035                SCHECK_PARTIAL();
4036                MRRETURN(MATCH_NOMATCH);
4037                }
4038              switch(*eptr++)
4039                {
4040                default: break;
4041                case 0x09:      /* HT */
4042                case 0x20:      /* SPACE */
4043                case 0xa0:      /* NBSP */
4044                MRRETURN(MATCH_NOMATCH);
4045                }
4046              }
4047            break;
4048    
4049            case OP_HSPACE:
4050            for (i = 1; i <= min; i++)
4051              {
4052              if (eptr >= md->end_subject)
4053                {
4054                SCHECK_PARTIAL();
4055                MRRETURN(MATCH_NOMATCH);
4056                }
4057              switch(*eptr++)
4058                {
4059                default: MRRETURN(MATCH_NOMATCH);
4060                case 0x09:      /* HT */
4061                case 0x20:      /* SPACE */
4062                case 0xa0:      /* NBSP */
4063                break;
4064                }
4065              }
4066            break;
4067    
4068            case OP_NOT_VSPACE:
4069            for (i = 1; i <= min; i++)
4070              {
4071              if (eptr >= md->end_subject)
4072                {
4073                SCHECK_PARTIAL();
4074                MRRETURN(MATCH_NOMATCH);
4075                }
4076              switch(*eptr++)
4077                {
4078                default: break;
4079                case 0x0a:      /* LF */
4080                case 0x0b:      /* VT */
4081                case 0x0c:      /* FF */
4082                case 0x0d:      /* CR */
4083                case 0x85:      /* NEL */
4084                MRRETURN(MATCH_NOMATCH);
4085                }
4086              }
4087            break;
4088    
4089            case OP_VSPACE:
4090            for (i = 1; i <= min; i++)
4091              {
4092              if (eptr >= md->end_subject)
4093                {
4094                SCHECK_PARTIAL();
4095                MRRETURN(MATCH_NOMATCH);
4096                }
4097              switch(*eptr++)
4098                {
4099                default: MRRETURN(MATCH_NOMATCH);
4100                case 0x0a:      /* LF */
4101                case 0x0b:      /* VT */
4102                case 0x0c:      /* FF */
4103                case 0x0d:      /* CR */
4104                case 0x85:      /* NEL */
4105              break;              break;
4106              }              }
4107            }            }
# Line 2892  for (;;) Line 4109  for (;;)
4109    
4110          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
4111          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4112            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            {
4113              if (eptr >= md->end_subject)
4114                {
4115                SCHECK_PARTIAL();
4116                MRRETURN(MATCH_NOMATCH);
4117                }
4118              if ((md->ctypes[*eptr++] & ctype_digit) != 0) MRRETURN(MATCH_NOMATCH);
4119              }
4120          break;          break;
4121    
4122          case OP_DIGIT:          case OP_DIGIT:
4123          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4124            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            {
4125              if (eptr >= md->end_subject)
4126                {
4127                SCHECK_PARTIAL();
4128                MRRETURN(MATCH_NOMATCH);
4129                }
4130              if ((md->ctypes[*eptr++] & ctype_digit) == 0) MRRETURN(MATCH_NOMATCH);
4131              }
4132          break;          break;
4133    
4134          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
4135          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4136            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            {
4137              if (eptr >= md->end_subject)
4138                {
4139                SCHECK_PARTIAL();
4140                MRRETURN(MATCH_NOMATCH);
4141                }
4142              if ((md->ctypes[*eptr++] & ctype_space) != 0) MRRETURN(MATCH_NOMATCH);
4143              }
4144          break;          break;
4145    
4146          case OP_WHITESPACE:          case OP_WHITESPACE:
4147          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4148            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            {
4149              if (eptr >= md->end_subject)
4150                {
4151                SCHECK_PARTIAL();
4152                MRRETURN(MATCH_NOMATCH);
4153                }
4154              if ((md->ctypes[*eptr++] & ctype_space) == 0) MRRETURN(MATCH_NOMATCH);
4155              }
4156          break;          break;
4157    
4158          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
4159          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4160              {
4161              if (eptr >= md->end_subject)
4162                {
4163                SCHECK_PARTIAL();
4164                MRRETURN(MATCH_NOMATCH);
4165                }
4166            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
4167              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4168              }
4169          break;          break;
4170    
4171          case OP_WORDCHAR:          case OP_WORDCHAR:
4172          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
4173              {
4174              if (eptr >= md->end_subject)
4175                {
4176                SCHECK_PARTIAL();
4177                MRRETURN(MATCH_NOMATCH);
4178                }
4179            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
4180              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
4181              }
4182          break;          break;
4183    
4184          default:          default:
# Line 2945  for (;;) Line 4204  for (;;)
4204            case PT_ANY:            case PT_ANY:
4205            for (fi = min;; fi++)            for (fi = min;; fi++)
4206              {              {
4207              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
4208              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4209              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
4210                if (eptr >= md->end_subject)
4211                  {
4212                  SCHECK_PARTIAL();
4213                  MRRETURN(MATCH_NOMATCH);
4214                  }
4215              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
4216              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
4217