/[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 137 by ph10, Thu Mar 29 13:56:00 2007 UTC revision 435 by ph10, Sat Sep 5 10:20:44 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2007 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 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_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* 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.
80  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,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 152  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 188  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
220  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
221  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
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* 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
251  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef DEBUG
258  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 210  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
275  #else  #else
276    
277    
278  /* 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
279  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
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     {\  
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 256  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 271  typedef struct heapframe { Line 322  typedef struct heapframe {
322    
323    /* Function arguments that may change */    /* Function arguments that may change */
324    
325    const uschar *Xeptr;    USPTR Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      USPTR Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 281  typedef struct heapframe { Line 333  typedef struct heapframe {
333    
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    USPTR Xcallpat;
337    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
338    const uschar *Xdata;    USPTR Xcharptr;
339    const uschar *Xnext;  #endif
340    const uschar *Xpp;    USPTR Xdata;
341    const uschar *Xprev;    USPTR Xnext;
342    const uschar *Xsaved_eptr;    USPTR Xpp;
343      USPTR Xprev;
344      USPTR Xsaved_eptr;
345    
346    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
347    
# Line 308  typedef struct heapframe { Line 362  typedef struct heapframe {
362    uschar Xocchars[8];    uschar Xocchars[8];
363  #endif  #endif
364    
365      int Xcodelink;
366    int Xctype;    int Xctype;
367    unsigned int Xfc;    unsigned int Xfc;
368    int Xfi;    int Xfi;
# Line 323  typedef struct heapframe { Line 378  typedef struct heapframe {
378    
379    eptrblock Xnewptrb;    eptrblock Xnewptrb;
380    
381    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
382    
383    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
384    
385  } heapframe;  } heapframe;
386    
# Line 344  typedef struct heapframe { Line 398  typedef struct heapframe {
398    
399  /* This function is called recursively in many circumstances. Whenever it  /* This function is called recursively in many circumstances. Whenever it
400  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
401  same response.  same response. */
402    
403    /* These macros pack up tests that are used for partial matching, and which
404    appears several times in the code. We set the "hit end" flag if the pointer is
405    at the end of the subject and also past the start of the subject (i.e.
406    something has been matched). For hard partial matching, we then return
407    immediately. The second one is used when we already know we are past the end of
408    the subject. */
409    
410    #define CHECK_PARTIAL()\
411      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417  Performance note: It might be tempting to extract commonly used fields from the  #define SCHECK_PARTIAL()\
418  md structure (e.g. utf8, end_subject) into individual variables to improve    if (md->partial && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424    
425    /* Performance note: It might be tempting to extract commonly used fields from
426    the md structure (e.g. utf8, end_subject) into individual variables to improve
427  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
428  made performance worse.  made performance worse.
429    
430  Arguments:  Arguments:
431     eptr        pointer to current character in subject     eptr        pointer to current character in subject
432     ecode       pointer to current position in compiled code     ecode       pointer to current position in compiled code
433       mstart      pointer to the current match start position (can be modified
434                     by encountering \K)
435     offset_top  current top pointer     offset_top  current top pointer
436     md          pointer to "static" info for the match     md          pointer to "static" info for the match
437     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 363  Arguments: Line 441  Arguments:
441                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
442                   match_cbegroup - this is the start of an unlimited repeat                   match_cbegroup - this is the start of an unlimited repeat
443                     group that can match an empty string                     group that can match an empty string
                  match_tail_recursed - this is a tail_recursed group  
444     rdepth      the recursion depth     rdepth      the recursion depth
445    
446  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 373  Returns:       MATCH_MATCH if matched Line 450  Returns:       MATCH_MATCH if matched
450  */  */
451    
452  static int  static int
453  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
454    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
455    int flags, unsigned int rdepth)    int flags, unsigned int rdepth)
456  {  {
# Line 387  register unsigned int c;   /* Character Line 464  register unsigned int c;   /* Character
464  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
467    int condcode;
468    
469  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
470  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
# Line 401  frame->Xprevframe = NULL;            /* Line 479  frame->Xprevframe = NULL;            /*
479    
480  frame->Xeptr = eptr;  frame->Xeptr = eptr;
481  frame->Xecode = ecode;  frame->Xecode = ecode;
482    frame->Xmstart = mstart;
483  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
484  frame->Xims = ims;  frame->Xims = ims;
485  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 415  HEAP_RECURSE: Line 494  HEAP_RECURSE:
494    
495  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
496  #define ecode              frame->Xecode  #define ecode              frame->Xecode
497    #define mstart             frame->Xmstart
498  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
499  #define ims                frame->Xims  #define ims                frame->Xims
500  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 427  HEAP_RECURSE: Line 507  HEAP_RECURSE:
507  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
508  #endif  #endif
509  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
510    #define codelink           frame->Xcodelink
511  #define data               frame->Xdata  #define data               frame->Xdata
512  #define next               frame->Xnext  #define next               frame->Xnext
513  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 507  int oclength; Line 588  int oclength;
588  uschar occhars[8];  uschar occhars[8];
589  #endif  #endif
590    
591    int codelink;
592  int ctype;  int ctype;
593  int length;  int length;
594  int max;  int max;
# Line 545  defined). However, RMATCH isn't like a f Line 627  defined). However, RMATCH isn't like a f
627  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
629    
630    #ifdef SUPPORT_UTF8
631    utf8 = md->utf8;       /* Local copy of the flag */
632    #else
633    utf8 = FALSE;
634    #endif
635    
636  /* 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
637  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
638    
# Line 553  if (rdepth >= md->match_limit_recursion) Line 641  if (rdepth >= md->match_limit_recursion)
641    
642  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
643    
 #ifdef SUPPORT_UTF8  
 utf8 = md->utf8;       /* Local copy of the flag */  
 #else  
 utf8 = FALSE;  
 #endif  
   
644  /* 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
645  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
646  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
647  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.
648  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
649  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
650  already used. */  block that is used is on the stack, so a new one may be required for each
651    match(). */
652    
653  if ((flags & match_cbegroup) != 0)  if ((flags & match_cbegroup) != 0)
654    {    {
655    eptrblock *p;    newptrb.epb_saved_eptr = eptr;
656    if ((flags & match_tail_recursed) != 0)    newptrb.epb_prev = eptrb;
657      {    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;  
658    }    }
659    
660  /* Now start processing the opcodes. */  /* Now start processing the opcodes. */
# Line 587  for (;;) Line 663  for (;;)
663    {    {
664    minimize = possessive = FALSE;    minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
666    
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. */  
   
   if (md->partial &&  
       eptr >= md->end_subject &&  
       eptr > md->start_match)  
     md->hitend = TRUE;  
   
667    switch(op)    switch(op)
668      {      {
669        case OP_FAIL:
670        RRETURN(MATCH_NOMATCH);
671    
672        case OP_PRUNE:
673        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
674          ims, eptrb, flags, RM51);
675        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
676        RRETURN(MATCH_PRUNE);
677    
678        case OP_COMMIT:
679        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
680          ims, eptrb, flags, RM52);
681        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
682        RRETURN(MATCH_COMMIT);
683    
684        case OP_SKIP:
685        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
686          ims, eptrb, flags, RM53);
687        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
688        md->start_match_ptr = eptr;   /* Pass back current position */
689        RRETURN(MATCH_SKIP);
690    
691        case OP_THEN:
692        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
693          ims, eptrb, flags, RM54);
694        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
695        RRETURN(MATCH_THEN);
696    
697      /* 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
698      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.
699      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 637  for (;;) Line 733  for (;;)
733        flags = (op == OP_SCBRA)? match_cbegroup : 0;        flags = (op == OP_SCBRA)? match_cbegroup : 0;
734        do        do
735          {          {
736          RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
737            ims, eptrb, flags);            ims, eptrb, flags, RM1);
738          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
739          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
740          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
741          }          }
# Line 654  for (;;) Line 750  for (;;)
750        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
751        }        }
752    
753      /* Insufficient room for saving captured contents. Treat as a non-capturing      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
754      bracket. */      as a non-capturing bracket. */
755    
756        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
757        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
758    
759      DPRINTF(("insufficient capture room: treat as non-capturing\n"));      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
760    
761        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
762        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
763    
764      /* 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
765      final alternative within the brackets, we would return the result of a      final alternative within the brackets, we would return the result of a
766      recursive call to match() whatever happened. We can reduce stack usage by      recursive call to match() whatever happened. We can reduce stack usage by
767      turning this into a tail recursion. */      turning this into a tail recursion, except in the case when match_cbegroup
768        is set.*/
769    
770      case OP_BRA:      case OP_BRA:
771      case OP_SBRA:      case OP_SBRA:
# Line 670  for (;;) Line 773  for (;;)
773      flags = (op >= OP_SBRA)? match_cbegroup : 0;      flags = (op >= OP_SBRA)? match_cbegroup : 0;
774      for (;;)      for (;;)
775        {        {
776        if (ecode[GET(ecode, 1)] != OP_ALT)        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
777          {          {
778          ecode += _pcre_OP_lengths[*ecode];          if (flags == 0)    /* Not a possibly empty group */
779          flags |= match_tail_recursed;            {
780          DPRINTF(("bracket 0 tail recursion\n"));            ecode += _pcre_OP_lengths[*ecode];
781          goto TAIL_RECURSE;            DPRINTF(("bracket 0 tail recursion\n"));
782              goto TAIL_RECURSE;
783              }
784    
785            /* Possibly empty group; can't use tail recursion. */
786    
787            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
788              eptrb, flags, RM48);
789            RRETURN(rrc);
790          }          }
791    
792        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
793        otherwise return. */        otherwise return. */
794    
795        RMATCH(rrc, eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
796          eptrb, flags);          eptrb, flags, RM2);
797        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
798        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
799        }        }
800      /* Control never reaches here. */      /* Control never reaches here. */
# Line 696  for (;;) Line 807  for (;;)
807    
808      case OP_COND:      case OP_COND:
809      case OP_SCOND:      case OP_SCOND:
810      if (ecode[LINK_SIZE+1] == OP_RREF)         /* Recursion test */      codelink= GET(ecode, 1);
811    
812        /* Because of the way auto-callout works during compile, a callout item is
813        inserted between OP_COND and an assertion condition. */
814    
815        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816          {
817          if (pcre_callout != NULL)
818            {
819            pcre_callout_block cb;
820            cb.version          = 1;   /* Version 1 of the callout block */
821            cb.callout_number   = ecode[LINK_SIZE+2];
822            cb.offset_vector    = md->offset_vector;
823            cb.subject          = (PCRE_SPTR)md->start_subject;
824            cb.subject_length   = md->end_subject - md->start_subject;
825            cb.start_match      = mstart - md->start_subject;
826            cb.current_position = eptr - md->start_subject;
827            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
828            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
829            cb.capture_top      = offset_top/2;
830            cb.capture_last     = md->capture_last;
831            cb.callout_data     = md->callout_data;
832            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
833            if (rrc < 0) RRETURN(rrc);
834            }
835          ecode += _pcre_OP_lengths[OP_CALLOUT];
836          }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840        /* Now see what the actual condition is */
841    
842        if (condcode == OP_RREF)         /* Recursion test */
843        {        {
844        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/        offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
845        condition = md->recursive != NULL &&        condition = md->recursive != NULL &&
# Line 704  for (;;) Line 847  for (;;)
847        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
848        }        }
849    
850      else if (ecode[LINK_SIZE+1] == OP_CREF)    /* Group used test */      else if (condcode == OP_CREF)    /* Group used test */
851        {        {
852        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
853        condition = offset < offset_top && md->offset_vector[offset] >= 0;        condition = offset < offset_top && md->offset_vector[offset] >= 0;
854        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 3 : GET(ecode, 1);
855        }        }
856    
857      else if (ecode[LINK_SIZE+1] == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
858        {        {
859        condition = FALSE;        condition = FALSE;
860        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
# Line 723  for (;;) Line 866  for (;;)
866    
867      else      else
868        {        {
869        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
870            match_condassert);            match_condassert, RM3);
871        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
872          {          {
873          condition = TRUE;          condition = TRUE;
874          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
875          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
876          }          }
877        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
878          {          {
879          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
880          }          }
881        else        else
882          {          {
883          condition = FALSE;          condition = FALSE;
884          ecode += GET(ecode, 1);          ecode += codelink;
885          }          }
886        }        }
887    
888      /* 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,
889      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
890      alternative doesn't exist, we can just plough on. */      match_cbegroup is required for an unlimited repeat of a possibly empty
891        group. If the second alternative doesn't exist, we can just plough on. */
892    
893      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
894        {        {
895        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
896        flags = match_tail_recursed | ((op == OP_SCOND)? match_cbegroup : 0);        if (op == OP_SCOND)        /* Possibly empty group */
897        goto TAIL_RECURSE;          {
898            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
899            RRETURN(rrc);
900            }
901          else                       /* Group must match something */
902            {
903            flags = 0;
904            goto TAIL_RECURSE;
905            }
906        }        }
907      else      else                         /* Condition false & no alternative */
908        {        {
909        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
910        }        }
911      break;      break;
912    
913    
914      /* End of the pattern. If we are in a top-level recursion, we should      /* End of the pattern, either real or forced. If we are in a top-level
915      restore the offsets appropriately and continue from after the call. */      recursion, we should restore the offsets appropriately and continue from
916        after the call. */
917    
918        case OP_ACCEPT:
919      case OP_END:      case OP_END:
920      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
921        {        {
# Line 770  for (;;) Line 924  for (;;)
924        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
925        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
926          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
927        md->start_match = rec->save_start;        mstart = rec->save_start;
928        ims = original_ims;        ims = original_ims;
929        ecode = rec->after_call;        ecode = rec->after_call;
930        break;        break;
# Line 779  for (;;) Line 933  for (;;)
933      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty
934      string - backtracking will then try other alternatives, if any. */      string - backtracking will then try other alternatives, if any. */
935    
936      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      if (md->notempty && eptr == mstart) RRETURN(MATCH_NOMATCH);
937      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_match_ptr = eptr;           /* Record where we ended */
938      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
939        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
940      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
941    
942      /* Change option settings */      /* Change option settings */
# Line 802  for (;;) Line 957  for (;;)
957      case OP_ASSERTBACK:      case OP_ASSERTBACK:
958      do      do
959        {        {
960        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,
961            RM4);
962        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
963        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
964        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
965        }        }
966      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 828  for (;;) Line 984  for (;;)
984      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
985      do      do
986        {        {
987        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,
988            RM5);
989        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
990        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
991        ecode += GET(ecode,1);        ecode += GET(ecode,1);
992        }        }
993      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 854  for (;;) Line 1011  for (;;)
1011          {          {
1012          eptr--;          eptr--;
1013          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1014          BACKCHAR(eptr)          BACKCHAR(eptr);
1015          }          }
1016        }        }
1017      else      else
# Line 867  for (;;) Line 1024  for (;;)
1024        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1025        }        }
1026    
1027      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1028    
1029        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1030      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1031      break;      break;
1032    
# Line 885  for (;;) Line 1043  for (;;)
1043        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1044        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1045        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1046        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1047        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1048        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1049        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 947  for (;;) Line 1105  for (;;)
1105    
1106        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1107              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1108        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1109        md->start_match = eptr;        mstart = eptr;
1110    
1111        /* 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
1112        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 957  for (;;) Line 1115  for (;;)
1115        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1116        do        do
1117          {          {
1118          RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1119            md, ims, eptrb, flags);            md, ims, eptrb, flags, RM6);
1120          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1121            {            {
1122            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 967  for (;;) Line 1125  for (;;)
1125              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1126            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1127            }            }
1128          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1129            {            {
1130            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1131              if (new_recursive.offset_save != stacksave)
1132                (pcre_free)(new_recursive.offset_save);
1133            RRETURN(rrc);            RRETURN(rrc);
1134            }            }
1135    
# Line 1001  for (;;) Line 1161  for (;;)
1161    
1162      do      do
1163        {        {
1164        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
         eptrb, 0);  
1165        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1166        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1167        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1168        }        }
1169      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1047  for (;;) Line 1206  for (;;)
1206    
1207      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1208        {        {
1209        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);
1210        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1211        ecode = prev;        ecode = prev;
1212        flags = match_tail_recursed;        flags = 0;
1213        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1214        }        }
1215      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1216        {        {
1217        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1218        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1219        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1220        flags = match_tail_recursed;        flags = 0;
1221        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1222        }        }
1223      /* Control never gets here */      /* Control never gets here */
# Line 1070  for (;;) Line 1229  for (;;)
1229      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1230      break;      break;
1231    
1232      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1233      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
1234      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
1235      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
1236      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1237    
1238      case OP_BRAZERO:      case OP_BRAZERO:
1239        {        {
1240        next = ecode+1;        next = ecode+1;
1241        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1242        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1243        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1244        ecode = next + 1 + LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
# Line 1090  for (;;) Line 1249  for (;;)
1249        {        {
1250        next = ecode+1;        next = ecode+1;
1251        do next += GET(next, 1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1252        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);
1253        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1254        ecode++;        ecode++;
1255        }        }
1256      break;      break;
1257    
1258        case OP_SKIPZERO:
1259          {
1260          next = ecode+1;
1261          do next += GET(next,1); while (*next == OP_ALT);
1262          ecode = next + 1 + LINK_SIZE;
1263          }
1264        break;
1265    
1266      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1267    
1268      case OP_KET:      case OP_KET:
# Line 1160  for (;;) Line 1327  for (;;)
1327          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1328          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1329          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1330          md->start_match = rec->save_start;          mstart = rec->save_start;
1331          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1332            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1333          ecode = rec->after_call;          ecode = rec->after_call;
# Line 1189  for (;;) Line 1356  for (;;)
1356    
1357      /* 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
1358      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
1359      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1360        unlimited repeat of a group that can match an empty string. */
1361    
1362      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1363    
1364      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1365        {        {
1366        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);
1367        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1368          if (flags != 0)    /* Could match an empty string */
1369            {
1370            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1371            RRETURN(rrc);
1372            }
1373        ecode = prev;        ecode = prev;
       flags |= match_tail_recursed;  
1374        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1375        }        }
1376      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1377        {        {
1378        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1379        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1380        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1381        flags = match_tail_recursed;        flags = 0;
1382        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1383        }        }
1384      /* Control never gets here */      /* Control never gets here */
# Line 1239  for (;;) Line 1411  for (;;)
1411      ecode++;      ecode++;
1412      break;      break;
1413    
1414        /* Reset the start of match point */
1415    
1416        case OP_SET_SOM:
1417        mstart = eptr;
1418        ecode++;
1419        break;
1420    
1421      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1422      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1423    
# Line 1290  for (;;) Line 1469  for (;;)
1469    
1470        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1471        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
1472        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1473          partial matching. */
1474    
1475  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1476        if (utf8)        if (utf8)
1477          {          {
1478          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1479            {            {
1480            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1481            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1482              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1483            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1484            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1485            }            }
1486          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1487              {
1488              SCHECK_PARTIAL();
1489              cur_is_word = FALSE;
1490              }
1491            else
1492            {            {
1493            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1494            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1311  for (;;) Line 1497  for (;;)
1497        else        else
1498  #endif  #endif
1499    
1500        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1501    
1502          {          {
1503          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1504            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1505          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1506            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1507              }
1508            if (eptr >= md->end_subject)
1509              {
1510              SCHECK_PARTIAL();
1511              cur_is_word = FALSE;
1512              }
1513            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1514          }          }
1515    
1516        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1331  for (;;) Line 1524  for (;;)
1524      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1525    
1526      case OP_ANY:      case OP_ANY:
1527      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1528        /* Fall through */
1529    
1530        case OP_ALLANY:
1531        if (eptr++ >= md->end_subject)
1532        {        {
1533        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);        SCHECK_PARTIAL();
1534        }        RRETURN(MATCH_NOMATCH);
1535      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);        }
1536      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1537      ecode++;      ecode++;
1538      break;      break;
1539    
# Line 1345  for (;;) Line 1541  for (;;)
1541      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1542    
1543      case OP_ANYBYTE:      case OP_ANYBYTE:
1544      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1545          {
1546          SCHECK_PARTIAL();
1547          RRETURN(MATCH_NOMATCH);
1548          }
1549      ecode++;      ecode++;
1550      break;      break;
1551    
1552      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1553      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1554          {
1555          SCHECK_PARTIAL();
1556          RRETURN(MATCH_NOMATCH);
1557          }
1558      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1559      if (      if (
1560  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1363  for (;;) Line 1567  for (;;)
1567      break;      break;
1568    
1569      case OP_DIGIT:      case OP_DIGIT:
1570      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1571          {
1572          SCHECK_PARTIAL();
1573          RRETURN(MATCH_NOMATCH);
1574          }
1575      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1576      if (      if (
1577  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1376  for (;;) Line 1584  for (;;)
1584      break;      break;
1585    
1586      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1587      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1588          {
1589          SCHECK_PARTIAL();
1590          RRETURN(MATCH_NOMATCH);
1591          }
1592      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1593      if (      if (
1594  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1389  for (;;) Line 1601  for (;;)
1601      break;      break;
1602    
1603      case OP_WHITESPACE:      case OP_WHITESPACE:
1604      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1605          {
1606          SCHECK_PARTIAL();
1607          RRETURN(MATCH_NOMATCH);
1608          }
1609      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1610      if (      if (
1611  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1402  for (;;) Line 1618  for (;;)
1618      break;      break;
1619    
1620      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1621      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1622          {
1623          SCHECK_PARTIAL();
1624          RRETURN(MATCH_NOMATCH);
1625          }
1626      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1627      if (      if (
1628  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1415  for (;;) Line 1635  for (;;)
1635      break;      break;
1636    
1637      case OP_WORDCHAR:      case OP_WORDCHAR:
1638      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1639          {
1640          SCHECK_PARTIAL();
1641          RRETURN(MATCH_NOMATCH);
1642          }
1643      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1644      if (      if (
1645  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1428  for (;;) Line 1652  for (;;)
1652      break;      break;
1653    
1654      case OP_ANYNL:      case OP_ANYNL:
1655      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1656          {
1657          SCHECK_PARTIAL();
1658          RRETURN(MATCH_NOMATCH);
1659          }
1660      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1661      switch(c)      switch(c)
1662        {        {
# Line 1436  for (;;) Line 1664  for (;;)
1664        case 0x000d:        case 0x000d:
1665        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1666        break;        break;
1667    
1668        case 0x000a:        case 0x000a:
1669          break;
1670    
1671        case 0x000b:        case 0x000b:
1672        case 0x000c:        case 0x000c:
1673        case 0x0085:        case 0x0085:
1674        case 0x2028:        case 0x2028:
1675        case 0x2029:        case 0x2029:
1676          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1677          break;
1678          }
1679        ecode++;
1680        break;
1681    
1682        case OP_NOT_HSPACE:
1683        if (eptr >= md->end_subject)
1684          {
1685          SCHECK_PARTIAL();
1686          RRETURN(MATCH_NOMATCH);
1687          }
1688        GETCHARINCTEST(c, eptr);
1689        switch(c)
1690          {
1691          default: break;
1692          case 0x09:      /* HT */
1693          case 0x20:      /* SPACE */
1694          case 0xa0:      /* NBSP */
1695          case 0x1680:    /* OGHAM SPACE MARK */
1696          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1697          case 0x2000:    /* EN QUAD */
1698          case 0x2001:    /* EM QUAD */
1699          case 0x2002:    /* EN SPACE */
1700          case 0x2003:    /* EM SPACE */
1701          case 0x2004:    /* THREE-PER-EM SPACE */
1702          case 0x2005:    /* FOUR-PER-EM SPACE */
1703          case 0x2006:    /* SIX-PER-EM SPACE */
1704          case 0x2007:    /* FIGURE SPACE */
1705          case 0x2008:    /* PUNCTUATION SPACE */
1706          case 0x2009:    /* THIN SPACE */
1707          case 0x200A:    /* HAIR SPACE */
1708          case 0x202f:    /* NARROW NO-BREAK SPACE */
1709          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1710          case 0x3000:    /* IDEOGRAPHIC SPACE */
1711          RRETURN(MATCH_NOMATCH);
1712          }
1713        ecode++;
1714        break;
1715    
1716        case OP_HSPACE:
1717        if (eptr >= md->end_subject)
1718          {
1719          SCHECK_PARTIAL();
1720          RRETURN(MATCH_NOMATCH);
1721          }
1722        GETCHARINCTEST(c, eptr);
1723        switch(c)
1724          {
1725          default: RRETURN(MATCH_NOMATCH);
1726          case 0x09:      /* HT */
1727          case 0x20:      /* SPACE */
1728          case 0xa0:      /* NBSP */
1729          case 0x1680:    /* OGHAM SPACE MARK */
1730          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1731          case 0x2000:    /* EN QUAD */
1732          case 0x2001:    /* EM QUAD */
1733          case 0x2002:    /* EN SPACE */
1734          case 0x2003:    /* EM SPACE */
1735          case 0x2004:    /* THREE-PER-EM SPACE */
1736          case 0x2005:    /* FOUR-PER-EM SPACE */
1737          case 0x2006:    /* SIX-PER-EM SPACE */
1738          case 0x2007:    /* FIGURE SPACE */
1739          case 0x2008:    /* PUNCTUATION SPACE */
1740          case 0x2009:    /* THIN SPACE */
1741          case 0x200A:    /* HAIR SPACE */
1742          case 0x202f:    /* NARROW NO-BREAK SPACE */
1743          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1744          case 0x3000:    /* IDEOGRAPHIC SPACE */
1745          break;
1746          }
1747        ecode++;
1748        break;
1749    
1750        case OP_NOT_VSPACE:
1751        if (eptr >= md->end_subject)
1752          {
1753          SCHECK_PARTIAL();
1754          RRETURN(MATCH_NOMATCH);
1755          }
1756        GETCHARINCTEST(c, eptr);
1757        switch(c)
1758          {
1759          default: break;
1760          case 0x0a:      /* LF */
1761          case 0x0b:      /* VT */
1762          case 0x0c:      /* FF */
1763          case 0x0d:      /* CR */
1764          case 0x85:      /* NEL */
1765          case 0x2028:    /* LINE SEPARATOR */
1766          case 0x2029:    /* PARAGRAPH SEPARATOR */
1767          RRETURN(MATCH_NOMATCH);
1768          }
1769        ecode++;
1770        break;
1771    
1772        case OP_VSPACE:
1773        if (eptr >= md->end_subject)
1774          {
1775          SCHECK_PARTIAL();
1776          RRETURN(MATCH_NOMATCH);
1777          }
1778        GETCHARINCTEST(c, eptr);
1779        switch(c)
1780          {
1781          default: RRETURN(MATCH_NOMATCH);
1782          case 0x0a:      /* LF */
1783          case 0x0b:      /* VT */
1784          case 0x0c:      /* FF */
1785          case 0x0d:      /* CR */
1786          case 0x85:      /* NEL */
1787          case 0x2028:    /* LINE SEPARATOR */
1788          case 0x2029:    /* PARAGRAPH SEPARATOR */
1789        break;        break;
1790        }        }
1791      ecode++;      ecode++;
# Line 1453  for (;;) Line 1797  for (;;)
1797    
1798      case OP_PROP:      case OP_PROP:
1799      case OP_NOTPROP:      case OP_NOTPROP:
1800      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1801          {
1802          SCHECK_PARTIAL();
1803          RRETURN(MATCH_NOMATCH);
1804          }
1805      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1806        {        {
1807        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1808    
1809        switch(ecode[1])        switch(ecode[1])
1810          {          {
# Line 1466  for (;;) Line 1813  for (;;)
1813          break;          break;
1814    
1815          case PT_LAMP:          case PT_LAMP:
1816          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1817               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1818               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1819            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1820           break;           break;
1821    
1822          case PT_GC:          case PT_GC:
1823          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1824            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1825          break;          break;
1826    
1827          case PT_PC:          case PT_PC:
1828          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1829            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1830          break;          break;
1831    
1832          case PT_SC:          case PT_SC:
1833          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1834            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1835          break;          break;
1836    
# Line 1499  for (;;) Line 1846  for (;;)
1846      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
1847    
1848      case OP_EXTUNI:      case OP_EXTUNI:
1849      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1850          {
1851          SCHECK_PARTIAL();
1852          RRETURN(MATCH_NOMATCH);
1853          }
1854      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1855        {        {
1856        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1857        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1858        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1859          {          {
# Line 1512  for (;;) Line 1862  for (;;)
1862            {            {
1863            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1864            }            }
1865          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1866          if (category != ucp_M) break;          if (category != ucp_M) break;
1867          eptr += len;          eptr += len;
1868          }          }
# Line 1533  for (;;) Line 1883  for (;;)
1883      case OP_REF:      case OP_REF:
1884        {        {
1885        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1886        ecode += 3;                                 /* Advance past item */        ecode += 3;
1887    
1888          /* If the reference is unset, there are two possibilities:
1889    
1890          (a) In the default, Perl-compatible state, set the length to be longer
1891          than the amount of subject left; this ensures that every attempt at a
1892          match fails. We can't just fail here, because of the possibility of
1893          quantifiers with zero minima.
1894    
1895          (b) If the JavaScript compatibility flag is set, set the length to zero
1896          so that the back reference matches an empty string.
1897    
1898        /* If the reference is unset, set the length to be longer than the amount        Otherwise, set the length to the length of what was matched by the
1899        of subject left; this ensures that every attempt at a match fails. We        referenced subpattern. */
1900        can't just fail here, because of the possibility of quantifiers with zero  
1901        minima. */        if (offset >= offset_top || md->offset_vector[offset] < 0)
1902            length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1903        length = (offset >= offset_top || md->offset_vector[offset] < 0)?        else
1904          md->end_subject - eptr + 1 :          length = md->offset_vector[offset+1] - md->offset_vector[offset];
         md->offset_vector[offset+1] - md->offset_vector[offset];  
1905    
1906        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1907    
# Line 1571  for (;;) Line 1930  for (;;)
1930          break;          break;
1931    
1932          default:               /* No repeat follows */          default:               /* No repeat follows */
1933          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1934              {
1935              CHECK_PARTIAL();
1936              RRETURN(MATCH_NOMATCH);
1937              }
1938          eptr += length;          eptr += length;
1939          continue;              /* With the main loop */          continue;              /* With the main loop */
1940          }          }
1941    
1942        /* If the length of the reference is zero, just continue with the        /* If the length of the reference is zero, just continue with the
1943        main loop. */        main loop. */
1944    
1945        if (length == 0) continue;        if (length == 0) continue;
1946    
1947        /* First, ensure the minimum number of matches are present. We get back        /* First, ensure the minimum number of matches are present. We get back
# Line 1587  for (;;) Line 1950  for (;;)
1950    
1951        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
1952          {          {
1953          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1954              {
1955              CHECK_PARTIAL();
1956              RRETURN(MATCH_NOMATCH);
1957              }
1958          eptr += length;          eptr += length;
1959          }          }
1960    
# Line 1602  for (;;) Line 1969  for (;;)
1969          {          {
1970          for (fi = min;; fi++)          for (fi = min;; fi++)
1971            {            {
1972            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1973            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1974            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
1975              if (!match_ref(offset, eptr, length, md, ims))
1976                {
1977                CHECK_PARTIAL();
1978              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
1979                }
1980            eptr += length;            eptr += length;
1981            }            }
1982          /* Control never gets here */          /* Control never gets here */
# Line 1623  for (;;) Line 1994  for (;;)
1994            }            }
1995          while (eptr >= pp)          while (eptr >= pp)
1996            {            {
1997            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1998            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1999            eptr -= length;            eptr -= length;
2000            }            }
# Line 1632  for (;;) Line 2003  for (;;)
2003        }        }
2004      /* Control never gets here */      /* Control never gets here */
2005    
   
   
2006      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2007      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,
2008      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 2057  for (;;)
2057          {          {
2058          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2059            {            {
2060            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2061                {
2062                SCHECK_PARTIAL();
2063                RRETURN(MATCH_NOMATCH);
2064                }
2065            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2066            if (c > 255)            if (c > 255)
2067              {              {
# Line 1706  for (;;) Line 2079  for (;;)
2079          {          {
2080          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2081            {            {
2082            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2083                {
2084                SCHECK_PARTIAL();
2085                RRETURN(MATCH_NOMATCH);
2086                }
2087            c = *eptr++;            c = *eptr++;
2088            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2089            }            }
# Line 1728  for (;;) Line 2105  for (;;)
2105            {            {
2106            for (fi = min;; fi++)            for (fi = min;; fi++)
2107              {              {
2108              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2109              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2110              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2111                if (eptr >= md->end_subject)
2112                  {
2113                  SCHECK_PARTIAL();
2114                  RRETURN(MATCH_NOMATCH);
2115                  }
2116              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2117              if (c > 255)              if (c > 255)
2118                {                {
# Line 1748  for (;;) Line 2130  for (;;)
2130            {            {
2131            for (fi = min;; fi++)            for (fi = min;; fi++)
2132              {              {
2133              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2134              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2135              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2136                if (eptr >= md->end_subject)
2137                  {
2138                  SCHECK_PARTIAL();
2139                  RRETURN(MATCH_NOMATCH);
2140                  }
2141              c = *eptr++;              c = *eptr++;
2142              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2143              }              }
# Line 1785  for (;;) Line 2172  for (;;)
2172              }              }
2173            for (;;)            for (;;)
2174              {              {
2175              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2176              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2177              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2178              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1804  for (;;) Line 2191  for (;;)
2191              }              }
2192            while (eptr >= pp)            while (eptr >= pp)
2193              {              {
2194              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2195              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2196              eptr--;              eptr--;
2197              }              }
# Line 1817  for (;;) Line 2204  for (;;)
2204    
2205    
2206      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2207      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
2208        mode, because Unicode properties are supported in non-UTF-8 mode. */
2209    
2210  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2211      case OP_XCLASS:      case OP_XCLASS:
# Line 1858  for (;;) Line 2246  for (;;)
2246    
2247        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2248          {          {
2249          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2250          GETCHARINC(c, eptr);            {
2251              SCHECK_PARTIAL();
2252              RRETURN(MATCH_NOMATCH);
2253              }
2254            GETCHARINCTEST(c, eptr);
2255          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2256          }          }
2257    
# Line 1875  for (;;) Line 2267  for (;;)
2267          {          {
2268          for (fi = min;; fi++)          for (fi = min;; fi++)
2269            {            {
2270            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2271            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2272            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2273            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2274                {
2275                SCHECK_PARTIAL();
2276                RRETURN(MATCH_NOMATCH);
2277                }
2278              GETCHARINCTEST(c, eptr);
2279            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2280            }            }
2281          /* Control never gets here */          /* Control never gets here */
# Line 1893  for (;;) Line 2290  for (;;)
2290            {            {
2291            int len = 1;            int len = 1;
2292            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2293            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2294            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2295            eptr += len;            eptr += len;
2296            }            }
2297          for(;;)          for(;;)
2298            {            {
2299            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2300            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2301            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2302            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2303            }            }
2304          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2305          }          }
# Line 1920  for (;;) Line 2317  for (;;)
2317        length = 1;        length = 1;
2318        ecode++;        ecode++;
2319        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2320        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2321            {
2322            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2323            RRETURN(MATCH_NOMATCH);
2324            }
2325        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2326        }        }
2327      else      else
# Line 1928  for (;;) Line 2329  for (;;)
2329    
2330      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2331        {        {
2332        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2333            {
2334            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2335            RRETURN(MATCH_NOMATCH);
2336            }
2337        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2338        ecode += 2;        ecode += 2;
2339        }        }
# Line 1944  for (;;) Line 2349  for (;;)
2349        ecode++;        ecode++;
2350        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2351    
2352        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2353            {
2354            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2355            RRETURN(MATCH_NOMATCH);
2356            }
2357    
2358        /* 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
2359        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1968  for (;;) Line 2377  for (;;)
2377          if (fc != dc)          if (fc != dc)
2378            {            {
2379  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2380            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2381  #endif  #endif
2382              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2383            }            }
# Line 1979  for (;;) Line 2388  for (;;)
2388    
2389      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2390        {        {
2391        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2392            {
2393            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2394            RRETURN(MATCH_NOMATCH);
2395            }
2396        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2397        ecode += 2;        ecode += 2;
2398        }        }
# Line 2033  for (;;) Line 2446  for (;;)
2446      case OP_MINQUERY:      case OP_MINQUERY:
2447      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2448      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2449    
2450      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2451      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2452      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2453    
2454      /* 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. */  
2455    
2456      REPEATCHAR:      REPEATCHAR:
2457  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2048  for (;;) Line 2460  for (;;)
2460        length = 1;        length = 1;
2461        charptr = ecode;        charptr = ecode;
2462        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2463        ecode += length;        ecode += length;
2464    
2465        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2059  for (;;) Line 2470  for (;;)
2470  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2471          unsigned int othercase;          unsigned int othercase;
2472          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2473              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2474            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2475          else oclength = 0;          else oclength = 0;
2476  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2477    
2478          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2479            {            {
2480            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2481                memcmp(eptr, charptr, length) == 0) eptr += length;
2482  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2483            /* Need braces because of following else */            else if (oclength > 0 &&
2484            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                     eptr <= md->end_subject - oclength &&
2485                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2486    #endif  /* SUPPORT_UCP */
2487            else            else
2488              {              {
2489              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2490              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2491              }              }
 #else   /* without SUPPORT_UCP */  
           else { RRETURN(MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2492            }            }
2493    
2494          if (min == max) continue;          if (min == max) continue;
# Line 2086  for (;;) Line 2497  for (;;)
2497            {            {
2498            for (fi = min;; fi++)            for (fi = min;; fi++)
2499              {              {
2500              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2501              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2502              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2503              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2504                  memcmp(eptr, charptr, length) == 0) eptr += length;
2505  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2506              /* Need braces because of following else */              else if (oclength > 0 &&
2507              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                       eptr <= md->end_subject - oclength &&
2508                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2509    #endif  /* SUPPORT_UCP */
2510              else              else
2511                {                {
2512                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2513                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2514                }                }
 #else   /* without SUPPORT_UCP */  
             else { RRETURN (MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2515              }              }
2516            /* Control never gets here */            /* Control never gets here */
2517            }            }
# Line 2110  for (;;) Line 2521  for (;;)
2521            pp = eptr;            pp = eptr;
2522            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2523              {              {
2524              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2525              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2526  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2527              else if (oclength == 0) break;              else if (oclength > 0 &&
2528              else                       eptr <= md->end_subject - oclength &&
2529                {                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
               if (memcmp(eptr, occhars, oclength) != 0) break;  
               eptr += oclength;  
               }  
 #else   /* without SUPPORT_UCP */  
             else break;  
2530  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2531                else break;
2532              }              }
2533    
2534            if (possessive) continue;            if (possessive) continue;
2535    
2536            for(;;)            for(;;)
2537             {              {
2538             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2539             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2540             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2541  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2542             eptr--;              eptr--;
2543             BACKCHAR(eptr);              BACKCHAR(eptr);
2544  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2545             eptr -= length;              eptr -= length;
2546  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2547             }              }
2548            }            }
2549          /* Control never gets here */          /* Control never gets here */
2550          }          }
# Line 2149  for (;;) Line 2557  for (;;)
2557  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2558    
2559      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
       {  
       if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
       fc = *ecode++;  
       }  
2560    
2561        fc = *ecode++;
2562    
2563      /* 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
2564      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
2565      caseful cases, for speed, since matching characters is likely to be quite      caseful cases, for speed, since matching characters is likely to be quite
# Line 2170  for (;;) Line 2576  for (;;)
2576        {        {
2577        fc = md->lcc[fc];        fc = md->lcc[fc];
2578        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2579            {
2580            if (eptr >= md->end_subject)
2581              {
2582              SCHECK_PARTIAL();
2583              RRETURN(MATCH_NOMATCH);
2584              }
2585          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2586            }
2587        if (min == max) continue;        if (min == max) continue;
2588        if (minimize)        if (minimize)
2589          {          {
2590          for (fi = min;; fi++)          for (fi = min;; fi++)
2591            {            {
2592            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2593            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2594            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2595                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2596                {
2597                SCHECK_PARTIAL();
2598              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2599                }
2600              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2601            }            }
2602          /* Control never gets here */          /* Control never gets here */
2603          }          }
# Line 2192  for (;;) Line 2609  for (;;)
2609            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2610            eptr++;            eptr++;
2611            }            }
2612    
2613          if (possessive) continue;          if (possessive) continue;
2614    
2615          while (eptr >= pp)          while (eptr >= pp)
2616            {            {
2617            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2618            eptr--;            eptr--;
2619            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2620            }            }
# Line 2208  for (;;) Line 2627  for (;;)
2627    
2628      else      else
2629        {        {
2630        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2631        if (min == max) continue;          {
2632        if (minimize)          if (eptr >= md->end_subject)
2633              {
2634              SCHECK_PARTIAL();
2635              RRETURN(MATCH_NOMATCH);
2636              }
2637            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2638            }
2639    
2640          if (min == max) continue;
2641    
2642          if (minimize)
2643          {          {
2644          for (fi = min;; fi++)          for (fi = min;; fi++)
2645            {            {
2646            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2647            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2648            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2649              if (eptr >= md->end_subject)
2650                {
2651                SCHECK_PARTIAL();
2652              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2653                }
2654              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2655            }            }
2656          /* Control never gets here */          /* Control never gets here */
2657          }          }
# Line 2230  for (;;) Line 2664  for (;;)
2664            eptr++;            eptr++;
2665            }            }
2666          if (possessive) continue;          if (possessive) continue;
2667    
2668          while (eptr >= pp)          while (eptr >= pp)
2669            {            {
2670            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2671            eptr--;            eptr--;
2672            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2673            }            }
# Line 2245  for (;;) Line 2680  for (;;)
2680      checking can be multibyte. */      checking can be multibyte. */
2681    
2682      case OP_NOT:      case OP_NOT:
2683      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2684          {
2685          SCHECK_PARTIAL();
2686          RRETURN(MATCH_NOMATCH);
2687          }
2688      ecode++;      ecode++;
2689      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2690      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2322  for (;;) Line 2761  for (;;)
2761      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2762      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2763    
2764      /* 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. */  
2765    
2766      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2767      fc = *ecode++;      fc = *ecode++;
2768    
2769      /* 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 2788  for (;;)
2788          register unsigned int d;          register unsigned int d;
2789          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2790            {            {
2791              if (eptr >= md->end_subject)
2792                {
2793                SCHECK_PARTIAL();
2794                RRETURN(MATCH_NOMATCH);
2795                }
2796            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2797            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2798            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2363  for (;;) Line 2804  for (;;)
2804        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2805          {          {
2806          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2807              {
2808              if (eptr >= md->end_subject)
2809                {
2810                SCHECK_PARTIAL();
2811                RRETURN(MATCH_NOMATCH);
2812                }
2813            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2814              }
2815          }          }
2816    
2817        if (min == max) continue;        if (min == max) continue;
# Line 2377  for (;;) Line 2825  for (;;)
2825            register unsigned int d;            register unsigned int d;
2826            for (fi = min;; fi++)            for (fi = min;; fi++)
2827              {              {
2828              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2829              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2830                if (fi >= max) RRETURN(MATCH_NOMATCH);
2831                if (eptr >= md->end_subject)
2832                  {
2833                  SCHECK_PARTIAL();
2834                  RRETURN(MATCH_NOMATCH);
2835                  }
2836              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2837              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2838              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2839              }              }
2840            }            }
2841          else          else
# Line 2391  for (;;) Line 2844  for (;;)
2844            {            {
2845            for (fi = min;; fi++)            for (fi = min;; fi++)
2846              {              {
2847              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2848              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2849              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
2850                if (eptr >= md->end_subject)
2851                  {
2852                  SCHECK_PARTIAL();
2853                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2854                  }
2855                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2856              }              }
2857            }            }
2858          /* Control never gets here */          /* Control never gets here */
# Line 2423  for (;;) Line 2881  for (;;)
2881          if (possessive) continue;          if (possessive) continue;
2882          for(;;)          for(;;)
2883              {              {
2884              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2885              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2886              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2887              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2441  for (;;) Line 2899  for (;;)
2899            if (possessive) continue;            if (possessive) continue;
2900            while (eptr >= pp)            while (eptr >= pp)
2901              {              {
2902              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2903              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2904              eptr--;              eptr--;
2905              }              }
# Line 2463  for (;;) Line 2921  for (;;)
2921          register unsigned int d;          register unsigned int d;
2922          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2923            {            {
2924              if (eptr >= md->end_subject)
2925                {
2926                SCHECK_PARTIAL();
2927                RRETURN(MATCH_NOMATCH);
2928                }
2929            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2930            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
2931            }            }
# Line 2472  for (;;) Line 2935  for (;;)
2935        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2936          {          {
2937          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2938              {
2939              if (eptr >= md->end_subject)
2940                {
2941                SCHECK_PARTIAL();
2942                RRETURN(MATCH_NOMATCH);
2943                }
2944            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2945              }
2946          }          }
2947    
2948        if (min == max) continue;        if (min == max) continue;
# Line 2486  for (;;) Line 2956  for (;;)
2956            register unsigned int d;            register unsigned int d;
2957            for (fi = min;; fi++)            for (fi = min;; fi++)
2958              {              {
2959              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2960              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2961              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2962              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
2963                  {
2964                  SCHECK_PARTIAL();
2965                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2966                  }
2967                GETCHARINC(d, eptr);
2968                if (fc == d) RRETURN(MATCH_NOMATCH);
2969              }              }
2970            }            }
2971          else          else
# Line 2499  for (;;) Line 2974  for (;;)
2974            {            {
2975            for (fi = min;; fi++)            for (fi = min;; fi++)
2976              {              {
2977              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2978              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2979              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
2980                if (eptr >= md->end_subject)
2981                  {
2982                  SCHECK_PARTIAL();
2983                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2984                  }
2985                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2986              }              }
2987            }            }
2988          /* Control never gets here */          /* Control never gets here */
# Line 2530  for (;;) Line 3010  for (;;)
3010            if (possessive) continue;            if (possessive) continue;
3011            for(;;)            for(;;)
3012              {              {
3013              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3014              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3015              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3016              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2548  for (;;) Line 3028  for (;;)
3028            if (possessive) continue;            if (possessive) continue;
3029            while (eptr >= pp)            while (eptr >= pp)
3030              {              {
3031              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3032              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3033              eptr--;              eptr--;
3034              }              }
# Line 2636  for (;;) Line 3116  for (;;)
3116    
3117      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3118      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
3119      (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  
3120      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
3121      and single-bytes. */      and single-bytes. */
3122    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3123      if (min > 0)      if (min > 0)
3124        {        {
3125  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2654  for (;;) Line 3131  for (;;)
3131            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3132            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3133              {              {
3134              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3135              GETCHARINC(c, eptr);                {
3136                  SCHECK_PARTIAL();
3137                  RRETURN(MATCH_NOMATCH);
3138                  }
3139                GETCHARINCTEST(c, eptr);
3140              }              }
3141            break;            break;
3142    
3143            case PT_LAMP:            case PT_LAMP:
3144            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3145              {              {
3146              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3147              GETCHARINC(c, eptr);                {
3148              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3149                  RRETURN(MATCH_NOMATCH);
3150                  }
3151                GETCHARINCTEST(c, eptr);
3152                prop_chartype = UCD_CHARTYPE(c);
3153              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3154                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3155                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2675  for (;;) Line 3160  for (;;)
3160            case PT_GC:            case PT_GC:
3161            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3162              {              {
3163              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3164              GETCHARINC(c, eptr);                {
3165              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3166                  RRETURN(MATCH_NOMATCH);
3167                  }
3168                GETCHARINCTEST(c, eptr);
3169                prop_category = UCD_CATEGORY(c);
3170              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3171                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3172              }              }
# Line 2686  for (;;) Line 3175  for (;;)
3175            case PT_PC:            case PT_PC:
3176            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3177              {              {
3178              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3179              GETCHARINC(c, eptr);                {
3180              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3181                  RRETURN(MATCH_NOMATCH);
3182                  }
3183                GETCHARINCTEST(c, eptr);
3184                prop_chartype = UCD_CHARTYPE(c);
3185              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3186                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3187              }              }
# Line 2697  for (;;) Line 3190  for (;;)
3190            case PT_SC:            case PT_SC:
3191            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3192              {              {
3193              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3194              GETCHARINC(c, eptr);                {
3195              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3196                  RRETURN(MATCH_NOMATCH);
3197                  }
3198                GETCHARINCTEST(c, eptr);
3199                prop_script = UCD_SCRIPT(c);
3200              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3201                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3202              }              }
# Line 2717  for (;;) Line 3214  for (;;)
3214          {          {
3215          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3216            {            {
3217              if (eptr >= md->end_subject)
3218                {
3219                SCHECK_PARTIAL();
3220                RRETURN(MATCH_NOMATCH);
3221                }
3222            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3223            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3224            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3225            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3226              {              {
3227              int len = 1;              int len = 1;
3228              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3229                {                else { GETCHARLEN(c, eptr, len); }
3230                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3231              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3232              eptr += len;              eptr += len;
3233              }              }
# Line 2745  for (;;) Line 3245  for (;;)
3245          case OP_ANY:          case OP_ANY:
3246          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3247            {            {
3248            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3249                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))              {
3250                SCHECK_PARTIAL();
3251              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3252                }
3253              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3254              eptr++;
3255              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3256              }
3257            break;
3258    
3259            case OP_ALLANY:
3260            for (i = 1; i <= min; i++)
3261              {
3262              if (eptr >= md->end_subject)
3263                {
3264                SCHECK_PARTIAL();
3265                RRETURN(MATCH_NOMATCH);
3266                }
3267            eptr++;            eptr++;
3268            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3269            }            }
3270          break;          break;
3271    
3272          case OP_ANYBYTE:          case OP_ANYBYTE:
3273            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3274          eptr += min;          eptr += min;
3275          break;          break;
3276    
3277          case OP_ANYNL:          case OP_ANYNL:
3278          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3279            {            {
3280            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3281                {
3282                SCHECK_PARTIAL();
3283                RRETURN(MATCH_NOMATCH);
3284                }
3285            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3286            switch(c)            switch(c)
3287              {              {
# Line 2768  for (;;) Line 3289  for (;;)
3289              case 0x000d:              case 0x000d:
3290              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3291              break;              break;
3292    
3293              case 0x000a:              case 0x000a:
3294                break;
3295    
3296              case 0x000b:              case 0x000b:
3297              case 0x000c:              case 0x000c:
3298              case 0x0085:              case 0x0085:
3299              case 0x2028:              case 0x2028:
3300              case 0x2029:              case 0x2029:
3301                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3302                break;
3303                }
3304              }
3305            break;
3306    
3307            case OP_NOT_HSPACE:
3308            for (i = 1; i <= min; i++)
3309              {
3310              if (eptr >= md->end_subject)
3311                {
3312                SCHECK_PARTIAL();
3313                RRETURN(MATCH_NOMATCH);
3314                }
3315              GETCHARINC(c, eptr);
3316              switch(c)
3317                {
3318                default: break;
3319                case 0x09:      /* HT */
3320                case 0x20:      /* SPACE */
3321                case 0xa0:      /* NBSP */
3322                case 0x1680:    /* OGHAM SPACE MARK */
3323                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3324                case 0x2000:    /* EN QUAD */
3325                case 0x2001:    /* EM QUAD */
3326                case 0x2002:    /* EN SPACE */
3327                case 0x2003:    /* EM SPACE */
3328                case 0x2004:    /* THREE-PER-EM SPACE */
3329                case 0x2005:    /* FOUR-PER-EM SPACE */
3330                case 0x2006:    /* SIX-PER-EM SPACE */
3331                case 0x2007:    /* FIGURE SPACE */
3332                case 0x2008:    /* PUNCTUATION SPACE */
3333                case 0x2009:    /* THIN SPACE */
3334                case 0x200A:    /* HAIR SPACE */
3335                case 0x202f:    /* NARROW NO-BREAK SPACE */
3336                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3337                case 0x3000:    /* IDEOGRAPHIC SPACE */
3338                RRETURN(MATCH_NOMATCH);
3339                }
3340              }
3341            break;
3342    
3343            case OP_HSPACE:
3344            for (i = 1; i <= min; i++)
3345              {
3346              if (eptr >= md->end_subject)
3347                {
3348                SCHECK_PARTIAL();
3349                RRETURN(MATCH_NOMATCH);
3350                }
3351              GETCHARINC(c, eptr);
3352              switch(c)
3353                {
3354                default: RRETURN(MATCH_NOMATCH);
3355                case 0x09:      /* HT */
3356                case 0x20:      /* SPACE */
3357                case 0xa0:      /* NBSP */
3358                case 0x1680:    /* OGHAM SPACE MARK */
3359                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3360                case 0x2000:    /* EN QUAD */
3361                case 0x2001:    /* EM QUAD */
3362                case 0x2002:    /* EN SPACE */
3363                case 0x2003:    /* EM SPACE */
3364                case 0x2004:    /* THREE-PER-EM SPACE */
3365                case 0x2005:    /* FOUR-PER-EM SPACE */
3366                case 0x2006:    /* SIX-PER-EM SPACE */
3367                case 0x2007:    /* FIGURE SPACE */
3368                case 0x2008:    /* PUNCTUATION SPACE */
3369                case 0x2009:    /* THIN SPACE */
3370                case 0x200A:    /* HAIR SPACE */
3371                case 0x202f:    /* NARROW NO-BREAK SPACE */
3372                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3373                case 0x3000:    /* IDEOGRAPHIC SPACE */
3374                break;
3375                }
3376              }
3377            break;
3378    
3379            case OP_NOT_VSPACE:
3380            for (i = 1; i <= min; i++)
3381              {
3382              if (eptr >= md->end_subject)
3383                {
3384                SCHECK_PARTIAL();
3385                RRETURN(MATCH_NOMATCH);
3386                }
3387              GETCHARINC(c, eptr);
3388              switch(c)
3389                {
3390                default: break;
3391                case 0x0a:      /* LF */
3392                case 0x0b:      /* VT */
3393                case 0x0c:      /* FF */
3394                case 0x0d:      /* CR */
3395                case 0x85:      /* NEL */
3396                case 0x2028:    /* LINE SEPARATOR */
3397                case 0x2029:    /* PARAGRAPH SEPARATOR */
3398                RRETURN(MATCH_NOMATCH);
3399                }
3400              }
3401            break;
3402    
3403            case OP_VSPACE:
3404            for (i = 1; i <= min; i++)
3405              {
3406              if (eptr >= md->end_subject)
3407                {
3408                SCHECK_PARTIAL();
3409                RRETURN(MATCH_NOMATCH);
3410                }
3411              GETCHARINC(c, eptr);
3412              switch(c)
3413                {
3414                default: RRETURN(MATCH_NOMATCH);
3415                case 0x0a:      /* LF */
3416                case 0x0b:      /* VT */
3417                case 0x0c:      /* FF */
3418                case 0x0d:      /* CR */
3419                case 0x85:      /* NEL */
3420                case 0x2028:    /* LINE SEPARATOR */
3421                case 0x2029:    /* PARAGRAPH SEPARATOR */
3422              break;              break;
3423              }              }
3424            }            }
# Line 2782  for (;;) Line 3427  for (;;)
3427          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3428          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3429            {            {
3430            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3431                {
3432                SCHECK_PARTIAL();
3433                RRETURN(MATCH_NOMATCH);
3434                }
3435            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3436            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3437              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 2792  for (;;) Line 3441  for (;;)
3441          case OP_DIGIT:          case OP_DIGIT:
3442          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3443            {            {
3444            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3445               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3446                SCHECK_PARTIAL();
3447                RRETURN(MATCH_NOMATCH);
3448                }
3449              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3450              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3451            /* 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 */
3452            }            }
# Line 2802  for (;;) Line 3455  for (;;)
3455          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3456          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3457            {            {
3458            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3459               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3460                SCHECK_PARTIAL();
3461              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3462            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3463              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3464                RRETURN(MATCH_NOMATCH);
3465              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3466            }            }
3467          break;          break;
3468    
3469          case OP_WHITESPACE:          case OP_WHITESPACE:
3470          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3471            {            {
3472            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3473               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3474                SCHECK_PARTIAL();
3475                RRETURN(MATCH_NOMATCH);
3476                }
3477              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3478              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3479            /* 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 */
3480            }            }
# Line 2823  for (;;) Line 3484  for (;;)
3484          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3485            {            {
3486            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3487               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3488              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3489            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3490            }            }
3491          break;          break;
3492    
3493          case OP_WORDCHAR:          case OP_WORDCHAR:
3494          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3495            {            {
3496            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3497               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3498                SCHECK_PARTIAL();
3499                RRETURN(MATCH_NOMATCH);
3500                }
3501              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3502              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3503            /* 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 */
3504            }            }
# Line 2847  for (;;) Line 3512  for (;;)
3512  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3513    
3514        /* 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
3515        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. */  
3516    
3517        switch(ctype)        switch(ctype)
3518          {          {
3519          case OP_ANY:          case OP_ANY:
3520          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3521            {            {
3522            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3523              {              {
3524              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3525              eptr++;              RRETURN(MATCH_NOMATCH);
3526              }              }
3527              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3528              eptr++;
3529            }            }
         else eptr += min;  
3530          break;          break;
3531    
3532          case OP_ANYBYTE:          case OP_ALLANY:
3533            if (eptr > md->end_subject - min)
3534              {
3535              SCHECK_PARTIAL();
3536              RRETURN(MATCH_NOMATCH);
3537              }
3538          eptr += min;          eptr += min;
3539          break;          break;
3540    
3541          /* Because of the CRLF case, we can't assume the minimum number of          case OP_ANYBYTE:
3542          bytes are present in this case. */          if (eptr > md->end_subject - min)
3543              {
3544              SCHECK_PARTIAL();
3545              RRETURN(MATCH_NOMATCH);
3546              }
3547            eptr += min;
3548            break;
3549    
3550          case OP_ANYNL:          case OP_ANYNL:
3551          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3552            {            {
3553            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3554                {
3555                SCHECK_PARTIAL();
3556                RRETURN(MATCH_NOMATCH);
3557                }
3558            switch(*eptr++)            switch(*eptr++)
3559              {              {
3560              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 2882  for (;;) Line 3562  for (;;)
3562              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3563              break;              break;
3564              case 0x000a:              case 0x000a:
3565                break;
3566    
3567              case 0x000b:              case 0x000b:
3568              case 0x000c:              case 0x000c:
3569              case 0x0085:              case 0x0085:
3570                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3571                break;
3572                }
3573              }
3574            break;
3575    
3576            case OP_NOT_HSPACE:
3577            for (i = 1; i <= min; i++)
3578              {
3579              if (eptr >= md->end_subject)
3580                {
3581                SCHECK_PARTIAL();
3582                RRETURN(MATCH_NOMATCH);
3583                }
3584              switch(*eptr++)
3585                {
3586                default: break;
3587                case 0x09:      /* HT */
3588                case 0x20:      /* SPACE */
3589                case 0xa0:      /* NBSP */
3590                RRETURN(MATCH_NOMATCH);
3591                }
3592              }
3593            break;
3594    
3595            case OP_HSPACE:
3596            for (i = 1; i <= min; i++)
3597              {
3598              if (eptr >= md->end_subject)
3599                {
3600                SCHECK_PARTIAL();
3601                RRETURN(MATCH_NOMATCH);
3602                }
3603              switch(*eptr++)
3604                {
3605                default: RRETURN(MATCH_NOMATCH);
3606                case 0x09:      /* HT */
3607                case 0x20:      /* SPACE */
3608                case 0xa0:      /* NBSP */
3609                break;
3610                }
3611              }
3612            break;
3613    
3614            case OP_NOT_VSPACE:
3615            for (i = 1; i <= min; i++)
3616              {
3617              if (eptr >= md->end_subject)
3618                {
3619                SCHECK_PARTIAL();
3620                RRETURN(MATCH_NOMATCH);
3621                }
3622              switch(*eptr++)
3623                {
3624                default: break;
3625                case 0x0a:      /* LF */
3626                case 0x0b:      /* VT */
3627                case 0x0c:      /* FF */
3628                case 0x0d:      /* CR */
3629                case 0x85:      /* NEL */
3630                RRETURN(MATCH_NOMATCH);
3631                }
3632              }
3633            break;
3634    
3635            case OP_VSPACE:
3636            for (i = 1; i <= min; i++)
3637              {
3638              if (eptr >= md->end_subject)
3639                {
3640                SCHECK_PARTIAL();
3641                RRETURN(MATCH_NOMATCH);
3642                }
3643              switch(*eptr++)
3644                {
3645                default: RRETURN(MATCH_NOMATCH);
3646                case 0x0a:      /* LF */
3647                case 0x0b:      /* VT */
3648                case 0x0c:      /* FF */
3649                case 0x0d:      /* CR */
3650                case 0x85:      /* NEL */
3651              break;              break;
3652              }              }
3653            }            }
# Line 2892  for (;;) Line 3655  for (;;)
3655    
3656          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3657          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3658              {
3659              if (eptr >= md->end_subject)
3660                {
3661                SCHECK_PARTIAL();
3662                RRETURN(MATCH_NOMATCH);
3663                }
3664            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3665              }
3666          break;          break;
3667    
3668          case OP_DIGIT:          case OP_DIGIT:
3669          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3670              {
3671              if (eptr >= md->end_subject)
3672                {
3673                SCHECK_PARTIAL();
3674                RRETURN(MATCH_NOMATCH);
3675                }
3676            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3677              }
3678          break;          break;
3679    
3680          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3681          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3682              {
3683              if (eptr >= md->end_subject)
3684                {
3685                SCHECK_PARTIAL();
3686                RRETURN(MATCH_NOMATCH);
3687                }
3688            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3689              }
3690          break;          break;
3691    
3692          case OP_WHITESPACE:          case OP_WHITESPACE:
3693          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3694              {
3695              if (eptr >= md->end_subject)
3696                {
3697                SCHECK_PARTIAL();
3698                RRETURN(MATCH_NOMATCH);
3699                }
3700            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3701              }
3702          break;          break;
3703    
3704          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3705          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3706              {
3707              if (eptr >= md->end_subject)
3708                {
3709                SCHECK_PARTIAL();
3710                RRETURN(MATCH_NOMATCH);
3711                }
3712            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3713              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3714              }
3715          break;          break;
3716    
3717          case OP_WORDCHAR:          case OP_WORDCHAR:
3718          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3719              {
3720              if (eptr >= md->end_subject)
3721                {
3722                SCHECK_PARTIAL();
3723                RRETURN(MATCH_NOMATCH);
3724                }
3725            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3726              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3727              }
3728          break;          break;
3729    
3730          default:          default:
# Line 2945  for (;;) Line 3750  for (;;)
3750            case PT_ANY:            case PT_ANY:
3751            for (fi = min;; fi++)            for (fi = min;; fi++)
3752              {              {
3753              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3754              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3755              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3756                if (eptr >= md->end_subject)
3757                  {
3758                  SCHECK_PARTIAL();
3759                  RRETURN(MATCH_NOMATCH);
3760                  }
3761              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3762              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3763              }              }
# Line 2956  for (;;) Line 3766  for (;;)
3766            case PT_LAMP:            case PT_LAMP:
3767            for (fi = min;; fi++)            for (fi = min;; fi++)
3768              {              {
3769              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3770              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3771              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3772                if (eptr >= md->end_subject)
3773                  {
3774                  SCHECK_PARTIAL();
3775                  RRETURN(MATCH_NOMATCH);
3776                  }
3777              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3778              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3779              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3780                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3781                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2971  for (;;) Line 3786  for (;;)
3786            case PT_GC:            case PT_GC:
3787            for (fi = min;; fi++)            for (fi = min;; fi++)
3788              {              {
3789              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3790              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3791              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3792                if (eptr >= md->end_subject)
3793                  {
3794                  SCHECK_PARTIAL();
3795                  RRETURN(MATCH_NOMATCH);
3796                  }
3797              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3798              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3799              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3800                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3801              }              }
# Line 2984  for (;;) Line 3804  for (;;)
3804            case PT_PC:            case PT_PC:
3805            for (fi = min;; fi++)            for (fi = min;; fi++)
3806              {              {
3807              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3808              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3809              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3810                if (eptr >= md->end_subject)
3811                  {
3812                  SCHECK_PARTIAL();
3813                  RRETURN(MATCH_NOMATCH);
3814                  }
3815              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3816              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3817              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3818                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3819              }              }
# Line 2997  for (;;) Line 3822  for (;;)
3822            case PT_SC:            case PT_SC:
3823            for (fi = min;; fi++)            for (fi = min;; fi++)
3824              {              {
3825              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3826              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3827              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3828                if (eptr >= md->end_subject)
3829                  {
3830                  SCHECK_PARTIAL();
3831                  RRETURN(MATCH_NOMATCH);
3832                  }
3833              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3834              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3835              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3836                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3837              }              }
# Line 3019  for (;;) Line 3849  for (;;)
3849          {          {
3850          for (fi = min;; fi++)          for (fi = min;; fi++)
3851            {            {
3852            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3853            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3854            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3855              if (eptr >= md->end_subject)
3856                {
3857                SCHECK_PARTIAL();
3858                RRETURN(MATCH_NOMATCH);
3859                }
3860            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3861            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3862            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3863            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3864              {              {
3865              int len = 1;              int len = 1;
3866              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3867                {                else { GETCHARLEN(c, eptr, len); }
3868                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3869              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3870              eptr += len;              eptr += len;
3871              }              }
# Line 3048  for (;;) Line 3881  for (;;)
3881          {          {
3882          for (fi = min;; fi++)          for (fi = min;; fi++)
3883            {            {
3884            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3885            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3886            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
3887                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&            if (eptr >= md->end_subject)
3888                  IS_NEWLINE(eptr)))              {
3889                SCHECK_PARTIAL();
3890                RRETURN(MATCH_NOMATCH);
3891                }
3892              if (ctype == OP_ANY && IS_NEWLINE(eptr))
3893              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
3894            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3895            switch(ctype)            switch(ctype)
3896              {              {
3897              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3898              break;              case OP_ALLANY:
   
3899              case OP_ANYBYTE:              case OP_ANYBYTE:
3900              break;              break;
3901    
# Line 3072  for (;;) Line 3907  for (;;)
3907                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3908                break;                break;
3909                case 0x000a:                case 0x000a:
3910                  break;
3911    
3912                case 0x000b:                case 0x000b:
3913                case 0x000c:                case 0x000c:
3914                case 0x0085:                case 0x0085:
3915                case 0x2028:                case 0x2028:
3916                case 0x2029:                case 0x2029:
3917                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3918                  break;
3919                  }
3920                break;
3921    
3922                case OP_NOT_HSPACE:
3923                switch(c)
3924                  {
3925                  default: break;
3926                  case 0x09:      /* HT */
3927                  case 0x20:      /* SPACE */
3928                  case 0xa0:      /* NBSP */
3929                  case 0x1680:    /* OGHAM SPACE MARK */
3930                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3931                  case 0x2000:    /* EN QUAD */
3932                  case 0x2001:    /* EM QUAD */
3933                  case 0x2002:    /* EN SPACE */
3934                  case 0x2003:    /* EM SPACE */
3935                  case 0x2004:    /* THREE-PER-EM SPACE */
3936                  case 0x2005:    /* FOUR-PER-EM SPACE */
3937                  case 0x2006:    /* SIX-PER-EM SPACE */
3938                  case 0x2007:    /* FIGURE SPACE */
3939                  case 0x2008:    /* PUNCTUATION SPACE */
3940                  case 0x2009:    /* THIN SPACE */
3941                  case 0x200A:    /* HAIR SPACE */
3942                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3943                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3944                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3945                  RRETURN(MATCH_NOMATCH);
3946                  }
3947                break;
3948    
3949                case OP_HSPACE:
3950                switch(c)
3951                  {
3952                  default: RRETURN(MATCH_NOMATCH);
3953                  case 0x09:      /* HT */
3954                  case 0x20:      /* SPACE */
3955                  case 0xa0:      /* NBSP */
3956                  case 0x1680:    /* OGHAM SPACE MARK */
3957                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3958                  case 0x2000:    /* EN QUAD */
3959                  case 0x2001:    /* EM QUAD */
3960                  case 0x2002:    /* EN SPACE */
3961                  case 0x2003:    /* EM SPACE */
3962                  case 0x2004:    /* THREE-PER-EM SPACE */
3963                  case 0x2005:    /* FOUR-PER-EM SPACE */
3964                  case 0x2006:    /* SIX-PER-EM SPACE */
3965                  case 0x2007:    /* FIGURE SPACE */
3966                  case 0x2008:    /* PUNCTUATION SPACE */
3967                  case 0x2009:    /* THIN SPACE */
3968                  case 0x200A:    /* HAIR SPACE */
3969                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3970                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3971                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3972                  break;
3973                  }
3974                break;
3975    
3976                case OP_NOT_VSPACE:
3977                switch(c)
3978                  {
3979                  default: break;
3980                  case 0x0a:      /* LF */
3981                  case 0x0b:      /* VT */
3982                  case 0x0c:      /* FF */
3983                  case 0x0d:      /* CR */
3984                  case 0x85:      /* NEL */
3985                  case 0x2028:    /* LINE SEPARATOR */
3986                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3987                  RRETURN(MATCH_NOMATCH);
3988                  }
3989                break;
3990    
3991                case OP_VSPACE:
3992                switch(c)
3993                  {
3994                  default: RRETURN(MATCH_NOMATCH);
3995                  case 0x0a:      /* LF */
3996                  case 0x0b:      /* VT */
3997                  case 0x0c:      /* FF */
3998                  case 0x0d:      /* CR */
3999                  case 0x85:      /* NEL */
4000                  case 0x2028:    /* LINE SEPARATOR */
4001                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4002                break;                break;
4003                }                }
4004              break;              break;
# Line 3122  for (;;) Line 4044  for (;;)
4044          {          {
4045          for (fi = min;; fi++)          for (fi = min;; fi++)
4046            {            {
4047            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4048            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4049            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4050                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))            if (eptr >= md->end_subject)
4051                {
4052                SCHECK_PARTIAL();
4053                RRETURN(MATCH_NOMATCH);
4054                }
4055              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4056              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4057            c = *eptr++;            c = *eptr++;
4058            switch(ctype)            switch(ctype)
4059              {              {
4060              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
4061              break;              case OP_ALLANY:
   
4062              case OP_ANYBYTE:              case OP_ANYBYTE:
4063              break;              break;
4064    
# Line 3144  for (;;) Line 4069  for (;;)
4069                case 0x000d:                case 0x000d:
4070                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4071                break;                break;
4072    
4073                case 0x000a:                case 0x000a:
4074                  break;
4075    
4076                case 0x000b:                case 0x000b:
4077                case 0x000c:                case 0x000c:
4078                case 0x0085:                case 0x0085:
4079                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4080                  break;
4081                  }
4082                break;
4083    
4084                case OP_NOT_HSPACE:
4085                switch(c)
4086                  {
4087                  default: break;
4088                  case 0x09:      /* HT */
4089                  case 0x20:      /* SPACE */
4090                  case 0xa0:      /* NBSP */
4091                  RRETURN(MATCH_NOMATCH);
4092                  }
4093                break;
4094    
4095                case OP_HSPACE:
4096                switch(c)
4097                  {
4098                  default: RRETURN(MATCH_NOMATCH);
4099                  case 0x09:      /* HT */
4100                  case 0x20:      /* SPACE */
4101                  case 0xa0:      /* NBSP */
4102                  break;
4103                  }
4104                break;
4105    
4106                case OP_NOT_VSPACE:
4107                switch(c)
4108                  {
4109                  default: break;
4110                  case 0x0a:      /* LF */
4111                  case 0x0b:      /* VT */
4112                  case 0x0c:      /* FF */
4113                  case 0x0d:      /* CR */
4114                  case 0x85:      /* NEL */
4115                  RRETURN(MATCH_NOMATCH);
4116                  }
4117                break;
4118    
4119                case OP_VSPACE:
4120                switch(c)
4121                  {
4122                  default: RRETURN(MATCH_NOMATCH);
4123                  case 0x0a:      /* LF */
4124                  case 0x0b:      /* VT */
4125                  case 0x0c:      /* FF */
4126                  case 0x0d:      /* CR */
4127                  case 0x85:      /* NEL */
4128                break;                break;
4129                }                }
4130              break;              break;
# Line 3214  for (;;) Line 4191  for (;;)
4191              int len = 1;              int len = 1;
4192              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4193              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4194              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4195              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4196                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
4197                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3229  for (;;) Line 4206  for (;;)
4206              int len = 1;              int len = 1;
4207              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4208              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4209              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4210              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4211                break;                break;
4212              eptr+= len;              eptr+= len;
# Line 3242  for (;;) Line 4219  for (;;)
4219              int len = 1;              int len = 1;
4220              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4221              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4222              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4223              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4224                break;                break;
4225              eptr+= len;              eptr+= len;
# Line 3255  for (;;) Line 4232  for (;;)
4232              int len = 1;              int len = 1;
4233              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4234              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4235              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
4236              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
4237                break;                break;
4238              eptr+= len;              eptr+= len;
# Line 3268  for (;;) Line 4245  for (;;)
4245          if (possessive) continue;          if (possessive) continue;
4246          for(;;)          for(;;)
4247            {            {
4248            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
4249            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4250            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4251            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
4252            }            }
4253          }          }
4254    
# Line 3284  for (;;) Line 4261  for (;;)
4261            {            {
4262            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
4263            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4264            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
4265            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
4266            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4267              {              {
# Line 3293  for (;;) Line 4270  for (;;)
4270                {                {
4271                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
4272                }                }
4273              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4274              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4275              eptr += len;              eptr += len;
4276              }              }
# Line 3304  for (;;) Line 4281  for (;;)
4281          if (possessive) continue;          if (possessive) continue;
4282          for(;;)          for(;;)
4283            {            {
4284            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
4285            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4286            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4287            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
4288              {              {
4289              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
4290              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
4291                {                {
4292                  BACKCHAR(eptr);
4293                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
4294                }                }
4295              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4296              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4297              eptr--;              eptr--;
4298              }              }
# Line 3333  for (;;) Line 4310  for (;;)
4310          switch(ctype)          switch(ctype)
4311            {            {
4312            case OP_ANY:            case OP_ANY:
   
           /* Special code is required for UTF8, but when the maximum is  
           unlimited we don't need it, so we repeat the non-UTF8 code. This is  
           probably worth it, because .* is quite a common idiom. */  
   
4313            if (max < INT_MAX)            if (max < INT_MAX)
4314              {              {
4315              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
               {  
               for (i = min; i < max; i++)  
                 {  
                 if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
               }  
             else  
4316                {                {
4317                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4318                  {                eptr++;
4319                  if (eptr >= md->end_subject) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
                 }  
4320                }                }
4321              }              }
4322    
# Line 3364  for (;;) Line 4324  for (;;)
4324    
4325            else            else
4326              {              {
4327              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
4328                {                {
4329                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4330                  {                eptr++;
4331                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
4332                }                }
4333              else              }
4334              break;
4335    
4336              case OP_ALLANY:
4337              if (max < INT_MAX)
4338                {
4339                for (i = min; i < max; i++)
4340                {                {
4341                c = max - min;                if (eptr >= md->end_subject) break;
4342                if (c > (unsigned int)(md->end_subject - eptr))                eptr++;
4343                  c = md->end_subject - eptr;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
               eptr += c;  
4344                }                }
4345              }              }
4346              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
4347            break;            break;
4348    
4349            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3405  for (;;) Line 4368  for (;;)
4368                }                }
4369              else              else
4370                {                {
4371                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
4372                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
4373                       (c != 0x000b && c != 0x000c &&
4374                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
4375                  break;                  break;
4376                eptr += len;                eptr += len;
4377                }                }
4378              }              }
4379            break;            break;
4380    
4381              case OP_NOT_HSPACE:
4382              case OP_HSPACE:
4383              for (i = min; i < max; i++)
4384                {
4385                BOOL gotspace;
4386                int len = 1;
4387                if (eptr >= md->end_subject) break;
4388                GETCHARLEN(c, eptr, len);
4389                switch(c)
4390                  {
4391                  default: gotspace = FALSE; break;
4392                  case 0x09:      /* HT */
4393                  case 0x20:      /* SPACE */
4394                  case 0xa0:      /* NBSP */
4395                  case 0x1680:    /* OGHAM SPACE MARK */
4396                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4397                  case 0x2000:    /* EN QUAD */
4398                  case 0x2001:    /* EM QUAD */
4399                  case 0x2002:    /* EN SPACE */
4400                  case 0x2003:    /* EM SPACE */
4401                  case 0x2004:    /* THREE-PER-EM SPACE */
4402                  case 0x2005:    /* FOUR-PER-EM SPACE */
4403                  case 0x2006:    /* SIX-PER-EM SPACE */
4404                  case 0x2007:    /* FIGURE SPACE */
4405                  case 0x2008:    /* PUNCTUATION SPACE */
4406                  case 0x2009:    /* THIN SPACE */
4407                  case 0x200A:    /* HAIR SPACE */
4408                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4409                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4410                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4411                  gotspace = TRUE;
4412                  break;
4413                  }
4414                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
4415                eptr += len;
4416                }
4417              break;
4418    
4419              case OP_NOT_VSPACE:
4420              case OP_VSPACE:
4421              for (i = min; i < max; i++)
4422                {
4423                BOOL gotspace;
4424                int len = 1;
4425                if (eptr >= md->end_subject) break;
4426                GETCHARLEN(c, eptr, len);
4427                switch(c)
4428                  {
4429                  default: gotspace = FALSE; break;
4430                  case 0x0a:      /* LF */
4431                  case 0x0b:      /* VT */
4432                  case 0x0c:      /* FF */
4433                  case 0x0d:      /* CR */
4434                  case 0x85:      /* NEL */
4435                  case 0x2028:    /* LINE SEPARATOR */
4436                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4437                  gotspace = TRUE;
4438                  break;
4439                  }
4440                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4441                eptr += len;
4442                }
4443              break;
4444    
4445            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4446            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4447              {              {
# Line 3488  for (;;) Line 4517  for (;;)
4517          if (possessive) continue;          if (possessive) continue;
4518          for(;;)          for(;;)
4519            {            {
4520            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4521            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4522            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4523            BACKCHAR(eptr);            BACKCHAR(eptr);
4524            }            }
4525          }          }
4526        else        else
4527  #endif  #endif  /* SUPPORT_UTF8 */
4528    
4529        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4530          {          {
4531          switch(ctype)          switch(ctype)
4532            {            {
4533            case OP_ANY:            case OP_ANY:
4534            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4535              {              {
4536              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4537                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4538              }              }
4539            /* For DOTALL case, fall through and treat as \C */            break;
4540    
4541              case OP_ALLANY:
4542            case OP_ANYBYTE:            case OP_ANYBYTE:
4543            c = max - min;            c = max - min;
4544            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 3532  for (;;) Line 4558  for (;;)
4558                }                }
4559              else              else
4560                {                {
4561                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4562                      (md->bsr_anycrlf ||
4563                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4564                  break;                  break;
4565                eptr++;                eptr++;
4566                }                }
4567              }              }
4568            break;            break;
4569    
4570              case OP_NOT_HSPACE:
4571              for (i = min; i < max; i++)
4572                {
4573                if (eptr >= md->end_subject) break;
4574                c = *eptr;
4575                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4576                eptr++;
4577                }
4578              break;
4579    
4580              case OP_HSPACE:
4581              for (i = min; i < max; i++)
4582                {
4583                if (eptr >= md->end_subject) break;
4584                c = *eptr;
4585                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4586                eptr++;
4587                }
4588              break;
4589    
4590              case OP_NOT_VSPACE:
4591              for (i = min; i < max; i++)
4592                {
4593                if (eptr >= md->end_subject) break;
4594                c = *eptr;
4595                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4596                  break;
4597                eptr++;
4598                }
4599              break;
4600    
4601              case OP_VSPACE:
4602              for (i = min; i < max; i++)
4603                {
4604                if (eptr >= md->end_subject) break;
4605                c = *eptr;
4606                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4607                  break;
4608                eptr++;
4609                }
4610              break;
4611    
4612            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4613            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4614              {              {
# Line 3602  for (;;) Line 4672  for (;;)
4672          if (possessive) continue;          if (possessive) continue;
4673          while (eptr >= pp)          while (eptr >= pp)
4674            {            {
4675            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4676            eptr--;            eptr--;
4677            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4678            }            }
# Line 3628  for (;;) Line 4698  for (;;)
4698    
4699    }             /* End of main loop */    }             /* End of main loop */
4700  /* Control never reaches here */  /* Control never reaches here */
4701    
4702    
4703    /* When compiling to use the heap rather than the stack for recursive calls to
4704    match(), the RRETURN() macro jumps here. The number that is saved in
4705    frame->Xwhere indicates which label we actually want to return to. */
4706    
4707    #ifdef NO_RECURSE
4708    #define LBL(val) case val: goto L_RM##val;
4709    HEAP_RETURN:
4710    switch (frame->Xwhere)
4711      {
4712      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4713      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4714      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4715      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4716      LBL(53) LBL(54)
4717    #ifdef SUPPORT_UTF8
4718      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4719      LBL(32) LBL(34) LBL(42) LBL(46)
4720    #ifdef SUPPORT_UCP
4721      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4722    #endif  /* SUPPORT_UCP */
4723    #endif  /* SUPPORT_UTF8 */
4724      default:
4725      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4726      return PCRE_ERROR_INTERNAL;
4727      }
4728    #undef LBL
4729    #endif  /* NO_RECURSE */
4730  }  }
4731    
4732    
# Line 3640  Undefine all the macros that were define Line 4739  Undefine all the macros that were define
4739  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4740  #undef eptr  #undef eptr
4741  #undef ecode  #undef ecode
4742    #undef mstart
4743  #undef offset_top  #undef offset_top
4744  #undef ims  #undef ims
4745  #undef eptrb  #undef eptrb
# Line 3712  Returns:          > 0 => success; value Line 4812  Returns:          > 0 => success; value
4812                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4813  */  */
4814    
4815  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4816  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4817    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4818    int offsetcount)    int offsetcount)
# Line 3736  const uschar *tables; Line 4836  const uschar *tables;
4836  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4837  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4838  USPTR end_subject;  USPTR end_subject;
4839    USPTR start_partial = NULL;
4840  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
 eptrblock eptrchain[EPTR_WORK_SIZE];  
4841    
4842  pcre_study_data internal_study;  pcre_study_data internal_study;
4843  const pcre_study_data *study;  const pcre_study_data *study;
# Line 3800  if (re->magic_number != MAGIC_NUMBER) Line 4900  if (re->magic_number != MAGIC_NUMBER)
4900  /* Set up other data */  /* Set up other data */
4901    
4902  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4903  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4904  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4905    
4906  /* The code starts after the real_pcre block and the capture name table. */  /* The code starts after the real_pcre block and the capture name table. */
# Line 3815  end_subject = md->end_subject; Line 4915  end_subject = md->end_subject;
4915    
4916  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4917  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4918    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4919    
4920  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4921  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
4922  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
4923  md->partial = (options & PCRE_PARTIAL) != 0;  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
4924                  ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
4925  md->hitend = FALSE;  md->hitend = FALSE;
4926    
4927  md->recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
 md->eptrchain = eptrchain;              /* Make workspace generally available */  
4928    
4929  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4930  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4931    
4932    /* Handle different \R options. */
4933    
4934    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4935      {
4936      case 0:
4937      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4938        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4939      else
4940    #ifdef BSR_ANYCRLF
4941      md->bsr_anycrlf = TRUE;
4942    #else
4943      md->bsr_anycrlf = FALSE;
4944    #endif
4945      break;
4946    
4947      case PCRE_BSR_ANYCRLF:
4948      md->bsr_anycrlf = TRUE;
4949      break;
4950    
4951      case PCRE_BSR_UNICODE:
4952      md->bsr_anycrlf = FALSE;
4953      break;
4954    
4955      default: return PCRE_ERROR_BADNEWLINE;
4956      }
4957    
4958  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4959  nothing is set at run time, whatever was used at compile time applies. */  nothing is set at run time, whatever was used at compile time applies. */
4960    
4961  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4962         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4963    {    {
4964    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4965    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4966    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4967    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
4968         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4969    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
4970      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4971    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
4972    }    }
4973    
4974  if (newline < 0)  if (newline == -2)
4975      {
4976      md->nltype = NLTYPE_ANYCRLF;
4977      }
4978    else if (newline < 0)
4979    {    {
4980    md->nltype = NLTYPE_ANY;    md->nltype = NLTYPE_ANY;
4981    }    }
# Line 3863  else Line 4995  else
4995      }      }
4996    }    }
4997    
4998  /* Partial matching is supported only for a restricted set of regexes at the  /* Partial matching was originally supported only for a restricted set of
4999  moment. */  regexes; from release 8.00 there are no restrictions, but the bits are still
5000    defined (though never set). So there's no harm in leaving this code. */
5001    
5002  if (md->partial && (re->options & PCRE_NOPARTIAL) != 0)  if (md->partial && (re->flags & PCRE_NOPARTIAL) != 0)
5003    return PCRE_ERROR_BADPARTIAL;    return PCRE_ERROR_BADPARTIAL;
5004    
5005  /* Check a UTF-8 string if required. Unfortunately there's no way of passing  /* Check a UTF-8 string if required. Unfortunately there's no way of passing
# Line 3875  back the character offset. */ Line 5008  back the character offset. */
5008  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
5009  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)  if (utf8 && (options & PCRE_NO_UTF8_CHECK) == 0)
5010    {    {
5011    if (_pcre_valid_utf8((uschar *)subject, length) >= 0)    if (_pcre_valid_utf8((USPTR)subject, length) >= 0)
5012      return PCRE_ERROR_BADUTF8;      return PCRE_ERROR_BADUTF8;
5013    if (start_offset > 0 && start_offset < length)    if (start_offset > 0 && start_offset < length)
5014      {      {
5015      int tb = ((uschar *)subject)[start_offset];      int tb = ((USPTR)subject)[start_offset];
5016      if (tb > 127)      if (tb > 127)
5017        {        {
5018        tb &= 0xc0;        tb &= 0xc0;
# Line 3943  studied, there may be a bitmap of possib Line 5076  studied, there may be a bitmap of possib
5076    
5077  if (!anchored)  if (!anchored)
5078    {    {
5079    if ((re->options & PCRE_FIRSTSET) != 0)    if ((re->flags & PCRE_FIRSTSET) != 0)
5080      {      {
5081      first_byte = re->first_byte & 255;      first_byte = re->first_byte & 255;
5082      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)      if ((first_byte_caseless = ((re->first_byte & REQ_CASELESS) != 0)) == TRUE)
# Line 3958  if (!anchored) Line 5091  if (!anchored)
5091  /* For anchored or unanchored matches, there may be a "last known required  /* For anchored or unanchored matches, there may be a "last known required
5092  character" set. */  character" set. */
5093    
5094  if ((re->options & PCRE_REQCHSET) != 0)  if ((re->flags & PCRE_REQCHSET) != 0)
5095    {    {
5096    req_byte = re->req_byte & 255;    req_byte = re->req_byte & 255;
5097    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;    req_byte_caseless = (re->req_byte & REQ_CASELESS) != 0;
# Line 3974  the loop runs just once. */ Line 5107  the loop runs just once. */
5107  for(;;)  for(;;)
5108    {    {
5109    USPTR save_end_subject = end_subject;    USPTR save_end_subject = end_subject;