/[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 428 by ph10, Mon Aug 31 17:10:26 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 && 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 885  for (;;) Line 1042  for (;;)
1042        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1043        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1044        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1045        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1046        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1047        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1048        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 947  for (;;) Line 1104  for (;;)
1104    
1105        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1106              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1107        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1108        md->start_match = eptr;        mstart = eptr;
1109    
1110        /* 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
1111        restore the offset and recursion data. */        restore the offset and recursion data. */
# Line 957  for (;;) Line 1114  for (;;)
1114        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;        flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1115        do        do
1116          {          {
1117          RMATCH(rrc, eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1118            md, ims, eptrb, flags);            md, ims, eptrb, flags, RM6);
1119          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1120            {            {
1121            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 967  for (;;) Line 1124  for (;;)
1124              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1125            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1126            }            }
1127          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1128            {            {
1129            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1130              if (new_recursive.offset_save != stacksave)
1131                (pcre_free)(new_recursive.offset_save);
1132            RRETURN(rrc);            RRETURN(rrc);
1133            }            }
1134    
# Line 1001  for (;;) Line 1160  for (;;)
1160    
1161      do      do
1162        {        {
1163        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);  
1164        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1165        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1166        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1167        }        }
1168      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1047  for (;;) Line 1205  for (;;)
1205    
1206      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1207        {        {
1208        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);
1209        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1210        ecode = prev;        ecode = prev;
1211        flags = match_tail_recursed;        flags = 0;
1212        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1213        }        }
1214      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1215        {        {
1216        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_cbegroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1217        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1218        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1219        flags = match_tail_recursed;        flags = 0;
1220        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1221        }        }
1222      /* Control never gets here */      /* Control never gets here */
# Line 1070  for (;;) Line 1228  for (;;)
1228      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1229      break;      break;
1230    
1231      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1232      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
1233      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
1234      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
1235      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1236    
1237      case OP_BRAZERO:      case OP_BRAZERO:
1238        {        {
1239        next = ecode+1;        next = ecode+1;
1240        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1241        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1242        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1243        ecode = next + 1 + LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
# Line 1090  for (;;) Line 1248  for (;;)
1248        {        {
1249        next = ecode+1;        next = ecode+1;
1250        do next += GET(next, 1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1251        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);
1252        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1253        ecode++;        ecode++;
1254        }        }
1255      break;      break;
1256    
1257        case OP_SKIPZERO:
1258          {
1259          next = ecode+1;
1260          do next += GET(next,1); while (*next == OP_ALT);
1261          ecode = next + 1 + LINK_SIZE;
1262          }
1263        break;
1264    
1265      /* End of a group, repeated or non-repeating. */      /* End of a group, repeated or non-repeating. */
1266    
1267      case OP_KET:      case OP_KET:
# Line 1160  for (;;) Line 1326  for (;;)
1326          recursion_info *rec = md->recursive;          recursion_info *rec = md->recursive;
1327          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1328          md->recursive = rec->prevrec;          md->recursive = rec->prevrec;
1329          md->start_match = rec->save_start;          mstart = rec->save_start;
1330          memcpy(md->offset_vector, rec->offset_save,          memcpy(md->offset_vector, rec->offset_save,
1331            rec->saved_max * sizeof(int));            rec->saved_max * sizeof(int));
1332          ecode = rec->after_call;          ecode = rec->after_call;
# Line 1189  for (;;) Line 1355  for (;;)
1355    
1356      /* 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
1357      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
1358      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1359        unlimited repeat of a group that can match an empty string. */
1360    
1361      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1362    
1363      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1364        {        {
1365        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);
1366        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1367          if (flags != 0)    /* Could match an empty string */
1368            {
1369            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1370            RRETURN(rrc);
1371            }
1372        ecode = prev;        ecode = prev;
       flags |= match_tail_recursed;  
1373        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1374        }        }
1375      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1376        {        {
1377        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, flags);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1378        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1379        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1380        flags = match_tail_recursed;        flags = 0;
1381        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1382        }        }
1383      /* Control never gets here */      /* Control never gets here */
# Line 1239  for (;;) Line 1410  for (;;)
1410      ecode++;      ecode++;
1411      break;      break;
1412    
1413        /* Reset the start of match point */
1414    
1415        case OP_SET_SOM:
1416        mstart = eptr;
1417        ecode++;
1418        break;
1419    
1420      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1421      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. */
1422    
# Line 1297  for (;;) Line 1475  for (;;)
1475          {          {
1476          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1477            {            {
1478            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1479            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1480            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1481            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1482            }            }
1483          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1484              {
1485              SCHECK_PARTIAL();
1486              cur_is_word = FALSE;
1487              }
1488            else
1489            {            {
1490            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1491            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 1494  for (;;)
1494        else        else
1495  #endif  #endif
1496    
1497        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1498    
1499          {          {
1500          prev_is_word = (eptr != md->start_subject) &&          prev_is_word = (eptr != md->start_subject) &&
1501            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1502          cur_is_word = (eptr < md->end_subject) &&          if (eptr >= md->end_subject)
1503            ((md->ctypes[*eptr] & ctype_word) != 0);            {
1504              SCHECK_PARTIAL();
1505              cur_is_word = FALSE;
1506              }
1507            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1508          }          }
1509    
1510        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1331  for (;;) Line 1518  for (;;)
1518      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1519    
1520      case OP_ANY:      case OP_ANY:
1521      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1522        /* Fall through */
1523    
1524        case OP_ALLANY:
1525        if (eptr++ >= md->end_subject)
1526        {        {
1527        if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);        SCHECK_PARTIAL();
1528        }        RRETURN(MATCH_NOMATCH);
1529      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);        }
1530      if (utf8)      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1531      ecode++;      ecode++;
1532      break;      break;
1533    
# Line 1345  for (;;) Line 1535  for (;;)
1535      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1536    
1537      case OP_ANYBYTE:      case OP_ANYBYTE:
1538      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1539          {
1540          SCHECK_PARTIAL();
1541          RRETURN(MATCH_NOMATCH);
1542          }
1543      ecode++;      ecode++;
1544      break;      break;
1545    
1546      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1547      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1548          {
1549          SCHECK_PARTIAL();
1550          RRETURN(MATCH_NOMATCH);
1551          }
1552      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1553      if (      if (
1554  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1363  for (;;) Line 1561  for (;;)
1561      break;      break;
1562    
1563      case OP_DIGIT:      case OP_DIGIT:
1564      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1565          {
1566          SCHECK_PARTIAL();
1567          RRETURN(MATCH_NOMATCH);
1568          }
1569      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1570      if (      if (
1571  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1376  for (;;) Line 1578  for (;;)
1578      break;      break;
1579    
1580      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1581      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1582          {
1583          SCHECK_PARTIAL();
1584          RRETURN(MATCH_NOMATCH);
1585          }
1586      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1587      if (      if (
1588  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1389  for (;;) Line 1595  for (;;)
1595      break;      break;
1596    
1597      case OP_WHITESPACE:      case OP_WHITESPACE:
1598      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1599          {
1600          SCHECK_PARTIAL();
1601          RRETURN(MATCH_NOMATCH);
1602          }
1603      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1604      if (      if (
1605  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1402  for (;;) Line 1612  for (;;)
1612      break;      break;
1613    
1614      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1615      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1616          {
1617          SCHECK_PARTIAL();
1618          RRETURN(MATCH_NOMATCH);
1619          }
1620      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1621      if (      if (
1622  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1415  for (;;) Line 1629  for (;;)
1629      break;      break;
1630    
1631      case OP_WORDCHAR:      case OP_WORDCHAR:
1632      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1633          {
1634          SCHECK_PARTIAL();
1635          RRETURN(MATCH_NOMATCH);
1636          }
1637      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1638      if (      if (
1639  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1428  for (;;) Line 1646  for (;;)
1646      break;      break;
1647    
1648      case OP_ANYNL:      case OP_ANYNL:
1649      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1650          {
1651          SCHECK_PARTIAL();
1652          RRETURN(MATCH_NOMATCH);
1653          }
1654      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1655      switch(c)      switch(c)
1656        {        {
# Line 1436  for (;;) Line 1658  for (;;)
1658        case 0x000d:        case 0x000d:
1659        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1660        break;        break;
1661    
1662        case 0x000a:        case 0x000a:
1663          break;
1664    
1665        case 0x000b:        case 0x000b:
1666        case 0x000c:        case 0x000c:
1667        case 0x0085:        case 0x0085:
1668        case 0x2028:        case 0x2028:
1669        case 0x2029:        case 0x2029:
1670          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1671          break;
1672          }
1673        ecode++;
1674        break;
1675    
1676        case OP_NOT_HSPACE:
1677        if (eptr >= md->end_subject)
1678          {
1679          SCHECK_PARTIAL();
1680          RRETURN(MATCH_NOMATCH);
1681          }
1682        GETCHARINCTEST(c, eptr);
1683        switch(c)
1684          {
1685          default: break;
1686          case 0x09:      /* HT */
1687          case 0x20:      /* SPACE */
1688          case 0xa0:      /* NBSP */
1689          case 0x1680:    /* OGHAM SPACE MARK */
1690          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1691          case 0x2000:    /* EN QUAD */
1692          case 0x2001:    /* EM QUAD */
1693          case 0x2002:    /* EN SPACE */
1694          case 0x2003:    /* EM SPACE */
1695          case 0x2004:    /* THREE-PER-EM SPACE */
1696          case 0x2005:    /* FOUR-PER-EM SPACE */
1697          case 0x2006:    /* SIX-PER-EM SPACE */
1698          case 0x2007:    /* FIGURE SPACE */
1699          case 0x2008:    /* PUNCTUATION SPACE */
1700          case 0x2009:    /* THIN SPACE */
1701          case 0x200A:    /* HAIR SPACE */
1702          case 0x202f:    /* NARROW NO-BREAK SPACE */
1703          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1704          case 0x3000:    /* IDEOGRAPHIC SPACE */
1705          RRETURN(MATCH_NOMATCH);
1706          }
1707        ecode++;
1708        break;
1709    
1710        case OP_HSPACE:
1711        if (eptr >= md->end_subject)
1712          {
1713          SCHECK_PARTIAL();
1714          RRETURN(MATCH_NOMATCH);
1715          }
1716        GETCHARINCTEST(c, eptr);
1717        switch(c)
1718          {
1719          default: RRETURN(MATCH_NOMATCH);
1720          case 0x09:      /* HT */
1721          case 0x20:      /* SPACE */
1722          case 0xa0:      /* NBSP */
1723          case 0x1680:    /* OGHAM SPACE MARK */
1724          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1725          case 0x2000:    /* EN QUAD */
1726          case 0x2001:    /* EM QUAD */
1727          case 0x2002:    /* EN SPACE */
1728          case 0x2003:    /* EM SPACE */
1729          case 0x2004:    /* THREE-PER-EM SPACE */
1730          case 0x2005:    /* FOUR-PER-EM SPACE */
1731          case 0x2006:    /* SIX-PER-EM SPACE */
1732          case 0x2007:    /* FIGURE SPACE */
1733          case 0x2008:    /* PUNCTUATION SPACE */
1734          case 0x2009:    /* THIN SPACE */
1735          case 0x200A:    /* HAIR SPACE */
1736          case 0x202f:    /* NARROW NO-BREAK SPACE */
1737          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1738          case 0x3000:    /* IDEOGRAPHIC SPACE */
1739          break;
1740          }
1741        ecode++;
1742        break;
1743    
1744        case OP_NOT_VSPACE:
1745        if (eptr >= md->end_subject)
1746          {
1747          SCHECK_PARTIAL();
1748          RRETURN(MATCH_NOMATCH);
1749          }
1750        GETCHARINCTEST(c, eptr);
1751        switch(c)
1752          {
1753          default: break;
1754          case 0x0a:      /* LF */
1755          case 0x0b:      /* VT */
1756          case 0x0c:      /* FF */
1757          case 0x0d:      /* CR */
1758          case 0x85:      /* NEL */
1759          case 0x2028:    /* LINE SEPARATOR */
1760          case 0x2029:    /* PARAGRAPH SEPARATOR */
1761          RRETURN(MATCH_NOMATCH);
1762          }
1763        ecode++;
1764        break;
1765    
1766        case OP_VSPACE:
1767        if (eptr >= md->end_subject)
1768          {
1769          SCHECK_PARTIAL();
1770          RRETURN(MATCH_NOMATCH);
1771          }
1772        GETCHARINCTEST(c, eptr);
1773        switch(c)
1774          {
1775          default: RRETURN(MATCH_NOMATCH);
1776          case 0x0a:      /* LF */
1777          case 0x0b:      /* VT */
1778          case 0x0c:      /* FF */
1779          case 0x0d:      /* CR */
1780          case 0x85:      /* NEL */
1781          case 0x2028:    /* LINE SEPARATOR */
1782          case 0x2029:    /* PARAGRAPH SEPARATOR */
1783        break;        break;
1784        }        }
1785      ecode++;      ecode++;
# Line 1453  for (;;) Line 1791  for (;;)
1791    
1792      case OP_PROP:      case OP_PROP:
1793      case OP_NOTPROP:      case OP_NOTPROP:
1794      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1795          {
1796          SCHECK_PARTIAL();
1797          RRETURN(MATCH_NOMATCH);
1798          }
1799      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1800        {        {
1801        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1802    
1803        switch(ecode[1])        switch(ecode[1])
1804          {          {
# Line 1466  for (;;) Line 1807  for (;;)
1807          break;          break;
1808    
1809          case PT_LAMP:          case PT_LAMP:
1810          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1811               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1812               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1813            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1814           break;           break;
1815    
1816          case PT_GC:          case PT_GC:
1817          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1818            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1819          break;          break;
1820    
1821          case PT_PC:          case PT_PC:
1822          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1823            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1824          break;          break;
1825    
1826          case PT_SC:          case PT_SC:
1827          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1828            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1829          break;          break;
1830    
# Line 1499  for (;;) Line 1840  for (;;)
1840      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
1841    
1842      case OP_EXTUNI:      case OP_EXTUNI:
1843      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1844          {
1845          SCHECK_PARTIAL();
1846          RRETURN(MATCH_NOMATCH);
1847          }
1848      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1849        {        {
1850        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1851        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1852        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1853          {          {
# Line 1512  for (;;) Line 1856  for (;;)
1856            {            {
1857            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1858            }            }
1859          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1860          if (category != ucp_M) break;          if (category != ucp_M) break;
1861          eptr += len;          eptr += len;
1862          }          }
# Line 1533  for (;;) Line 1877  for (;;)
1877      case OP_REF:      case OP_REF:
1878        {        {
1879        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1880        ecode += 3;                                 /* Advance past item */        ecode += 3;
1881    
1882          /* If the reference is unset, there are two possibilities:
1883    
1884          (a) In the default, Perl-compatible state, set the length to be longer
1885          than the amount of subject left; this ensures that every attempt at a
1886          match fails. We can't just fail here, because of the possibility of
1887          quantifiers with zero minima.
1888    
1889        /* If the reference is unset, set the length to be longer than the amount        (b) If the JavaScript compatibility flag is set, set the length to zero
1890        of subject left; this ensures that every attempt at a match fails. We        so that the back reference matches an empty string.
1891        can't just fail here, because of the possibility of quantifiers with zero  
1892        minima. */        Otherwise, set the length to the length of what was matched by the
1893          referenced subpattern. */
1894        length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
1895          md->end_subject - eptr + 1 :        if (offset >= offset_top || md->offset_vector[offset] < 0)
1896          md->offset_vector[offset+1] - md->offset_vector[offset];          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1897          else
1898            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1899    
1900        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1901    
# Line 1571  for (;;) Line 1924  for (;;)
1924          break;          break;
1925    
1926          default:               /* No repeat follows */          default:               /* No repeat follows */
1927          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1928              {
1929              CHECK_PARTIAL();
1930              RRETURN(MATCH_NOMATCH);
1931              }
1932          eptr += length;          eptr += length;
1933          continue;              /* With the main loop */          continue;              /* With the main loop */
1934          }          }
1935    
1936        /* If the length of the reference is zero, just continue with the        /* If the length of the reference is zero, just continue with the
1937        main loop. */        main loop. */
1938    
1939        if (length == 0) continue;        if (length == 0) continue;
1940    
1941        /* 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 1944  for (;;)
1944    
1945        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
1946          {          {
1947          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1948              {
1949              CHECK_PARTIAL();
1950              RRETURN(MATCH_NOMATCH);
1951              }
1952          eptr += length;          eptr += length;
1953          }          }
1954    
# Line 1602  for (;;) Line 1963  for (;;)
1963          {          {
1964          for (fi = min;; fi++)          for (fi = min;; fi++)
1965            {            {
1966            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
1967            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1968            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
1969              if (!match_ref(offset, eptr, length, md, ims))
1970                {
1971                CHECK_PARTIAL();
1972              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
1973                }
1974            eptr += length;            eptr += length;
1975            }            }
1976          /* Control never gets here */          /* Control never gets here */
# Line 1623  for (;;) Line 1988  for (;;)
1988            }            }
1989          while (eptr >= pp)          while (eptr >= pp)
1990            {            {
1991            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
1992            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1993            eptr -= length;            eptr -= length;
1994            }            }
# Line 1632  for (;;) Line 1997  for (;;)
1997        }        }
1998      /* Control never gets here */      /* Control never gets here */
1999    
   
   
2000      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2001      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,
2002      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 2051  for (;;)
2051          {          {
2052          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2053            {            {
2054            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2055                {
2056                SCHECK_PARTIAL();
2057                RRETURN(MATCH_NOMATCH);
2058                }
2059            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2060            if (c > 255)            if (c > 255)
2061              {              {
# Line 1706  for (;;) Line 2073  for (;;)
2073          {          {
2074          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2075            {            {
2076            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2077                {
2078                SCHECK_PARTIAL();
2079                RRETURN(MATCH_NOMATCH);
2080                }
2081            c = *eptr++;            c = *eptr++;
2082            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2083            }            }
# Line 1728  for (;;) Line 2099  for (;;)
2099            {            {
2100            for (fi = min;; fi++)            for (fi = min;; fi++)
2101              {              {
2102              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2103              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2104              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2105                if (eptr >= md->end_subject)
2106                  {
2107                  SCHECK_PARTIAL();
2108                  RRETURN(MATCH_NOMATCH);
2109                  }
2110              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2111              if (c > 255)              if (c > 255)
2112                {                {
# Line 1748  for (;;) Line 2124  for (;;)
2124            {            {
2125            for (fi = min;; fi++)            for (fi = min;; fi++)
2126              {              {
2127              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2128              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2129              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2130                if (eptr >= md->end_subject)
2131                  {
2132                  SCHECK_PARTIAL();
2133                  RRETURN(MATCH_NOMATCH);
2134                  }
2135              c = *eptr++;              c = *eptr++;
2136              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2137              }              }
# Line 1785  for (;;) Line 2166  for (;;)
2166              }              }
2167            for (;;)            for (;;)
2168              {              {
2169              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2170              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2171              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2172              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1804  for (;;) Line 2185  for (;;)
2185              }              }
2186            while (eptr >= pp)            while (eptr >= pp)
2187              {              {
2188              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2189              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2190              eptr--;              eptr--;
2191              }              }
# Line 1817  for (;;) Line 2198  for (;;)
2198    
2199    
2200      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2201      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
2202        mode, because Unicode properties are supported in non-UTF-8 mode. */
2203    
2204  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2205      case OP_XCLASS:      case OP_XCLASS:
# Line 1858  for (;;) Line 2240  for (;;)
2240    
2241        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2242          {          {
2243          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2244          GETCHARINC(c, eptr);            {
2245              SCHECK_PARTIAL();
2246              RRETURN(MATCH_NOMATCH);
2247              }
2248            GETCHARINCTEST(c, eptr);
2249          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2250          }          }
2251    
# Line 1875  for (;;) Line 2261  for (;;)
2261          {          {
2262          for (fi = min;; fi++)          for (fi = min;; fi++)
2263            {            {
2264            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2265            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2266            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2267            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2268                {
2269                SCHECK_PARTIAL();
2270                RRETURN(MATCH_NOMATCH);
2271                }
2272              GETCHARINCTEST(c, eptr);
2273            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2274            }            }
2275          /* Control never gets here */          /* Control never gets here */
# Line 1893  for (;;) Line 2284  for (;;)
2284            {            {
2285            int len = 1;            int len = 1;
2286            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2287            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2288            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2289            eptr += len;            eptr += len;
2290            }            }
2291          for(;;)          for(;;)
2292            {            {
2293            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2294            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2295            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2296            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2297            }            }
2298          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2299          }          }
# Line 1920  for (;;) Line 2311  for (;;)
2311        length = 1;        length = 1;
2312        ecode++;        ecode++;
2313        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2314        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2315            {
2316            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2317            RRETURN(MATCH_NOMATCH);
2318            }
2319        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2320        }        }
2321      else      else
# Line 1928  for (;;) Line 2323  for (;;)
2323    
2324      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2325        {        {
2326        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2327            {
2328            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2329            RRETURN(MATCH_NOMATCH);
2330            }
2331        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2332        ecode += 2;        ecode += 2;
2333        }        }
# Line 1944  for (;;) Line 2343  for (;;)
2343        ecode++;        ecode++;
2344        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2345    
2346        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2347            {
2348            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2349            RRETURN(MATCH_NOMATCH);
2350            }
2351    
2352        /* 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
2353        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1968  for (;;) Line 2371  for (;;)
2371          if (fc != dc)          if (fc != dc)
2372            {            {
2373  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2374            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2375  #endif  #endif
2376              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2377            }            }
# Line 1979  for (;;) Line 2382  for (;;)
2382    
2383      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2384        {        {
2385        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2386            {
2387            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2388            RRETURN(MATCH_NOMATCH);
2389            }
2390        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2391        ecode += 2;        ecode += 2;
2392        }        }
# Line 2033  for (;;) Line 2440  for (;;)
2440      case OP_MINQUERY:      case OP_MINQUERY:
2441      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2442      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2443    
2444      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2445      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2446      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2447    
2448      /* 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. */  
2449    
2450      REPEATCHAR:      REPEATCHAR:
2451  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 2048  for (;;) Line 2454  for (;;)
2454        length = 1;        length = 1;
2455        charptr = ecode;        charptr = ecode;
2456        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2457        ecode += length;        ecode += length;
2458    
2459        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 2059  for (;;) Line 2464  for (;;)
2464  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2465          unsigned int othercase;          unsigned int othercase;
2466          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2467              (othercase = _pcre_ucp_othercase(fc)) != NOTACHAR)              (othercase = UCD_OTHERCASE(fc)) != fc)
2468            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2469          else oclength = 0;          else oclength = 0;
2470  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2471    
2472          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2473            {            {
2474            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2475                memcmp(eptr, charptr, length) == 0) eptr += length;
2476  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2477            /* Need braces because of following else */            else if (oclength > 0 &&
2478            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                     eptr <= md->end_subject - oclength &&
2479                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2480    #endif  /* SUPPORT_UCP */
2481            else            else
2482              {              {
2483              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2484              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2485              }              }
 #else   /* without SUPPORT_UCP */  
           else { RRETURN(MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2486            }            }
2487    
2488          if (min == max) continue;          if (min == max) continue;
# Line 2086  for (;;) Line 2491  for (;;)
2491            {            {
2492            for (fi = min;; fi++)            for (fi = min;; fi++)
2493              {              {
2494              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2495              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2496              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2497              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2498                  memcmp(eptr, charptr, length) == 0) eptr += length;
2499  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2500              /* Need braces because of following else */              else if (oclength > 0 &&
2501              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }                       eptr <= md->end_subject - oclength &&
2502                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2503    #endif  /* SUPPORT_UCP */
2504              else              else
2505                {                {
2506                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2507                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2508                }                }
 #else   /* without SUPPORT_UCP */  
             else { RRETURN (MATCH_NOMATCH); }  
 #endif  /* SUPPORT_UCP */  
2509              }              }
2510            /* Control never gets here */            /* Control never gets here */
2511            }            }
# Line 2110  for (;;) Line 2515  for (;;)
2515            pp = eptr;            pp = eptr;
2516            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2517              {              {
2518              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2519              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2520  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2521              else if (oclength == 0) break;              else if (oclength > 0 &&
2522              else                       eptr <= md->end_subject - oclength &&
2523                {                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
               if (memcmp(eptr, occhars, oclength) != 0) break;  
               eptr += oclength;  
               }  
 #else   /* without SUPPORT_UCP */  
             else break;  
2524  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2525                else break;
2526              }              }
2527    
2528            if (possessive) continue;            if (possessive) continue;
2529    
2530            for(;;)            for(;;)
2531             {              {
2532             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2533             if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2534             if (eptr == pp) RRETURN(MATCH_NOMATCH);              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2535  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2536             eptr--;              eptr--;
2537             BACKCHAR(eptr);              BACKCHAR(eptr);
2538  #else   /* without SUPPORT_UCP */  #else   /* without SUPPORT_UCP */
2539             eptr -= length;              eptr -= length;
2540  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2541             }              }
2542            }            }
2543          /* Control never gets here */          /* Control never gets here */
2544          }          }
# Line 2149  for (;;) Line 2551  for (;;)
2551  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2552    
2553      /* 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++;  
       }  
2554    
2555        fc = *ecode++;
2556    
2557      /* 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
2558      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
2559      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 2570  for (;;)
2570        {        {
2571        fc = md->lcc[fc];        fc = md->lcc[fc];
2572        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2573            {
2574            if (eptr >= md->end_subject)
2575              {
2576              SCHECK_PARTIAL();
2577              RRETURN(MATCH_NOMATCH);
2578              }
2579          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2580            }
2581        if (min == max) continue;        if (min == max) continue;
2582        if (minimize)        if (minimize)
2583          {          {
2584          for (fi = min;; fi++)          for (fi = min;; fi++)
2585            {            {
2586            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2587            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2588            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2589                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2590                {
2591                SCHECK_PARTIAL();
2592              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2593                }
2594              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2595            }            }
2596          /* Control never gets here */          /* Control never gets here */
2597          }          }
# Line 2192  for (;;) Line 2603  for (;;)
2603            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2604            eptr++;            eptr++;
2605            }            }
2606    
2607          if (possessive) continue;          if (possessive) continue;
2608    
2609          while (eptr >= pp)          while (eptr >= pp)
2610            {            {
2611            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2612            eptr--;            eptr--;
2613            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2614            }            }
# Line 2208  for (;;) Line 2621  for (;;)
2621    
2622      else      else
2623        {        {
2624        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2625            {
2626            if (eptr >= md->end_subject)
2627              {
2628              SCHECK_PARTIAL();
2629              RRETURN(MATCH_NOMATCH);
2630              }
2631            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2632            }
2633    
2634        if (min == max) continue;        if (min == max) continue;
2635    
2636        if (minimize)        if (minimize)
2637          {          {
2638          for (fi = min;; fi++)          for (fi = min;; fi++)
2639            {            {
2640            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2641            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2642            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2643              if (eptr >= md->end_subject)
2644                {
2645                SCHECK_PARTIAL();
2646              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2647                }
2648              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2649            }            }
2650          /* Control never gets here */          /* Control never gets here */
2651          }          }
# Line 2230  for (;;) Line 2658  for (;;)
2658            eptr++;            eptr++;
2659            }            }
2660          if (possessive) continue;          if (possessive) continue;
2661    
2662          while (eptr >= pp)          while (eptr >= pp)
2663            {            {
2664            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2665            eptr--;            eptr--;
2666            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2667            }            }
# Line 2245  for (;;) Line 2674  for (;;)
2674      checking can be multibyte. */      checking can be multibyte. */
2675    
2676      case OP_NOT:      case OP_NOT:
2677      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2678          {
2679          SCHECK_PARTIAL();
2680          RRETURN(MATCH_NOMATCH);
2681          }
2682      ecode++;      ecode++;
2683      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2684      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2322  for (;;) Line 2755  for (;;)
2755      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2756      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2757    
2758      /* 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. */  
2759    
2760      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2761      fc = *ecode++;      fc = *ecode++;
2762    
2763      /* 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 2782  for (;;)
2782          register unsigned int d;          register unsigned int d;
2783          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2784            {            {
2785              if (eptr >= md->end_subject)
2786                {
2787                SCHECK_PARTIAL();
2788                RRETURN(MATCH_NOMATCH);
2789                }
2790            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2791            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2792            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2363  for (;;) Line 2798  for (;;)
2798        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2799          {          {
2800          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2801              {
2802              if (eptr >= md->end_subject)
2803                {
2804                SCHECK_PARTIAL();
2805                RRETURN(MATCH_NOMATCH);
2806                }
2807            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2808              }
2809          }          }
2810    
2811        if (min == max) continue;        if (min == max) continue;
# Line 2377  for (;;) Line 2819  for (;;)
2819            register unsigned int d;            register unsigned int d;
2820            for (fi = min;; fi++)            for (fi = min;; fi++)
2821              {              {
2822              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2823              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2824                if (fi >= max) RRETURN(MATCH_NOMATCH);
2825                if (eptr >= md->end_subject)
2826                  {
2827                  SCHECK_PARTIAL();
2828                  RRETURN(MATCH_NOMATCH);
2829                  }
2830              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2831              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2832              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2833              }              }
2834            }            }
2835          else          else
# Line 2391  for (;;) Line 2838  for (;;)
2838            {            {
2839            for (fi = min;; fi++)            for (fi = min;; fi++)
2840              {              {
2841              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2842              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2843              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
2844                if (eptr >= md->end_subject)
2845                  {
2846                  SCHECK_PARTIAL();
2847                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2848                  }
2849                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2850              }              }
2851            }            }
2852          /* Control never gets here */          /* Control never gets here */
# Line 2423  for (;;) Line 2875  for (;;)
2875          if (possessive) continue;          if (possessive) continue;
2876          for(;;)          for(;;)
2877              {              {
2878              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2879              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2880              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2881              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2441  for (;;) Line 2893  for (;;)
2893            if (possessive) continue;            if (possessive) continue;
2894            while (eptr >= pp)            while (eptr >= pp)
2895              {              {
2896              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2897              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2898              eptr--;              eptr--;
2899              }              }
# Line 2463  for (;;) Line 2915  for (;;)
2915          register unsigned int d;          register unsigned int d;
2916          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2917            {            {
2918              if (eptr >= md->end_subject)
2919                {
2920                SCHECK_PARTIAL();
2921                RRETURN(MATCH_NOMATCH);
2922                }
2923            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2924            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
2925            }            }
# Line 2472  for (;;) Line 2929  for (;;)
2929        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2930          {          {
2931          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2932              {
2933              if (eptr >= md->end_subject)
2934                {
2935                SCHECK_PARTIAL();
2936                RRETURN(MATCH_NOMATCH);
2937                }
2938            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2939              }
2940          }          }
2941    
2942        if (min == max) continue;        if (min == max) continue;
# Line 2486  for (;;) Line 2950  for (;;)
2950            register unsigned int d;            register unsigned int d;
2951            for (fi = min;; fi++)            for (fi = min;; fi++)
2952              {              {
2953              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2954              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2955              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2956              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
2957                  {
2958                  SCHECK_PARTIAL();
2959                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2960                  }
2961                GETCHARINC(d, eptr);
2962                if (fc == d) RRETURN(MATCH_NOMATCH);
2963              }              }
2964            }            }
2965          else          else
# Line 2499  for (;;) Line 2968  for (;;)
2968            {            {
2969            for (fi = min;; fi++)            for (fi = min;; fi++)
2970              {              {
2971              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
2972              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2973              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
2974                if (eptr >= md->end_subject)
2975                  {
2976                  SCHECK_PARTIAL();
2977                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2978                  }
2979                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2980              }              }
2981            }            }
2982          /* Control never gets here */          /* Control never gets here */
# Line 2530  for (;;) Line 3004  for (;;)
3004            if (possessive) continue;            if (possessive) continue;
3005            for(;;)            for(;;)
3006              {              {
3007              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3008              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3009              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3010              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2548  for (;;) Line 3022  for (;;)
3022            if (possessive) continue;            if (possessive) continue;
3023            while (eptr >= pp)            while (eptr >= pp)
3024              {              {
3025              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3026              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3027              eptr--;              eptr--;
3028              }              }
# Line 2636  for (;;) Line 3110  for (;;)
3110    
3111      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3112      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
3113      (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  
3114      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
3115      and single-bytes. */      and single-bytes. */
3116    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3117      if (min > 0)      if (min > 0)
3118        {        {
3119  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2654  for (;;) Line 3125  for (;;)
3125            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3126            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3127              {              {
3128              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3129              GETCHARINC(c, eptr);                {
3130                  SCHECK_PARTIAL();
3131                  RRETURN(MATCH_NOMATCH);
3132                  }
3133                GETCHARINCTEST(c, eptr);
3134              }              }
3135            break;            break;
3136    
3137            case PT_LAMP:            case PT_LAMP:
3138            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3139              {              {
3140              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3141              GETCHARINC(c, eptr);                {
3142              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3143                  RRETURN(MATCH_NOMATCH);
3144                  }
3145                GETCHARINCTEST(c, eptr);
3146                prop_chartype = UCD_CHARTYPE(c);
3147              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3148                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3149                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2675  for (;;) Line 3154  for (;;)
3154            case PT_GC:            case PT_GC:
3155            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3156              {              {
3157              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3158              GETCHARINC(c, eptr);                {
3159              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3160                  RRETURN(MATCH_NOMATCH);
3161                  }
3162                GETCHARINCTEST(c, eptr);
3163                prop_category = UCD_CATEGORY(c);
3164              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3165                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3166              }              }
# Line 2686  for (;;) Line 3169  for (;;)
3169            case PT_PC:            case PT_PC:
3170            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3171              {              {
3172              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3173              GETCHARINC(c, eptr);                {
3174              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3175                  RRETURN(MATCH_NOMATCH);
3176                  }
3177                GETCHARINCTEST(c, eptr);
3178                prop_chartype = UCD_CHARTYPE(c);
3179              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3180                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3181              }              }
# Line 2697  for (;;) Line 3184  for (;;)
3184            case PT_SC:            case PT_SC:
3185            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3186              {              {
3187              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3188              GETCHARINC(c, eptr);                {
3189              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3190                  RRETURN(MATCH_NOMATCH);
3191                  }
3192                GETCHARINCTEST(c, eptr);
3193                prop_script = UCD_SCRIPT(c);
3194              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3195                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3196              }              }
# Line 2717  for (;;) Line 3208  for (;;)
3208          {          {
3209          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3210            {            {
3211              if (eptr >= md->end_subject)
3212                {
3213                SCHECK_PARTIAL();
3214                RRETURN(MATCH_NOMATCH);
3215                }
3216            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3217            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3218            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3219            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3220              {              {
3221              int len = 1;              int len = 1;
3222              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3223                {                else { GETCHARLEN(c, eptr, len); }
3224                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3225              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3226              eptr += len;              eptr += len;
3227              }              }
# Line 2745  for (;;) Line 3239  for (;;)
3239          case OP_ANY:          case OP_ANY:
3240          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3241            {            {
3242            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3243                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))              {
3244                SCHECK_PARTIAL();
3245                RRETURN(MATCH_NOMATCH);
3246                }
3247              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3248              eptr++;
3249              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3250              }
3251            break;
3252    
3253            case OP_ALLANY:
3254            for (i = 1; i <= min; i++)
3255              {
3256              if (eptr >= md->end_subject)
3257                {
3258                SCHECK_PARTIAL();
3259              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3260                }
3261            eptr++;            eptr++;
3262            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3263            }            }
3264          break;          break;
3265    
3266          case OP_ANYBYTE:          case OP_ANYBYTE:
3267            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3268          eptr += min;          eptr += min;
3269          break;          break;
3270    
3271          case OP_ANYNL:          case OP_ANYNL:
3272          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3273            {            {
3274            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3275                {
3276                SCHECK_PARTIAL();
3277                RRETURN(MATCH_NOMATCH);
3278                }
3279            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3280            switch(c)            switch(c)
3281              {              {
# Line 2768  for (;;) Line 3283  for (;;)
3283              case 0x000d:              case 0x000d:
3284              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3285              break;              break;
3286    
3287              case 0x000a:              case 0x000a:
3288                break;
3289    
3290              case 0x000b:              case 0x000b:
3291              case 0x000c:              case 0x000c:
3292              case 0x0085:              case 0x0085:
3293              case 0x2028:              case 0x2028:
3294              case 0x2029:              case 0x2029:
3295                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3296                break;
3297                }
3298              }
3299            break;
3300    
3301            case OP_NOT_HSPACE:
3302            for (i = 1; i <= min; i++)
3303              {
3304              if (eptr >= md->end_subject)
3305                {
3306                SCHECK_PARTIAL();
3307                RRETURN(MATCH_NOMATCH);
3308                }
3309              GETCHARINC(c, eptr);
3310              switch(c)
3311                {
3312                default: break;
3313                case 0x09:      /* HT */
3314                case 0x20:      /* SPACE */
3315                case 0xa0:      /* NBSP */
3316                case 0x1680:    /* OGHAM SPACE MARK */
3317                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3318                case 0x2000:    /* EN QUAD */
3319                case 0x2001:    /* EM QUAD */
3320                case 0x2002:    /* EN SPACE */
3321                case 0x2003:    /* EM SPACE */
3322                case 0x2004:    /* THREE-PER-EM SPACE */
3323                case 0x2005:    /* FOUR-PER-EM SPACE */
3324                case 0x2006:    /* SIX-PER-EM SPACE */
3325                case 0x2007:    /* FIGURE SPACE */
3326                case 0x2008:    /* PUNCTUATION SPACE */
3327                case 0x2009:    /* THIN SPACE */
3328                case 0x200A:    /* HAIR SPACE */
3329                case 0x202f:    /* NARROW NO-BREAK SPACE */
3330                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3331                case 0x3000:    /* IDEOGRAPHIC SPACE */
3332                RRETURN(MATCH_NOMATCH);
3333                }
3334              }
3335            break;
3336    
3337            case OP_HSPACE:
3338            for (i = 1; i <= min; i++)
3339              {
3340              if (eptr >= md->end_subject)
3341                {
3342                SCHECK_PARTIAL();
3343                RRETURN(MATCH_NOMATCH);
3344                }
3345              GETCHARINC(c, eptr);
3346              switch(c)
3347                {
3348                default: RRETURN(MATCH_NOMATCH);
3349                case 0x09:      /* HT */
3350                case 0x20:      /* SPACE */
3351                case 0xa0:      /* NBSP */
3352                case 0x1680:    /* OGHAM SPACE MARK */
3353                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3354                case 0x2000:    /* EN QUAD */
3355                case 0x2001:    /* EM QUAD */
3356                case 0x2002:    /* EN SPACE */
3357                case 0x2003:    /* EM SPACE */
3358                case 0x2004:    /* THREE-PER-EM SPACE */
3359                case 0x2005:    /* FOUR-PER-EM SPACE */
3360                case 0x2006:    /* SIX-PER-EM SPACE */
3361                case 0x2007:    /* FIGURE SPACE */
3362                case 0x2008:    /* PUNCTUATION SPACE */
3363                case 0x2009:    /* THIN SPACE */
3364                case 0x200A:    /* HAIR SPACE */
3365                case 0x202f:    /* NARROW NO-BREAK SPACE */
3366                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3367                case 0x3000:    /* IDEOGRAPHIC SPACE */
3368                break;
3369                }
3370              }
3371            break;
3372    
3373            case OP_NOT_VSPACE:
3374            for (i = 1; i <= min; i++)
3375              {
3376              if (eptr >= md->end_subject)
3377                {
3378                SCHECK_PARTIAL();
3379                RRETURN(MATCH_NOMATCH);
3380                }
3381              GETCHARINC(c, eptr);
3382              switch(c)
3383                {
3384                default: break;
3385                case 0x0a:      /* LF */
3386                case 0x0b:      /* VT */
3387                case 0x0c:      /* FF */
3388                case 0x0d:      /* CR */
3389                case 0x85:      /* NEL */
3390                case 0x2028:    /* LINE SEPARATOR */
3391                case 0x2029:    /* PARAGRAPH SEPARATOR */
3392                RRETURN(MATCH_NOMATCH);
3393                }
3394              }
3395            break;
3396    
3397            case OP_VSPACE:
3398            for (i = 1; i <= min; i++)
3399              {
3400              if (eptr >= md->end_subject)
3401                {
3402                SCHECK_PARTIAL();
3403                RRETURN(MATCH_NOMATCH);
3404                }
3405              GETCHARINC(c, eptr);
3406              switch(c)
3407                {
3408                default: RRETURN(MATCH_NOMATCH);
3409                case 0x0a:      /* LF */
3410                case 0x0b:      /* VT */
3411                case 0x0c:      /* FF */
3412                case 0x0d:      /* CR */
3413                case 0x85:      /* NEL */
3414                case 0x2028:    /* LINE SEPARATOR */
3415                case 0x2029:    /* PARAGRAPH SEPARATOR */
3416              break;              break;
3417              }              }
3418            }            }
# Line 2782  for (;;) Line 3421  for (;;)
3421          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3422          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3423            {            {
3424            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3425                {
3426                SCHECK_PARTIAL();
3427                RRETURN(MATCH_NOMATCH);
3428                }
3429            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3430            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3431              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 2792  for (;;) Line 3435  for (;;)
3435          case OP_DIGIT:          case OP_DIGIT:
3436          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3437            {            {
3438            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3439               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3440                SCHECK_PARTIAL();
3441                RRETURN(MATCH_NOMATCH);
3442                }
3443              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3444              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3445            /* 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 */
3446            }            }
# Line 2802  for (;;) Line 3449  for (;;)
3449          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3450          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3451            {            {
3452            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3453               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3454                SCHECK_PARTIAL();
3455              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3456            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3457              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3458                RRETURN(MATCH_NOMATCH);
3459              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3460            }            }
3461          break;          break;
3462    
3463          case OP_WHITESPACE:          case OP_WHITESPACE:
3464          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3465            {            {
3466            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3467               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3468                SCHECK_PARTIAL();
3469                RRETURN(MATCH_NOMATCH);
3470                }
3471              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3472              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3473            /* 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 */
3474            }            }
# Line 2823  for (;;) Line 3478  for (;;)
3478          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3479            {            {
3480            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3481               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3482              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3483            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3484            }            }
3485          break;          break;
3486    
3487          case OP_WORDCHAR:          case OP_WORDCHAR:
3488          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3489            {            {
3490            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3491               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3492                SCHECK_PARTIAL();
3493                RRETURN(MATCH_NOMATCH);
3494                }
3495              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3496              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3497            /* 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 */
3498            }            }
# Line 2847  for (;;) Line 3506  for (;;)
3506  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF8 */
3507    
3508        /* 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
3509        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. */  
3510    
3511        switch(ctype)        switch(ctype)
3512          {          {
3513          case OP_ANY:          case OP_ANY:
3514          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3515            {            {
3516            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3517              {              {
3518              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);              SCHECK_PARTIAL();
3519              eptr++;              RRETURN(MATCH_NOMATCH);
3520              }              }
3521              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3522              eptr++;
3523            }            }
         else eptr += min;  
3524          break;          break;
3525    
3526          case OP_ANYBYTE:          case OP_ALLANY:
3527            if (eptr > md->end_subject - min)
3528              {
3529              SCHECK_PARTIAL();
3530              RRETURN(MATCH_NOMATCH);
3531              }
3532          eptr += min;          eptr += min;
3533          break;          break;
3534    
3535          /* Because of the CRLF case, we can't assume the minimum number of          case OP_ANYBYTE:
3536          bytes are present in this case. */          if (eptr > md->end_subject - min)
3537              {
3538              SCHECK_PARTIAL();
3539              RRETURN(MATCH_NOMATCH);
3540              }
3541            eptr += min;
3542            break;
3543    
3544          case OP_ANYNL:          case OP_ANYNL:
3545          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3546            {            {
3547            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3548                {
3549                SCHECK_PARTIAL();
3550                RRETURN(MATCH_NOMATCH);
3551                }
3552            switch(*eptr++)            switch(*eptr++)
3553              {              {
3554              default: RRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
# Line 2882  for (;;) Line 3556  for (;;)
3556              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3557              break;              break;
3558              case 0x000a:              case 0x000a:
3559                break;
3560    
3561              case 0x000b:              case 0x000b:
3562              case 0x000c:              case 0x000c:
3563              case 0x0085:              case 0x0085:
3564                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3565                break;
3566                }
3567              }
3568            break;
3569    
3570            case OP_NOT_HSPACE:
3571            for (i = 1; i <= min; i++)
3572              {
3573              if (eptr >= md->end_subject)
3574                {
3575                SCHECK_PARTIAL();
3576                RRETURN(MATCH_NOMATCH);
3577                }
3578              switch(*eptr++)
3579                {
3580                default: break;
3581                case 0x09:      /* HT */
3582                case 0x20:      /* SPACE */
3583                case 0xa0:      /* NBSP */
3584                RRETURN(MATCH_NOMATCH);
3585                }
3586              }
3587            break;
3588    
3589            case OP_HSPACE:
3590            for (i = 1; i <= min; i++)
3591              {
3592              if (eptr >= md->end_subject)
3593                {
3594                SCHECK_PARTIAL();
3595                RRETURN(MATCH_NOMATCH);
3596                }
3597              switch(*eptr++)
3598                {
3599                default: RRETURN(MATCH_NOMATCH);
3600                case 0x09:      /* HT */
3601                case 0x20:      /* SPACE */
3602                case 0xa0:      /* NBSP */
3603                break;
3604                }
3605              }
3606            break;
3607    
3608            case OP_NOT_VSPACE:
3609            for (i = 1; i <= min; i++)
3610              {
3611              if (eptr >= md->end_subject)
3612                {
3613                SCHECK_PARTIAL();
3614                RRETURN(MATCH_NOMATCH);
3615                }
3616              switch(*eptr++)
3617                {
3618                default: break;
3619                case 0x0a:      /* LF */
3620                case 0x0b:      /* VT */
3621                case 0x0c:      /* FF */
3622                case 0x0d:      /* CR */
3623                case 0x85:      /* NEL */
3624                RRETURN(MATCH_NOMATCH);
3625                }
3626              }
3627            break;
3628    
3629            case OP_VSPACE:
3630            for (i = 1; i <= min; i++)
3631              {
3632              if (eptr >= md->end_subject)
3633                {
3634                SCHECK_PARTIAL();
3635                RRETURN(MATCH_NOMATCH);
3636                }
3637              switch(*eptr++)
3638                {
3639                default: RRETURN(MATCH_NOMATCH);
3640                case 0x0a:      /* LF */
3641                case 0x0b:      /* VT */
3642                case 0x0c:      /* FF */
3643                case 0x0d:      /* CR */
3644                case 0x85:      /* NEL */
3645              break;              break;
3646              }              }
3647            }            }
# Line 2892  for (;;) Line 3649  for (;;)
3649    
3650          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3651          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3652              {
3653              if (eptr >= md->end_subject)
3654                {
3655                SCHECK_PARTIAL();
3656                RRETURN(MATCH_NOMATCH);
3657                }
3658            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3659              }
3660          break;          break;
3661    
3662          case OP_DIGIT:          case OP_DIGIT:
3663          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3664              {
3665              if (eptr >= md->end_subject)
3666                {
3667                SCHECK_PARTIAL();
3668                RRETURN(MATCH_NOMATCH);
3669                }
3670            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3671              }
3672          break;          break;
3673    
3674          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3675          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3676              {
3677              if (eptr >= md->end_subject)
3678                {
3679                SCHECK_PARTIAL();
3680                RRETURN(MATCH_NOMATCH);
3681                }
3682            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3683              }
3684          break;          break;
3685    
3686          case OP_WHITESPACE:          case OP_WHITESPACE:
3687          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3688              {
3689              if (eptr >= md->end_subject)
3690                {
3691                SCHECK_PARTIAL();
3692                RRETURN(MATCH_NOMATCH);
3693                }
3694            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3695              }
3696          break;          break;
3697    
3698          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3699          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3700              {
3701              if (eptr >= md->end_subject)
3702                {
3703                SCHECK_PARTIAL();
3704                RRETURN(MATCH_NOMATCH);
3705                }
3706            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3707              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3708              }
3709          break;          break;
3710    
3711          case OP_WORDCHAR:          case OP_WORDCHAR:
3712          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3713              {
3714              if (eptr >= md->end_subject)
3715                {
3716                SCHECK_PARTIAL();
3717                RRETURN(MATCH_NOMATCH);
3718                }
3719            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3720              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3721              }
3722          break;          break;
3723    
3724          default:          default:
# Line 2945  for (;;) Line 3744  for (;;)
3744            case PT_ANY:            case PT_ANY:
3745            for (fi = min;; fi++)            for (fi = min;; fi++)
3746              {              {
3747              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3748              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3749              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3750                if (eptr >= md->end_subject)
3751                  {
3752                  SCHECK_PARTIAL();
3753                  RRETURN(MATCH_NOMATCH);
3754                  }
3755              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3756              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3757              }              }
# Line 2956  for (;;) Line 3760  for (;;)
3760            case PT_LAMP:            case PT_LAMP:
3761            for (fi = min;; fi++)            for (fi = min;; fi++)
3762              {              {
3763              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3764              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3765              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3766                if (eptr >= md->end_subject)
3767                  {
3768                  SCHECK_PARTIAL();
3769                  RRETURN(MATCH_NOMATCH);
3770                  }
3771              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3772              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3773              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3774                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3775                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2971  for (;;) Line 3780  for (;;)
3780            case PT_GC:            case PT_GC:
3781            for (fi = min;; fi++)            for (fi = min;; fi++)
3782              {              {
3783              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3784              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3785              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3786                if (eptr >= md->end_subject)
3787                  {
3788                  SCHECK_PARTIAL();
3789                  RRETURN(MATCH_NOMATCH);
3790                  }
3791              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3792              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3793              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3794                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3795              }              }
# Line 2984  for (;;) Line 3798  for (;;)
3798            case PT_PC:            case PT_PC:
3799            for (fi = min;; fi++)            for (fi = min;; fi++)
3800              {              {
3801              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3802              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3803              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3804                if (eptr >= md->end_subject)
3805                  {
3806                  SCHECK_PARTIAL();
3807                  RRETURN(MATCH_NOMATCH);
3808                  }
3809              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3810              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3811              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3812                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3813              }              }
# Line 2997  for (;;) Line 3816  for (;;)
3816            case PT_SC:            case PT_SC:
3817            for (fi = min;; fi++)            for (fi = min;; fi++)
3818              {              {
3819              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3820              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3821              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3822                if (eptr >= md->end_subject)
3823                  {
3824                  SCHECK_PARTIAL();
3825                  RRETURN(MATCH_NOMATCH);
3826                  }
3827              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3828              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3829              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3830                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3831              }              }
# Line 3019  for (;;) Line 3843  for (;;)
3843          {          {
3844          for (fi = min;; fi++)          for (fi = min;; fi++)
3845            {            {
3846            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3847            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3848            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3849              if (eptr >= md->end_subject)
3850                {
3851                SCHECK_PARTIAL();
3852                RRETURN(MATCH_NOMATCH);
3853                }
3854            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3855            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3856            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3857            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3858              {              {
3859              int len = 1;              int len = 1;
3860              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3861                {                else { GETCHARLEN(c, eptr, len); }
3862                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3863              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3864              eptr += len;              eptr += len;
3865              }              }
# Line 3048  for (;;) Line 3875  for (;;)
3875          {          {
3876          for (fi = min;; fi++)          for (fi = min;; fi++)
3877            {            {
3878            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3879            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3880            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
3881                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&            if (eptr >= md->end_subject)
3882                  IS_NEWLINE(eptr)))              {
3883                SCHECK_PARTIAL();
3884                RRETURN(MATCH_NOMATCH);
3885                }
3886              if (ctype == OP_ANY && IS_NEWLINE(eptr))
3887              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
3888            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3889            switch(ctype)            switch(ctype)
3890              {              {
3891              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3892              break;              case OP_ALLANY:
   
3893              case OP_ANYBYTE:              case OP_ANYBYTE:
3894              break;              break;
3895    
# Line 3072  for (;;) Line 3901  for (;;)
3901                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3902                break;                break;
3903                case 0x000a:                case 0x000a:
3904                  break;
3905    
3906                case 0x000b:                case 0x000b:
3907                case 0x000c:                case 0x000c:
3908                case 0x0085:                case 0x0085:
3909                case 0x2028:                case 0x2028:
3910                case 0x2029:                case 0x2029:
3911                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3912                  break;
3913                  }
3914                break;
3915    
3916                case OP_NOT_HSPACE:
3917                switch(c)
3918                  {
3919                  default: break;
3920                  case 0x09:      /* HT */
3921                  case 0x20:      /* SPACE */
3922                  case 0xa0:      /* NBSP */
3923                  case 0x1680:    /* OGHAM SPACE MARK */
3924                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3925                  case 0x2000:    /* EN QUAD */
3926                  case 0x2001:    /* EM QUAD */
3927                  case 0x2002:    /* EN SPACE */
3928                  case 0x2003:    /* EM SPACE */
3929                  case 0x2004:    /* THREE-PER-EM SPACE */
3930                  case 0x2005:    /* FOUR-PER-EM SPACE */
3931                  case 0x2006:    /* SIX-PER-EM SPACE */
3932                  case 0x2007:    /* FIGURE SPACE */
3933                  case 0x2008:    /* PUNCTUATION SPACE */
3934                  case 0x2009:    /* THIN SPACE */
3935                  case 0x200A:    /* HAIR SPACE */
3936                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3937                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3938                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3939                  RRETURN(MATCH_NOMATCH);
3940                  }
3941                break;
3942    
3943                case OP_HSPACE:
3944                switch(c)
3945                  {
3946                  default: RRETURN(MATCH_NOMATCH);
3947                  case 0x09:      /* HT */
3948                  case 0x20:      /* SPACE */
3949                  case 0xa0:      /* NBSP */
3950                  case 0x1680:    /* OGHAM SPACE MARK */
3951                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3952                  case 0x2000:    /* EN QUAD */
3953                  case 0x2001:    /* EM QUAD */
3954                  case 0x2002:    /* EN SPACE */
3955                  case 0x2003:    /* EM SPACE */
3956                  case 0x2004:    /* THREE-PER-EM SPACE */
3957                  case 0x2005:    /* FOUR-PER-EM SPACE */
3958                  case 0x2006:    /* SIX-PER-EM SPACE */
3959                  case 0x2007:    /* FIGURE SPACE */
3960                  case 0x2008:    /* PUNCTUATION SPACE */
3961                  case 0x2009:    /* THIN SPACE */
3962                  case 0x200A:    /* HAIR SPACE */
3963                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3964                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3965                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3966                  break;
3967                  }
3968                break;
3969    
3970                case OP_NOT_VSPACE:
3971                switch(c)
3972                  {
3973                  default: break;
3974                  case 0x0a:      /* LF */
3975                  case 0x0b:      /* VT */
3976                  case 0x0c:      /* FF */
3977                  case 0x0d:      /* CR */
3978                  case 0x85:      /* NEL */
3979                  case 0x2028:    /* LINE SEPARATOR */
3980                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3981                  RRETURN(MATCH_NOMATCH);
3982                  }
3983                break;
3984    
3985                case OP_VSPACE:
3986                switch(c)
3987                  {
3988                  default: RRETURN(MATCH_NOMATCH);
3989                  case 0x0a:      /* LF */
3990                  case 0x0b:      /* VT */
3991                  case 0x0c:      /* FF */
3992                  case 0x0d:      /* CR */
3993                  case 0x85:      /* NEL */
3994                  case 0x2028:    /* LINE SEPARATOR */
3995                  case 0x2029:    /* PARAGRAPH SEPARATOR */
3996                break;                break;
3997                }                }
3998              break;              break;
# Line 3122  for (;;) Line 4038  for (;;)
4038          {          {
4039          for (fi = min;; fi++)          for (fi = min;; fi++)
4040            {            {
4041            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4042            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4043            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4044                 ((ims & PCRE_DOTALL) == 0 && IS_NEWLINE(eptr)))            if (eptr >= md->end_subject)
4045                {
4046                SCHECK_PARTIAL();
4047                RRETURN(MATCH_NOMATCH);
4048                }
4049              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4050              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4051            c = *eptr++;            c = *eptr++;
4052            switch(ctype)            switch(ctype)
4053              {              {
4054              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
4055              break;              case OP_ALLANY:
   
4056              case OP_ANYBYTE:              case OP_ANYBYTE:
4057              break;              break;
4058    
# Line 3144  for (;;) Line 4063  for (;;)
4063                case 0x000d:                case 0x000d:
4064                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4065                break;                break;
4066    
4067                case 0x000a:                case 0x000a:
4068                  break;
4069    
4070                case 0x000b:                case 0x000b:
4071                case 0x000c:                case 0x000c:
4072                case 0x0085:                case 0x0085:
4073                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4074                  break;
4075                  }
4076                break;
4077    
4078                case OP_NOT_HSPACE:
4079                switch(c)
4080                  {
4081                  default: break;
4082                  case 0x09:      /* HT */
4083                  case 0x20:      /* SPACE */
4084                  case 0xa0:      /* NBSP */
4085                  RRETURN(MATCH_NOMATCH);
4086                  }
4087                break;
4088    
4089                case OP_HSPACE:
4090                switch(c)
4091                  {
4092                  default: RRETURN(MATCH_NOMATCH);
4093                  case 0x09:      /* HT */
4094                  case 0x20:      /* SPACE */
4095                  case 0xa0:      /* NBSP */
4096                  break;
4097                  }
4098                break;
4099    
4100                case OP_NOT_VSPACE:
4101                switch(c)
4102                  {
4103                  default: break;
4104                  case 0x0a:      /* LF */
4105                  case 0x0b:      /* VT */
4106                  case 0x0c:      /* FF */
4107                  case 0x0d:      /* CR */
4108                  case 0x85:      /* NEL */
4109                  RRETURN(MATCH_NOMATCH);
4110                  }
4111                break;
4112    
4113                case OP_VSPACE:
4114                switch(c)
4115                  {
4116                  default: RRETURN(MATCH_NOMATCH);
4117                  case 0x0a:      /* LF */
4118                  case 0x0b:      /* VT */
4119                  case 0x0c:      /* FF */
4120                  case 0x0d:      /* CR */
4121                  case 0x85:      /* NEL */
4122                break;                break;
4123                }                }
4124              break;              break;
# Line 3214  for (;;) Line 4185  for (;;)
4185              int len = 1;              int len = 1;
4186              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4187              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4188              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4189              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4190                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
4191                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 3229  for (;;) Line 4200  for (;;)
4200              int len = 1;              int len = 1;
4201              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4202              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4203              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4204              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
4205                break;                break;
4206              eptr+= len;              eptr+= len;
# Line 3242  for (;;) Line 4213  for (;;)
4213              int len = 1;              int len = 1;
4214              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4215              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4216              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4217              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
4218                break;                break;
4219              eptr+= len;              eptr+= len;
# Line 3255  for (;;) Line 4226  for (;;)
4226              int len = 1;              int len = 1;
4227              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject) break;
4228              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
4229              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
4230              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
4231                break;                break;
4232              eptr+= len;              eptr+= len;
# Line 3268  for (;;) Line 4239  for (;;)
4239          if (possessive) continue;          if (possessive) continue;
4240          for(;;)          for(;;)
4241            {            {
4242            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM44);
4243            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4244            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4245            BACKCHAR(eptr);            if (utf8) BACKCHAR(eptr);
4246            }            }
4247          }          }
4248    
# Line 3284  for (;;) Line 4255  for (;;)
4255            {            {
4256            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
4257            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4258            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
4259            if (prop_category == ucp_M) break;            if (prop_category == ucp_M) break;
4260            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4261              {              {
# Line 3293  for (;;) Line 4264  for (;;)
4264                {                {
4265                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
4266                }                }
4267              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4268              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4269              eptr += len;              eptr += len;
4270              }              }
# Line 3304  for (;;) Line 4275  for (;;)
4275          if (possessive) continue;          if (possessive) continue;
4276          for(;;)          for(;;)
4277            {            {
4278            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM45);
4279            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4280            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4281            for (;;)                        /* Move back over one extended */            for (;;)                        /* Move back over one extended */
4282              {              {
4283              int len = 1;              int len = 1;
             BACKCHAR(eptr);  
4284              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr; else
4285                {                {
4286                  BACKCHAR(eptr);
4287                GETCHARLEN(c, eptr, len);                GETCHARLEN(c, eptr, len);
4288                }                }
4289              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
4290              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
4291              eptr--;              eptr--;
4292              }              }
# Line 3333  for (;;) Line 4304  for (;;)
4304          switch(ctype)          switch(ctype)
4305            {            {
4306            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. */  
   
4307            if (max < INT_MAX)            if (max < INT_MAX)
4308              {              {
4309              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  
4310                {                {
4311                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4312                  {                eptr++;
4313                  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++;  
                 }  
4314                }                }
4315              }              }
4316    
# Line 3364  for (;;) Line 4318  for (;;)
4318    
4319            else            else
4320              {              {
4321              if ((ims & PCRE_DOTALL) == 0)              for (i = min; i < max; i++)
4322                {                {
4323                for (i = min; i < max; i++)                if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4324                  {                eptr++;
4325                  if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
                 eptr++;  
                 }  
               break;  
4326                }                }
4327              else              }
4328              break;
4329    
4330              case OP_ALLANY:
4331              if (max < INT_MAX)
4332                {
4333                for (i = min; i < max; i++)
4334                {                {
4335                c = max - min;                if (eptr >= md->end_subject) break;
4336                if (c > (unsigned int)(md->end_subject - eptr))                eptr++;
4337                  c = md->end_subject - eptr;                while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
               eptr += c;  
4338                }                }
4339              }              }
4340              else eptr = md->end_subject;   /* Unlimited UTF-8 repeat */
4341            break;            break;
4342    
4343            /* The byte case is the same as non-UTF8 */            /* The byte case is the same as non-UTF8 */
# Line 3405  for (;;) Line 4362  for (;;)
4362                }                }
4363              else              else
4364                {                {
4365                if (c != 0x000a && c != 0x000b && c != 0x000c &&                if (c != 0x000a &&
4366                    c != 0x0085 && c != 0x2028 && c != 0x2029)                    (md->bsr_anycrlf ||
4367                       (c != 0x000b && c != 0x000c &&
4368                        c != 0x0085 && c != 0x2028 && c != 0x2029)))
4369                  break;                  break;
4370                eptr += len;                eptr += len;
4371                }                }
4372              }              }
4373            break;            break;
4374    
4375              case OP_NOT_HSPACE:
4376              case OP_HSPACE:
4377              for (i = min; i < max; i++)
4378                {
4379                BOOL gotspace;
4380                int len = 1;
4381                if (eptr >= md->end_subject) break;
4382                GETCHARLEN(c, eptr, len);
4383                switch(c)
4384                  {
4385                  default: gotspace = FALSE; break;
4386                  case 0x09:      /* HT */
4387                  case 0x20:      /* SPACE */
4388                  case 0xa0:      /* NBSP */
4389                  case 0x1680:    /* OGHAM SPACE MARK */
4390                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4391                  case 0x2000:    /* EN QUAD */
4392                  case 0x2001:    /* EM QUAD */
4393                  case 0x2002:    /* EN SPACE */
4394                  case 0x2003:    /* EM SPACE */
4395                  case 0x2004:    /* THREE-PER-EM SPACE */
4396                  case 0x2005:    /* FOUR-PER-EM SPACE */
4397                  case 0x2006:    /* SIX-PER-EM SPACE */
4398                  case 0x2007:    /* FIGURE SPACE */
4399                  case 0x2008:    /* PUNCTUATION SPACE */
4400                  case 0x2009:    /* THIN SPACE */
4401                  case 0x200A:    /* HAIR SPACE */
4402                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4403                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4404                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4405                  gotspace = TRUE;
4406                  break;
4407                  }
4408                if (gotspace == (ctype == OP_NOT_HSPACE)) break;
4409                eptr += len;
4410                }
4411              break;
4412    
4413              case OP_NOT_VSPACE:
4414              case OP_VSPACE:
4415              for (i = min; i < max; i++)
4416                {
4417                BOOL gotspace;
4418                int len = 1;
4419                if (eptr >= md->end_subject) break;
4420                GETCHARLEN(c, eptr, len);
4421                switch(c)
4422                  {
4423                  default: gotspace = FALSE; break;
4424                  case 0x0a:      /* LF */
4425                  case 0x0b:      /* VT */
4426                  case 0x0c:      /* FF */
4427                  case 0x0d:      /* CR */
4428                  case 0x85:      /* NEL */
4429                  case 0x2028:    /* LINE SEPARATOR */
4430                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4431                  gotspace = TRUE;
4432                  break;
4433                  }
4434                if (gotspace == (ctype == OP_NOT_VSPACE)) break;
4435                eptr += len;
4436                }
4437              break;
4438    
4439            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4440            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4441              {              {
# Line 3488  for (;;) Line 4511  for (;;)
4511          if (possessive) continue;          if (possessive) continue;
4512          for(;;)          for(;;)
4513            {            {
4514            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM46);
4515            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4516            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
4517            BACKCHAR(eptr);            BACKCHAR(eptr);
4518            }            }
4519          }          }
4520        else        else
4521  #endif  #endif  /* SUPPORT_UTF8 */
4522    
4523        /* Not UTF-8 mode */        /* Not UTF-8 mode */
4524          {          {
4525          switch(ctype)          switch(ctype)
4526            {            {
4527            case OP_ANY:            case OP_ANY:
4528            if ((ims & PCRE_DOTALL) == 0)            for (i = min; i < max; i++)
4529              {              {
4530              for (i = min; i < max; i++)              if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;
4531                {              eptr++;
               if (eptr >= md->end_subject || IS_NEWLINE(eptr)) break;  
               eptr++;  
               }  
             break;  
4532              }              }
4533            /* For DOTALL case, fall through and treat as \C */            break;
4534    
4535              case OP_ALLANY:
4536            case OP_ANYBYTE:            case OP_ANYBYTE:
4537            c = max - min;            c = max - min;
4538            if (c > (unsigned int)(md->end_subject - eptr))            if (c > (unsigned int)(md->end_subject - eptr))
# Line 3532  for (;;) Line 4552  for (;;)
4552                }                }
4553              else              else
4554                {                {
4555                if (c != 0x000a && c != 0x000b && c != 0x000c && c != 0x0085)                if (c != 0x000a &&
4556                      (md->bsr_anycrlf ||
4557                        (c != 0x000b && c != 0x000c && c != 0x0085)))
4558                  break;                  break;
4559                eptr++;                eptr++;
4560                }                }
4561              }              }
4562            break;            break;
4563    
4564              case OP_NOT_HSPACE:
4565              for (i = min; i < max; i++)
4566                {
4567                if (eptr >= md->end_subject) break;
4568                c = *eptr;
4569                if (c == 0x09 || c == 0x20 || c == 0xa0) break;
4570                eptr++;
4571                }
4572              break;
4573    
4574              case OP_HSPACE:
4575              for (i = min; i < max; i++)
4576                {
4577                if (eptr >= md->end_subject) break;
4578                c = *eptr;
4579                if (c != 0x09 && c != 0x20 && c != 0xa0) break;
4580                eptr++;
4581                }
4582              break;
4583    
4584              case OP_NOT_VSPACE:
4585              for (i = min; i < max; i++)
4586                {
4587                if (eptr >= md->end_subject) break;
4588                c = *eptr;
4589                if (c == 0x0a || c == 0x0b || c == 0x0c || c == 0x0d || c == 0x85)
4590                  break;
4591                eptr++;
4592                }
4593              break;
4594    
4595              case OP_VSPACE:
4596              for (i = min; i < max; i++)
4597                {
4598                if (eptr >= md->end_subject) break;
4599                c = *eptr;
4600                if (c != 0x0a && c != 0x0b && c != 0x0c && c != 0x0d && c != 0x85)
4601                  break;
4602                eptr++;
4603                }
4604              break;
4605    
4606            case OP_NOT_DIGIT:            case OP_NOT_DIGIT:
4607            for (i = min; i < max; i++)            for (i = min; i < max; i++)
4608              {              {
# Line 3602  for (;;) Line 4666  for (;;)
4666          if (possessive) continue;          if (possessive) continue;
4667          while (eptr >= pp)          while (eptr >= pp)
4668            {            {
4669            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM47);
4670            eptr--;            eptr--;
4671            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4672            }            }
# Line 3628  for (;;) Line 4692  for (;;)
4692    
4693    }             /* End of main loop */    }             /* End of main loop */
4694  /* Control never reaches here */  /* Control never reaches here */
4695    
4696    
4697    /* When compiling to use the heap rather than the stack for recursive calls to
4698    match(), the RRETURN() macro jumps here. The number that is saved in
4699    frame->Xwhere indicates which label we actually want to return to. */
4700    
4701    #ifdef NO_RECURSE
4702    #define LBL(val) case val: goto L_RM##val;
4703    HEAP_RETURN:
4704    switch (frame->Xwhere)
4705      {
4706      LBL( 1) LBL( 2) LBL( 3) LBL( 4) LBL( 5) LBL( 6) LBL( 7) LBL( 8)
4707      LBL( 9) LBL(10) LBL(11) LBL(12) LBL(13) LBL(14) LBL(15) LBL(17)
4708      LBL(19) LBL(24) LBL(25) LBL(26) LBL(27) LBL(29) LBL(31) LBL(33)
4709      LBL(35) LBL(43) LBL(47) LBL(48) LBL(49) LBL(50) LBL(51) LBL(52)
4710      LBL(53) LBL(54)
4711    #ifdef SUPPORT_UTF8
4712      LBL(16) LBL(18) LBL(20) LBL(21) LBL(22) LBL(23) LBL(28) LBL(30)
4713      LBL(32) LBL(34) LBL(42) LBL(46)
4714    #ifdef SUPPORT_UCP
4715      LBL(36) LBL(37) LBL(38) LBL(39) LBL(40) LBL(41) LBL(44) LBL(45)
4716    #endif  /* SUPPORT_UCP */
4717    #endif  /* SUPPORT_UTF8 */
4718      default:
4719      DPRINTF(("jump error in pcre match: label %d non-existent\n", frame->Xwhere));
4720      return PCRE_ERROR_INTERNAL;
4721      }
4722    #undef LBL
4723    #endif  /* NO_RECURSE */
4724  }  }
4725    
4726    
# Line 3640  Undefine all the macros that were define Line 4733  Undefine all the macros that were define
4733  #ifdef NO_RECURSE  #ifdef NO_RECURSE
4734  #undef eptr  #undef eptr
4735  #undef ecode  #undef ecode
4736    #undef mstart
4737  #undef offset_top  #undef offset_top
4738  #undef ims  #undef ims
4739  #undef eptrb  #undef eptrb
# Line 3712  Returns: > 0 => success; value Line 4806  Returns: > 0 => success; value
4806                   < -1 => some kind of unexpected problem                   < -1 => some kind of unexpected problem
4807  */  */
4808    
4809  PCRE_DATA_SCOPE int  PCRE_EXP_DEFN int PCRE_CALL_CONVENTION
4810  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,  pcre_exec(const pcre *argument_re, const pcre_extra *extra_data,
4811    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,    PCRE_SPTR subject, int length, int start_offset, int options, int *offsets,
4812    int offsetcount)    int offsetcount)
# Line 3736  const uschar *tables; Line 4830  const uschar *tables;
4830  const uschar *start_bits = NULL;  const uschar *start_bits = NULL;
4831  USPTR start_match = (USPTR)subject + start_offset;  USPTR start_match = (USPTR)subject + start_offset;
4832  USPTR end_subject;  USPTR end_subject;
4833    USPTR start_partial = NULL;
4834  USPTR req_byte_ptr = start_match - 1;  USPTR req_byte_ptr = start_match - 1;
 eptrblock eptrchain[EPTR_WORK_SIZE];  
4835    
4836  pcre_study_data internal_study;  pcre_study_data internal_study;
4837  const pcre_study_data *study;  const pcre_study_data *study;
# Line 3800  if (re->magic_number != MAGIC_NUMBER) Line 4894  if (re->magic_number != MAGIC_NUMBER)
4894  /* Set up other data */  /* Set up other data */
4895    
4896  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;  anchored = ((re->options | options) & PCRE_ANCHORED) != 0;
4897  startline = (re->options & PCRE_STARTLINE) != 0;  startline = (re->flags & PCRE_STARTLINE) != 0;
4898  firstline = (re->options & PCRE_FIRSTLINE) != 0;  firstline = (re->options & PCRE_FIRSTLINE) != 0;
4899    
4900  /* 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 4909  end_subject = md->end_subject;
4909    
4910  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;  md->endonly = (re->options & PCRE_DOLLAR_ENDONLY) != 0;
4911  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;  utf8 = md->utf8 = (re->options & PCRE_UTF8) != 0;
4912    md->jscript_compat = (re->options & PCRE_JAVASCRIPT_COMPAT) != 0;
4913    
4914  md->notbol = (options & PCRE_NOTBOL) != 0;  md->notbol = (options & PCRE_NOTBOL) != 0;
4915  md->noteol = (options & PCRE_NOTEOL) != 0;  md->noteol = (options & PCRE_NOTEOL) != 0;
4916  md->notempty = (options & PCRE_NOTEMPTY) != 0;  md->notempty = (options & PCRE_NOTEMPTY) != 0;
4917  md->partial = (options & PCRE_PARTIAL) != 0;  md->partial = ((options & PCRE_PARTIAL_HARD) != 0)? 2 :
4918                  ((options & PCRE_PARTIAL_SOFT) != 0)? 1 : 0;
4919  md->hitend = FALSE;  md->hitend = FALSE;
4920    
4921  md->recursive = NULL;                   /* No recursion at top level */  md->recursive = NULL;                   /* No recursion at top level */
 md->eptrchain = eptrchain;              /* Make workspace generally available */  
4922    
4923  md->lcc = tables + lcc_offset;  md->lcc = tables + lcc_offset;
4924  md->ctypes = tables + ctypes_offset;  md->ctypes = tables + ctypes_offset;
4925    
4926    /* Handle different \R options. */
4927    
4928    switch (options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE))
4929      {
4930      case 0:
4931      if ((re->options & (PCRE_BSR_ANYCRLF|PCRE_BSR_UNICODE)) != 0)
4932        md->bsr_anycrlf = (re->options & PCRE_BSR_ANYCRLF) != 0;
4933      else
4934    #ifdef BSR_ANYCRLF
4935      md->bsr_anycrlf = TRUE;
4936    #else
4937      md->bsr_anycrlf = FALSE;
4938    #endif
4939      break;
4940    
4941      case PCRE_BSR_ANYCRLF:
4942      md->bsr_anycrlf = TRUE;
4943      break;
4944    
4945      case PCRE_BSR_UNICODE:
4946      md->bsr_anycrlf = FALSE;
4947      break;
4948    
4949      default: return PCRE_ERROR_BADNEWLINE;
4950      }
4951    
4952  /* Handle different types of newline. The three bits give eight cases. If  /* Handle different types of newline. The three bits give eight cases. If
4953  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. */
4954    
4955  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options : options) &  switch ((((options & PCRE_NEWLINE_BITS) == 0)? re->options :
4956         PCRE_NEWLINE_BITS)          (pcre_uint32)options) & PCRE_NEWLINE_BITS)
4957    {    {
4958    case 0: newline = NEWLINE; break;   /* Compile-time default */    case 0: newline = NEWLINE; break;   /* Compile-time default */
4959    case PCRE_NEWLINE_CR: newline = '\r'; break;    case PCRE_NEWLINE_CR: newline = CHAR_CR; break;
4960    case PCRE_NEWLINE_LF: newline = '\n'; break;    case PCRE_NEWLINE_LF: newline = CHAR_NL; break;
4961    case PCRE_NEWLINE_CR+    case PCRE_NEWLINE_CR+
4962         PCRE_NEWLINE_LF: newline = ('\r' << 8) | '\n'; break;         PCRE_NEWLINE_LF: newline = (CHAR_CR << 8) | CHAR_NL; break;
4963    case PCRE_NEWLINE_ANY: newline = -1; break;    case PCRE_NEWLINE_ANY: newline = -1; break;
4964      case PCRE_NEWLINE_ANYCRLF: newline = -2; break;
4965    default: return PCRE_ERROR_BADNEWLINE;    default: return PCRE_ERROR_BADNEWLINE;
4966    }    }
4967    
4968  if (newline < 0)  if (newline == -2)
4969      {
4970      md->nltype = NLTYPE_ANYCRLF;
4971      }
4972    else if (newline < 0)
4973    {    {
4974    md->nltype = NLTYPE_ANY;    md->nltype = NLTYPE_ANY;
4975    }    }
# Line 3863  else Line 4989  else