/[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 626 by ph10, Wed Jul 20 17:51:54 2011 UTC revision 934 by ph10, Sat Feb 25 12:30:36 2012 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-2011 University of Cambridge             Copyright (c) 1997-2012 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 82  negative to avoid the external error cod Line 82  negative to avoid the external error cod
82  #define MATCH_SKIP_ARG     (-993)  #define MATCH_SKIP_ARG     (-993)
83  #define MATCH_THEN         (-992)  #define MATCH_THEN         (-992)
84    
 /* This is a convenience macro for code that occurs many times. */  
   
 #define MRRETURN(ra) \  
   { \  
   md->mark = markptr; \  
   RRETURN(ra); \  
   }  
   
85  /* 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.
86  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,
87  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 121  Returns:     nothing Line 113  Returns:     nothing
113  */  */
114    
115  static void  static void
116  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const pcre_uchar *p, int length, BOOL is_subject, match_data *md)
117  {  {
118  unsigned int c;  unsigned int c;
119  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
# Line 148  Arguments: Line 140  Arguments:
140    md          points to match data block    md          points to match data block
141    caseless    TRUE if caseless    caseless    TRUE if caseless
142    
143  Returns:      < 0 if not matched, otherwise the number of subject bytes matched  Returns:      >= 0 the number of subject bytes matched
144                  -1 no match
145                  -2 partial match; always given if at end subject
146  */  */
147    
148  static int  static int
149  match_ref(int offset, register USPTR eptr, int length, match_data *md,  match_ref(int offset, register PCRE_PUCHAR eptr, int length, match_data *md,
150    BOOL caseless)    BOOL caseless)
151  {  {
152  USPTR eptr_start = eptr;  PCRE_PUCHAR eptr_start = eptr;
153  register USPTR p = md->start_subject + md->offset_vector[offset];  register PCRE_PUCHAR p = md->start_subject + md->offset_vector[offset];
154    
155  #ifdef PCRE_DEBUG  #ifdef PCRE_DEBUG
156  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
# Line 171  pchars(p, length, FALSE, md); Line 165  pchars(p, length, FALSE, md);
165  printf("\n");  printf("\n");
166  #endif  #endif
167    
168  /* Always fail if reference not set (and not JavaScript compatible). */  /* Always fail if reference not set (and not JavaScript compatible - in that
169    case the length is passed as zero). */
170    
171  if (length < 0) return -1;  if (length < 0) return -1;
172    
# Line 181  ASCII characters. */ Line 176  ASCII characters. */
176    
177  if (caseless)  if (caseless)
178    {    {
179  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
180  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
181    if (md->utf8)    if (md->utf)
182      {      {
183      /* Match characters up to the end of the reference. NOTE: the number of      /* Match characters up to the end of the reference. NOTE: the number of
184      bytes matched may differ, because there are some characters whose upper and      bytes matched may differ, because there are some characters whose upper and
# Line 193  if (caseless) Line 188  if (caseless)
188      the latter. It is important, therefore, to check the length along the      the latter. It is important, therefore, to check the length along the
189      reference, not along the subject (earlier code did this wrong). */      reference, not along the subject (earlier code did this wrong). */
190    
191      USPTR endptr = p + length;      PCRE_PUCHAR endptr = p + length;
192      while (p < endptr)      while (p < endptr)
193        {        {
194        int c, d;        int c, d;
195        if (eptr >= md->end_subject) return -1;        if (eptr >= md->end_subject) return -2;   /* Partial match */
196        GETCHARINC(c, eptr);        GETCHARINC(c, eptr);
197        GETCHARINC(d, p);        GETCHARINC(d, p);
198        if (c != d && c != UCD_OTHERCASE(d)) return -1;        if (c != d && c != UCD_OTHERCASE(d)) return -1;
# Line 210  if (caseless) Line 205  if (caseless)
205    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there    /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
206    is no UCP support. */    is no UCP support. */
207      {      {
     if (eptr + length > md->end_subject) return -1;  
208      while (length-- > 0)      while (length-- > 0)
209        { if (md->lcc[*p++] != md->lcc[*eptr++]) return -1; }        {
210          if (eptr >= md->end_subject) return -2;   /* Partial match */
211          if (TABLE_GET(*p, md->lcc, *p) != TABLE_GET(*eptr, md->lcc, *eptr)) return -1;
212          p++;
213          eptr++;
214          }
215      }      }
216    }    }
217    
# Line 221  are in UTF-8 mode. */ Line 220  are in UTF-8 mode. */
220    
221  else  else
222    {    {
223    if (eptr + length > md->end_subject) return -1;    while (length-- > 0)
224    while (length-- > 0) if (*p++ != *eptr++) return -1;      {
225        if (eptr >= md->end_subject) return -2;   /* Partial match */
226        if (*p++ != *eptr++) return -1;
227        }
228    }    }
229    
230  return eptr - eptr_start;  return (int)(eptr - eptr_start);
231  }  }
232    
233    
# Line 277  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM Line 279  enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM
279         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,         RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
280         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,         RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
281         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,         RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58, RM59, RM60,
282         RM61,  RM62, RM63 };         RM61,  RM62, RM63, RM64, RM65, RM66 };
283    
284  /* 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
285  versions and production versions. Note that the "rw" argument of RMATCH isn't  versions and production versions. Note that the "rw" argument of RMATCH isn't
# Line 290  actually used in this definition. */ Line 292  actually used in this definition. */
292  #define RMATCH(ra,rb,rc,rd,re,rw) \  #define RMATCH(ra,rb,rc,rd,re,rw) \
293    { \    { \
294    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
295    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1); \
296    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
297    }    }
298  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 300  actually used in this definition. */ Line 302  actually used in this definition. */
302    }    }
303  #else  #else
304  #define RMATCH(ra,rb,rc,rd,re,rw) \  #define RMATCH(ra,rb,rc,rd,re,rw) \
305    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rdepth+1)
306  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
307  #endif  #endif
308    
# Line 315  argument of match(), which never changes Line 317  argument of match(), which never changes
317    
318  #define RMATCH(ra,rb,rc,rd,re,rw)\  #define RMATCH(ra,rb,rc,rd,re,rw)\
319    {\    {\
320    heapframe *newframe = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = frame->Xnextframe;\
321    if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\    if (newframe == NULL)\
322    frame->Xwhere = rw; \      {\
323        newframe = (heapframe *)(PUBL(stack_malloc))(sizeof(heapframe));\
324        if (newframe == NULL) RRETURN(PCRE_ERROR_NOMEMORY);\
325        newframe->Xnextframe = NULL;\
326        frame->Xnextframe = newframe;\
327        }\
328      frame->Xwhere = rw;\
329    newframe->Xeptr = ra;\    newframe->Xeptr = ra;\
330    newframe->Xecode = rb;\    newframe->Xecode = rb;\
331    newframe->Xmstart = mstart;\    newframe->Xmstart = mstart;\
   newframe->Xmarkptr = markptr;\  
332    newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
333    newframe->Xeptrb = re;\    newframe->Xeptrb = re;\
334    newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
# Line 337  argument of match(), which never changes Line 344  argument of match(), which never changes
344    {\    {\
345    heapframe *oldframe = frame;\    heapframe *oldframe = frame;\
346    frame = oldframe->Xprevframe;\    frame = oldframe->Xprevframe;\
   (pcre_stack_free)(oldframe);\  
347    if (frame != NULL)\    if (frame != NULL)\
348      {\      {\
349      rrc = ra;\      rrc = ra;\
# Line 351  argument of match(), which never changes Line 357  argument of match(), which never changes
357    
358  typedef struct heapframe {  typedef struct heapframe {
359    struct heapframe *Xprevframe;    struct heapframe *Xprevframe;
360      struct heapframe *Xnextframe;
361    
362    /* Function arguments that may change */    /* Function arguments that may change */
363    
364    USPTR Xeptr;    PCRE_PUCHAR Xeptr;
365    const uschar *Xecode;    const pcre_uchar *Xecode;
366    USPTR Xmstart;    PCRE_PUCHAR Xmstart;
   USPTR Xmarkptr;  
367    int Xoffset_top;    int Xoffset_top;
368    eptrblock *Xeptrb;    eptrblock *Xeptrb;
369    unsigned int Xrdepth;    unsigned int Xrdepth;
370    
371    /* Function local variables */    /* Function local variables */
372    
373    USPTR Xcallpat;    PCRE_PUCHAR Xcallpat;
374  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
375    USPTR Xcharptr;    PCRE_PUCHAR Xcharptr;
376  #endif  #endif
377    USPTR Xdata;    PCRE_PUCHAR Xdata;
378    USPTR Xnext;    PCRE_PUCHAR Xnext;
379    USPTR Xpp;    PCRE_PUCHAR Xpp;
380    USPTR Xprev;    PCRE_PUCHAR Xprev;
381    USPTR Xsaved_eptr;    PCRE_PUCHAR Xsaved_eptr;
382    
383    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
384    
# Line 385  typedef struct heapframe { Line 391  typedef struct heapframe {
391    int Xprop_value;    int Xprop_value;
392    int Xprop_fail_result;    int Xprop_fail_result;
393    int Xoclength;    int Xoclength;
394    uschar Xocchars[8];    pcre_uchar Xocchars[6];
395  #endif  #endif
396    
397    int Xcodelink;    int Xcodelink;
# Line 427  returns a negative (error) response, the Line 433  returns a negative (error) response, the
433  same response. */  same response. */
434    
435  /* These macros pack up tests that are used for partial matching, and which  /* These macros pack up tests that are used for partial matching, and which
436  appears several times in the code. We set the "hit end" flag if the pointer is  appear several times in the code. We set the "hit end" flag if the pointer is
437  at the end of the subject and also past the start of the subject (i.e.  at the end of the subject and also past the start of the subject (i.e.
438  something has been matched). For hard partial matching, we then return  something has been matched). For hard partial matching, we then return
439  immediately. The second one is used when we already know we are past the end of  immediately. The second one is used when we already know we are past the end of
# Line 438  the subject. */ Line 444  the subject. */
444        eptr > md->start_used_ptr) \        eptr > md->start_used_ptr) \
445      { \      { \
446      md->hitend = TRUE; \      md->hitend = TRUE; \
447      if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \
448      }      }
449    
450  #define SCHECK_PARTIAL()\  #define SCHECK_PARTIAL()\
451    if (md->partial != 0 && eptr > md->start_used_ptr) \    if (md->partial != 0 && eptr > md->start_used_ptr) \
452      { \      { \
453      md->hitend = TRUE; \      md->hitend = TRUE; \
454      if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL); \      if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL); \
455      }      }
456    
457    
458  /* Performance note: It might be tempting to extract commonly used fields from  /* Performance note: It might be tempting to extract commonly used fields from
459  the md structure (e.g. utf8, end_subject) into individual variables to improve  the md structure (e.g. utf, end_subject) into individual variables to improve
460  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
461  made performance worse.  made performance worse.
462    
# Line 459  Arguments: Line 465  Arguments:
465     ecode       pointer to current position in compiled code     ecode       pointer to current position in compiled code
466     mstart      pointer to the current match start position (can be modified     mstart      pointer to the current match start position (can be modified
467                   by encountering \K)                   by encountering \K)
    markptr     pointer to the most recent MARK name, or NULL  
468     offset_top  current top pointer     offset_top  current top pointer
469     md          pointer to "static" info for the match     md          pointer to "static" info for the match
470     eptrb       pointer to chain of blocks containing eptr at start of     eptrb       pointer to chain of blocks containing eptr at start of
# Line 474  Returns:       MATCH_MATCH if matched Line 479  Returns:       MATCH_MATCH if matched
479  */  */
480    
481  static int  static int
482  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,  match(REGISTER PCRE_PUCHAR eptr, REGISTER const pcre_uchar *ecode,
483    const uschar *markptr, int offset_top, match_data *md, eptrblock *eptrb,    PCRE_PUCHAR mstart, int offset_top, match_data *md, eptrblock *eptrb,
484    unsigned int rdepth)    unsigned int rdepth)
485  {  {
486  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
# Line 485  so they can be ordinary variables in all Line 490  so they can be ordinary variables in all
490  register int  rrc;         /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
491  register int  i;           /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
492  register unsigned int c;   /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
493  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf;         /* Local copy of UTF flag for speed */
494    
495  BOOL minimize, possessive; /* Quantifier options */  BOOL minimize, possessive; /* Quantifier options */
496  BOOL caseless;  BOOL caseless;
497  int condcode;  int condcode;
498    
499  /* 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
500  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame". We set up the top-level
501  heap storage. Set up the top-level frame here; others are obtained from the  frame on the stack here; subsequent instantiations are obtained from the heap
502  heap whenever RMATCH() does a "recursion". See the macro definitions above. */  whenever RMATCH() does a "recursion". See the macro definitions above. Putting
503    the top-level on the stack rather than malloc-ing them all gives a performance
504    boost in many cases where there is not much "recursion". */
505    
506  #ifdef NO_RECURSE  #ifdef NO_RECURSE
507  heapframe *frame = (heapframe *)(pcre_stack_malloc)(sizeof(heapframe));  heapframe *frame = (heapframe *)md->match_frames_base;
 if (frame == NULL) RRETURN(PCRE_ERROR_NOMEMORY);  
 frame->Xprevframe = NULL;            /* Marks the top level */  
508    
509  /* Copy in the original argument variables */  /* Copy in the original argument variables */
510    
511  frame->Xeptr = eptr;  frame->Xeptr = eptr;
512  frame->Xecode = ecode;  frame->Xecode = ecode;
513  frame->Xmstart = mstart;  frame->Xmstart = mstart;
 frame->Xmarkptr = markptr;  
514  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
515  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
516  frame->Xrdepth = rdepth;  frame->Xrdepth = rdepth;
# Line 520  HEAP_RECURSE: Line 524  HEAP_RECURSE:
524  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
525  #define ecode              frame->Xecode  #define ecode              frame->Xecode
526  #define mstart             frame->Xmstart  #define mstart             frame->Xmstart
 #define markptr            frame->Xmarkptr  
527  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
528  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
529  #define rdepth             frame->Xrdepth  #define rdepth             frame->Xrdepth
530    
531  /* Ditto for the local variables */  /* Ditto for the local variables */
532    
533  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
534  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
535  #endif  #endif
536  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
# Line 585  declarations can be cut out in a block. Line 588  declarations can be cut out in a block.
588  below are for variables that do not have to be preserved over a recursive call  below are for variables that do not have to be preserved over a recursive call
589  to RMATCH(). */  to RMATCH(). */
590    
591  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
592  const uschar *charptr;  const pcre_uchar *charptr;
593  #endif  #endif
594  const uschar *callpat;  const pcre_uchar *callpat;
595  const uschar *data;  const pcre_uchar *data;
596  const uschar *next;  const pcre_uchar *next;
597  USPTR         pp;  PCRE_PUCHAR       pp;
598  const uschar *prev;  const pcre_uchar *prev;
599  USPTR         saved_eptr;  PCRE_PUCHAR       saved_eptr;
600    
601  recursion_info new_recursive;  recursion_info new_recursive;
602    
# Line 606  int prop_type; Line 609  int prop_type;
609  int prop_value;  int prop_value;
610  int prop_fail_result;  int prop_fail_result;
611  int oclength;  int oclength;
612  uschar occhars[8];  pcre_uchar occhars[6];
613  #endif  #endif
614    
615  int codelink;  int codelink;
# Line 622  int save_offset1, save_offset2, save_off Line 625  int save_offset1, save_offset2, save_off
625  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
626    
627  eptrblock newptrb;  eptrblock newptrb;
628    
629    /* There is a special fudge for calling match() in a way that causes it to
630    measure the size of its basic stack frame when the stack is being used for
631    recursion. The second argument (ecode) being NULL triggers this behaviour. It
632    cannot normally ever be NULL. The return is the negated value of the frame
633    size. */
634    
635    if (ecode == NULL)
636      {
637      if (rdepth == 0)
638        return match((PCRE_PUCHAR)&rdepth, NULL, NULL, 0, NULL, NULL, 1);
639      else
640        {
641        int len = (char *)&rdepth - (char *)eptr;
642        return (len > 0)? -len : len;
643        }
644      }
645  #endif     /* NO_RECURSE */  #endif     /* NO_RECURSE */
646    
647  /* To save space on the stack and in the heap frame, I have doubled up on some  /* To save space on the stack and in the heap frame, I have doubled up on some
# Line 634  the alternative names that are used. */ Line 654  the alternative names that are used. */
654  #define code_offset   codelink  #define code_offset   codelink
655  #define condassert    condition  #define condassert    condition
656  #define matched_once  prev_is_word  #define matched_once  prev_is_word
657    #define foc           number
658    #define save_mark     data
659    
660  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
661  variables. */  variables. */
# Line 659  defined). However, RMATCH isn't like a f Line 681  defined). However, RMATCH isn't like a f
681  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,
682  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
683    
684  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
685  utf8 = md->utf8;       /* Local copy of the flag */  utf = md->utf;       /* Local copy of the flag */
686  #else  #else
687  utf8 = FALSE;  utf = FALSE;
688  #endif  #endif
689    
690  /* 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
# Line 701  for (;;) Line 723  for (;;)
723    switch(op)    switch(op)
724      {      {
725      case OP_MARK:      case OP_MARK:
726      markptr = ecode + 2;      md->nomatch_mark = ecode + 2;
727      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      md->mark = NULL;    /* In case previously set by assertion */
728        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
729        eptrb, RM55);        eptrb, RM55);
730        if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
731             md->mark == NULL) md->mark = ecode + 2;
732    
733      /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an      /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
734      argument, and we must check whether that argument matches this MARK's      argument, and we must check whether that argument matches this MARK's
# Line 712  for (;;) Line 737  for (;;)
737      position and return MATCH_SKIP. Otherwise, pass back the return code      position and return MATCH_SKIP. Otherwise, pass back the return code
738      unaltered. */      unaltered. */
739    
740      if (rrc == MATCH_SKIP_ARG &&      else if (rrc == MATCH_SKIP_ARG &&
741          strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)          STRCMP_UC_UC(ecode + 2, md->start_match_ptr) == 0)
742        {        {
743        md->start_match_ptr = eptr;        md->start_match_ptr = eptr;
744        RRETURN(MATCH_SKIP);        RRETURN(MATCH_SKIP);
745        }        }
   
     if (md->mark == NULL) md->mark = markptr;  
746      RRETURN(rrc);      RRETURN(rrc);
747    
748      case OP_FAIL:      case OP_FAIL:
749      MRRETURN(MATCH_NOMATCH);      RRETURN(MATCH_NOMATCH);
750    
751      /* COMMIT overrides PRUNE, SKIP, and THEN */      /* COMMIT overrides PRUNE, SKIP, and THEN */
752    
753      case OP_COMMIT:      case OP_COMMIT:
754      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
755        eptrb, RM52);        eptrb, RM52);
756      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE &&
757          rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&          rrc != MATCH_SKIP && rrc != MATCH_SKIP_ARG &&
758          rrc != MATCH_THEN)          rrc != MATCH_THEN)
759        RRETURN(rrc);        RRETURN(rrc);
760      MRRETURN(MATCH_COMMIT);      RRETURN(MATCH_COMMIT);
761    
762      /* PRUNE overrides THEN */      /* PRUNE overrides THEN */
763    
764      case OP_PRUNE:      case OP_PRUNE:
765      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
766        eptrb, RM51);        eptrb, RM51);
767      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
768      MRRETURN(MATCH_PRUNE);      RRETURN(MATCH_PRUNE);
769    
770      case OP_PRUNE_ARG:      case OP_PRUNE_ARG:
771      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      md->nomatch_mark = ecode + 2;
772        md->mark = NULL;    /* In case previously set by assertion */
773        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
774        eptrb, RM56);        eptrb, RM56);
775        if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
776             md->mark == NULL) md->mark = ecode + 2;
777      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);      if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
     md->mark = ecode + 2;  
778      RRETURN(MATCH_PRUNE);      RRETURN(MATCH_PRUNE);
779    
780      /* SKIP overrides PRUNE and THEN */      /* SKIP overrides PRUNE and THEN */
781    
782      case OP_SKIP:      case OP_SKIP:
783      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
784        eptrb, RM53);        eptrb, RM53);
785      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
786        RRETURN(rrc);        RRETURN(rrc);
787      md->start_match_ptr = eptr;   /* Pass back current position */      md->start_match_ptr = eptr;   /* Pass back current position */
788      MRRETURN(MATCH_SKIP);      RRETURN(MATCH_SKIP);
789    
790        /* Note that, for Perl compatibility, SKIP with an argument does NOT set
791        nomatch_mark. There is a flag that disables this opcode when re-matching a
792        pattern that ended with a SKIP for which there was not a matching MARK. */
793    
794      case OP_SKIP_ARG:      case OP_SKIP_ARG:
795      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,      if (md->ignore_skip_arg)
796          {
797          ecode += PRIV(OP_lengths)[*ecode] + ecode[1];
798          break;
799          }
800        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top, md,
801        eptrb, RM57);        eptrb, RM57);
802      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)      if (rrc != MATCH_NOMATCH && rrc != MATCH_PRUNE && rrc != MATCH_THEN)
803        RRETURN(rrc);        RRETURN(rrc);
804    
805      /* Pass back the current skip name by overloading md->start_match_ptr and      /* Pass back the current skip name by overloading md->start_match_ptr and
806      returning the special MATCH_SKIP_ARG return code. This will either be      returning the special MATCH_SKIP_ARG return code. This will either be
807      caught by a matching MARK, or get to the top, where it is treated the same      caught by a matching MARK, or get to the top, where it causes a rematch
808      as PRUNE. */      with the md->ignore_skip_arg flag set. */
809    
810      md->start_match_ptr = ecode + 2;      md->start_match_ptr = ecode + 2;
811      RRETURN(MATCH_SKIP_ARG);      RRETURN(MATCH_SKIP_ARG);
812    
813      /* For THEN (and THEN_ARG) we pass back the address of the bracket or      /* For THEN (and THEN_ARG) we pass back the address of the opcode, so that
814      the alt that is at the start of the current branch. This makes it possible      the branch in which it occurs can be determined. Overload the start of
815      to skip back past alternatives that precede the THEN within the current      match pointer to do this. */
     branch. */  
816    
817      case OP_THEN:      case OP_THEN:
818      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,      RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
819        eptrb, RM54);        eptrb, RM54);
820      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
821      md->start_match_ptr = ecode - GET(ecode, 1);      md->start_match_ptr = ecode;
822      MRRETURN(MATCH_THEN);      RRETURN(MATCH_THEN);
823    
824      case OP_THEN_ARG:      case OP_THEN_ARG:
825      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1+LINK_SIZE],      md->nomatch_mark = ecode + 2;
826        offset_top, md, eptrb, RM58);      md->mark = NULL;    /* In case previously set by assertion */
827        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode] + ecode[1], offset_top,
828          md, eptrb, RM58);
829        if ((rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) &&
830             md->mark == NULL) md->mark = ecode + 2;
831      if (rrc != MATCH_NOMATCH) RRETURN(rrc);      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
832      md->start_match_ptr = ecode - GET(ecode, 1);      md->start_match_ptr = ecode;
     md->mark = ecode + LINK_SIZE + 2;  
833      RRETURN(MATCH_THEN);      RRETURN(MATCH_THEN);
834    
835        /* Handle an atomic group that does not contain any capturing parentheses.
836        This can be handled like an assertion. Prior to 8.13, all atomic groups
837        were handled this way. In 8.13, the code was changed as below for ONCE, so
838        that backups pass through the group and thereby reset captured values.
839        However, this uses a lot more stack, so in 8.20, atomic groups that do not
840        contain any captures generate OP_ONCE_NC, which can be handled in the old,
841        less stack intensive way.
842    
843        Check the alternative branches in turn - the matching won't pass the KET
844        for this kind of subpattern. If any one branch matches, we carry on as at
845        the end of a normal bracket, leaving the subject pointer, but resetting
846        the start-of-match value in case it was changed by \K. */
847    
848        case OP_ONCE_NC:
849        prev = ecode;
850        saved_eptr = eptr;
851        save_mark = md->mark;
852        do
853          {
854          RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM64);
855          if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
856            {
857            mstart = md->start_match_ptr;
858            break;
859            }
860          if (rrc == MATCH_THEN)
861            {
862            next = ecode + GET(ecode,1);
863            if (md->start_match_ptr < next &&
864                (*ecode == OP_ALT || *next == OP_ALT))
865              rrc = MATCH_NOMATCH;
866            }
867    
868          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
869          ecode += GET(ecode,1);
870          md->mark = save_mark;
871          }
872        while (*ecode == OP_ALT);
873    
874        /* If hit the end of the group (which could be repeated), fail */
875    
876        if (*ecode != OP_ONCE_NC && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
877    
878        /* Continue as from after the group, updating the offsets high water
879        mark, since extracts may have been taken. */
880    
881        do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
882    
883        offset_top = md->end_offset_top;
884        eptr = md->end_match_ptr;
885    
886        /* For a non-repeating ket, just continue at this level. This also
887        happens for a repeating ket if no characters were matched in the group.
888        This is the forcible breaking of infinite loops as implemented in Perl
889        5.005. */
890    
891        if (*ecode == OP_KET || eptr == saved_eptr)
892          {
893          ecode += 1+LINK_SIZE;
894          break;
895          }
896    
897        /* The repeating kets try the rest of the pattern or restart from the
898        preceding bracket, in the appropriate order. The second "call" of match()
899        uses tail recursion, to avoid using another stack frame. */
900    
901        if (*ecode == OP_KETRMIN)
902          {
903          RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM65);
904          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
905          ecode = prev;
906          goto TAIL_RECURSE;
907          }
908        else  /* OP_KETRMAX */
909          {
910          md->match_function_type = MATCH_CBEGROUP;
911          RMATCH(eptr, prev, offset_top, md, eptrb, RM66);
912          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
913          ecode += 1 + LINK_SIZE;
914          goto TAIL_RECURSE;
915          }
916        /* Control never gets here */
917    
918      /* Handle a capturing bracket, other than those that are possessive with an      /* Handle a capturing bracket, other than those that are possessive with an
919      unlimited repeat. If there is space in the offset vector, save the current      unlimited repeat. If there is space in the offset vector, save the current
920      subject position in the working slot at the top of the vector. We mustn't      subject position in the working slot at the top of the vector. We mustn't
# Line 827  for (;;) Line 947  for (;;)
947        save_offset2 = md->offset_vector[offset+1];        save_offset2 = md->offset_vector[offset+1];
948        save_offset3 = md->offset_vector[md->offset_end - number];        save_offset3 = md->offset_vector[md->offset_end - number];
949        save_capture_last = md->capture_last;        save_capture_last = md->capture_last;
950          save_mark = md->mark;
951    
952        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
953        md->offset_vector[md->offset_end - number] =        md->offset_vector[md->offset_end - number] =
# Line 835  for (;;) Line 956  for (;;)
956        for (;;)        for (;;)
957          {          {
958          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
959          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
960            eptrb, RM1);            eptrb, RM1);
961          if (rrc == MATCH_ONCE) break;  /* Backing up through an atomic group */          if (rrc == MATCH_ONCE) break;  /* Backing up through an atomic group */
962          if (rrc != MATCH_NOMATCH &&  
963              (rrc != MATCH_THEN || md->start_match_ptr != ecode))          /* If we backed up to a THEN, check whether it is within the current
964            RRETURN(rrc);          branch by comparing the address of the THEN that is passed back with
965            the end of the branch. If it is within the current branch, and the
966            branch is one of two or more alternatives (it either starts or ends
967            with OP_ALT), we have reached the limit of THEN's action, so convert
968            the return code to NOMATCH, which will cause normal backtracking to
969            happen from now on. Otherwise, THEN is passed back to an outer
970            alternative. This implements Perl's treatment of parenthesized groups,
971            where a group not containing | does not affect the current alternative,
972            that is, (X) is NOT the same as (X|(*F)). */
973    
974            if (rrc == MATCH_THEN)
975              {
976              next = ecode + GET(ecode,1);
977              if (md->start_match_ptr < next &&
978                  (*ecode == OP_ALT || *next == OP_ALT))
979                rrc = MATCH_NOMATCH;
980              }
981    
982            /* Anything other than NOMATCH is passed back. */
983    
984            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
985          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
986          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
987            md->mark = save_mark;
988          if (*ecode != OP_ALT) break;          if (*ecode != OP_ALT) break;
989          }          }
990    
# Line 851  for (;;) Line 993  for (;;)
993        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
994        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
995    
996        /* At this point, rrc will be one of MATCH_ONCE, MATCH_NOMATCH, or        /* At this point, rrc will be one of MATCH_ONCE or MATCH_NOMATCH. */
       MATCH_THEN. */  
997    
998        if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;        RRETURN(rrc);
       RRETURN(((rrc == MATCH_ONCE)? MATCH_ONCE:MATCH_NOMATCH));  
999        }        }
1000    
1001      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
# Line 870  for (;;) Line 1010  for (;;)
1010      /* VVVVVVVVVVVVVVVVVVVVVVVVV */      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
1011    
1012      /* Non-capturing or atomic group, except for possessive with unlimited      /* Non-capturing or atomic group, except for possessive with unlimited
1013      repeat. Loop for all the alternatives. When we get to the final alternative      repeat and ONCE group with no captures. Loop for all the alternatives.
1014      within the brackets, we used to return the result of a recursive call to  
1015      match() whatever happened so it was possible to reduce stack usage by      When we get to the final alternative within the brackets, we used to return
1016      turning this into a tail recursion, except in the case of a possibly empty      the result of a recursive call to match() whatever happened so it was
1017      group. However, now that there is the possiblity of (*THEN) occurring in      possible to reduce stack usage by turning this into a tail recursion,
1018      the final alternative, this optimization is no longer possible.      except in the case of a possibly empty group. However, now that there is
1019        the possiblity of (*THEN) occurring in the final alternative, this
1020        optimization is no longer always possible.
1021    
1022        We can optimize if we know there are no (*THEN)s in the pattern; at present
1023        this is the best that can be done.
1024    
1025      MATCH_ONCE is returned when the end of an atomic group is successfully      MATCH_ONCE is returned when the end of an atomic group is successfully
1026      reached, but subsequent matching fails. It passes back up the tree (causing      reached, but subsequent matching fails. It passes back up the tree (causing
# Line 892  for (;;) Line 1037  for (;;)
1037      for (;;)      for (;;)
1038        {        {
1039        if (op >= OP_SBRA || op == OP_ONCE) md->match_function_type = MATCH_CBEGROUP;        if (op >= OP_SBRA || op == OP_ONCE) md->match_function_type = MATCH_CBEGROUP;
1040        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, eptrb,  
1041          /* If this is not a possibly empty group, and there are no (*THEN)s in
1042          the pattern, and this is the final alternative, optimize as described
1043          above. */
1044    
1045          else if (!md->hasthen && ecode[GET(ecode, 1)] != OP_ALT)
1046            {
1047            ecode += PRIV(OP_lengths)[*ecode];
1048            goto TAIL_RECURSE;
1049            }
1050    
1051          /* In all other cases, we have to make another call to match(). */
1052    
1053          save_mark = md->mark;
1054          RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md, eptrb,
1055          RM2);          RM2);
1056        if (rrc != MATCH_NOMATCH &&  
1057            (rrc != MATCH_THEN || md->start_match_ptr != ecode))        /* See comment in the code for capturing groups above about handling
1058          THEN. */
1059    
1060          if (rrc == MATCH_THEN)
1061            {
1062            next = ecode + GET(ecode,1);
1063            if (md->start_match_ptr < next &&
1064                (*ecode == OP_ALT || *next == OP_ALT))
1065              rrc = MATCH_NOMATCH;
1066            }
1067    
1068          if (rrc != MATCH_NOMATCH)
1069          {          {
1070          if (rrc == MATCH_ONCE)          if (rrc == MATCH_ONCE)
1071            {            {
1072            const uschar *scode = ecode;            const pcre_uchar *scode = ecode;
1073            if (*scode != OP_ONCE)           /* If not at start, find it */            if (*scode != OP_ONCE)           /* If not at start, find it */
1074              {              {
1075              while (*scode == OP_ALT) scode += GET(scode, 1);              while (*scode == OP_ALT) scode += GET(scode, 1);
# Line 910  for (;;) Line 1080  for (;;)
1080          RRETURN(rrc);          RRETURN(rrc);
1081          }          }
1082        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1083          md->mark = save_mark;
1084        if (*ecode != OP_ALT) break;        if (*ecode != OP_ALT) break;
1085        }        }
1086      if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;  
1087      RRETURN(MATCH_NOMATCH);      RRETURN(MATCH_NOMATCH);
1088    
1089      /* Handle possessive capturing brackets with an unlimited repeat. We come      /* Handle possessive capturing brackets with an unlimited repeat. We come
# Line 941  for (;;) Line 1112  for (;;)
1112      if (offset < md->offset_max)      if (offset < md->offset_max)
1113        {        {
1114        matched_once = FALSE;        matched_once = FALSE;
1115        code_offset = ecode - md->start_code;        code_offset = (int)(ecode - md->start_code);
1116    
1117        save_offset1 = md->offset_vector[offset];        save_offset1 = md->offset_vector[offset];
1118        save_offset2 = md->offset_vector[offset+1];        save_offset2 = md->offset_vector[offset+1];
# Line 964  for (;;) Line 1135  for (;;)
1135          md->offset_vector[md->offset_end - number] =          md->offset_vector[md->offset_end - number] =
1136            (int)(eptr - md->start_subject);            (int)(eptr - md->start_subject);
1137          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;          if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1138          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,          RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
1139            eptrb, RM63);            eptrb, RM63);
1140          if (rrc == MATCH_KETRPOS)          if (rrc == MATCH_KETRPOS)
1141            {            {
# Line 975  for (;;) Line 1146  for (;;)
1146            matched_once = TRUE;            matched_once = TRUE;
1147            continue;            continue;
1148            }            }
1149          if (rrc != MATCH_NOMATCH &&  
1150              (rrc != MATCH_THEN || md->start_match_ptr != ecode))          /* See comment in the code for capturing groups above about handling
1151            RRETURN(rrc);          THEN. */
1152    
1153            if (rrc == MATCH_THEN)
1154              {
1155              next = ecode + GET(ecode,1);
1156              if (md->start_match_ptr < next &&
1157                  (*ecode == OP_ALT || *next == OP_ALT))
1158                rrc = MATCH_NOMATCH;
1159              }
1160    
1161            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1162          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
1163          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
1164          if (*ecode != OP_ALT) break;          if (*ecode != OP_ALT) break;
# Line 990  for (;;) Line 1171  for (;;)
1171          md->offset_vector[md->offset_end - number] = save_offset3;          md->offset_vector[md->offset_end - number] = save_offset3;
1172          }          }
1173    
       if (rrc != MATCH_THEN && md->mark == NULL) md->mark = markptr;  
1174        if (allow_zero || matched_once)        if (allow_zero || matched_once)
1175          {          {
1176          ecode += 1 + LINK_SIZE;          ecode += 1 + LINK_SIZE;
# Line 1022  for (;;) Line 1202  for (;;)
1202    
1203      POSSESSIVE_NON_CAPTURE:      POSSESSIVE_NON_CAPTURE:
1204      matched_once = FALSE;      matched_once = FALSE;
1205      code_offset = ecode - md->start_code;      code_offset = (int)(ecode - md->start_code);
1206    
1207      for (;;)      for (;;)
1208        {        {
1209        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;        if (op >= OP_SBRA) md->match_function_type = MATCH_CBEGROUP;
1210        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,        RMATCH(eptr, ecode + PRIV(OP_lengths)[*ecode], offset_top, md,
1211          eptrb, RM48);          eptrb, RM48);
1212        if (rrc == MATCH_KETRPOS)        if (rrc == MATCH_KETRPOS)
1213          {          {
# Line 1037  for (;;) Line 1217  for (;;)
1217          matched_once = TRUE;          matched_once = TRUE;
1218          continue;          continue;
1219          }          }
1220        if (rrc != MATCH_NOMATCH &&  
1221            (rrc != MATCH_THEN || md->start_match_ptr != ecode))        /* See comment in the code for capturing groups above about handling
1222          RRETURN(rrc);        THEN. */
1223    
1224          if (rrc == MATCH_THEN)
1225            {
1226            next = ecode + GET(ecode,1);
1227            if (md->start_match_ptr < next &&
1228                (*ecode == OP_ALT || *next == OP_ALT))
1229              rrc = MATCH_NOMATCH;
1230            }
1231    
1232          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1233        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1234        if (*ecode != OP_ALT) break;        if (*ecode != OP_ALT) break;
1235        }        }
# Line 1067  for (;;) Line 1257  for (;;)
1257    
1258      if (ecode[LINK_SIZE+1] == OP_CALLOUT)      if (ecode[LINK_SIZE+1] == OP_CALLOUT)
1259        {        {
1260        if (pcre_callout != NULL)        if (PUBL(callout) != NULL)
1261          {          {
1262          pcre_callout_block cb;          PUBL(callout_block) cb;
1263          cb.version          = 1;   /* Version 1 of the callout block */          cb.version          = 2;   /* Version 1 of the callout block */
1264          cb.callout_number   = ecode[LINK_SIZE+2];          cb.callout_number   = ecode[LINK_SIZE+2];
1265          cb.offset_vector    = md->offset_vector;          cb.offset_vector    = md->offset_vector;
1266    #ifdef COMPILE_PCRE8
1267          cb.subject          = (PCRE_SPTR)md->start_subject;          cb.subject          = (PCRE_SPTR)md->start_subject;
1268    #else
1269            cb.subject          = (PCRE_SPTR16)md->start_subject;
1270    #endif
1271          cb.subject_length   = (int)(md->end_subject - md->start_subject);          cb.subject_length   = (int)(md->end_subject - md->start_subject);
1272          cb.start_match      = (int)(mstart - md->start_subject);          cb.start_match      = (int)(mstart - md->start_subject);
1273          cb.current_position = (int)(eptr - md->start_subject);          cb.current_position = (int)(eptr - md->start_subject);
# Line 1082  for (;;) Line 1276  for (;;)
1276          cb.capture_top      = offset_top/2;          cb.capture_top      = offset_top/2;
1277          cb.capture_last     = md->capture_last;          cb.capture_last     = md->capture_last;
1278          cb.callout_data     = md->callout_data;          cb.callout_data     = md->callout_data;
1279          if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);          cb.mark             = md->nomatch_mark;
1280            if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1281          if (rrc < 0) RRETURN(rrc);          if (rrc < 0) RRETURN(rrc);
1282          }          }
1283        ecode += _pcre_OP_lengths[OP_CALLOUT];        ecode += PRIV(OP_lengths)[OP_CALLOUT];
1284        }        }
1285    
1286      condcode = ecode[LINK_SIZE+1];      condcode = ecode[LINK_SIZE+1];
# Line 1102  for (;;) Line 1297  for (;;)
1297        else        else
1298          {          {
1299          int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/          int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
1300          condition =  (recno == RREF_ANY || recno == md->recursive->group_num);          condition = (recno == RREF_ANY || recno == md->recursive->group_num);
1301    
1302          /* If the test is for recursion into a specific subpattern, and it is          /* If the test is for recursion into a specific subpattern, and it is
1303          false, but the test was set up by name, scan the table to see if the          false, but the test was set up by name, scan the table to see if the
1304          name refers to any other numbers, and test them. The condition is true          name refers to any other numbers, and test them. The condition is true
1305          if any one is set. */          if any one is set. */
1306    
1307          if (!condition && condcode == OP_NRREF && recno != RREF_ANY)          if (!condition && condcode == OP_NRREF)
1308            {            {
1309            uschar *slotA = md->name_table;            pcre_uchar *slotA = md->name_table;
1310            for (i = 0; i < md->name_count; i++)            for (i = 0; i < md->name_count; i++)
1311              {              {
1312              if (GET2(slotA, 0) == recno) break;              if (GET2(slotA, 0) == recno) break;
# Line 1124  for (;;) Line 1319  for (;;)
1319    
1320            if (i < md->name_count)            if (i < md->name_count)
1321              {              {
1322              uschar *slotB = slotA;              pcre_uchar *slotB = slotA;
1323              while (slotB > md->name_table)              while (slotB > md->name_table)
1324                {                {
1325                slotB -= md->name_entry_size;                slotB -= md->name_entry_size;
1326                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)                if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1327                  {                  {
1328                  condition = GET2(slotB, 0) == md->recursive->group_num;                  condition = GET2(slotB, 0) == md->recursive->group_num;
1329                  if (condition) break;                  if (condition) break;
# Line 1144  for (;;) Line 1339  for (;;)
1339                for (i++; i < md->name_count; i++)                for (i++; i < md->name_count; i++)
1340                  {                  {
1341                  slotB += md->name_entry_size;                  slotB += md->name_entry_size;
1342                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)                  if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1343                    {                    {
1344                    condition = GET2(slotB, 0) == md->recursive->group_num;                    condition = GET2(slotB, 0) == md->recursive->group_num;
1345                    if (condition) break;                    if (condition) break;
# Line 1157  for (;;) Line 1352  for (;;)
1352    
1353          /* Chose branch according to the condition */          /* Chose branch according to the condition */
1354    
1355          ecode += condition? 3 : GET(ecode, 1);          ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1);
1356          }          }
1357        }        }
1358    
# Line 1174  for (;;) Line 1369  for (;;)
1369        if (!condition && condcode == OP_NCREF)        if (!condition && condcode == OP_NCREF)
1370          {          {
1371          int refno = offset >> 1;          int refno = offset >> 1;
1372          uschar *slotA = md->name_table;          pcre_uchar *slotA = md->name_table;
1373    
1374          for (i = 0; i < md->name_count; i++)          for (i = 0; i < md->name_count; i++)
1375            {            {
# Line 1188  for (;;) Line 1383  for (;;)
1383    
1384          if (i < md->name_count)          if (i < md->name_count)
1385            {            {
1386            uschar *slotB = slotA;            pcre_uchar *slotB = slotA;
1387            while (slotB > md->name_table)            while (slotB > md->name_table)
1388              {              {
1389              slotB -= md->name_entry_size;              slotB -= md->name_entry_size;
1390              if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)              if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1391                {                {
1392                offset = GET2(slotB, 0) << 1;                offset = GET2(slotB, 0) << 1;
1393                condition = offset < offset_top &&                condition = offset < offset_top &&
# Line 1210  for (;;) Line 1405  for (;;)
1405              for (i++; i < md->name_count; i++)              for (i++; i < md->name_count; i++)
1406                {                {
1407                slotB += md->name_entry_size;                slotB += md->name_entry_size;
1408                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)                if (STRCMP_UC_UC(slotA + IMM2_SIZE, slotB + IMM2_SIZE) == 0)
1409                  {                  {
1410                  offset = GET2(slotB, 0) << 1;                  offset = GET2(slotB, 0) << 1;
1411                  condition = offset < offset_top &&                  condition = offset < offset_top &&
# Line 1225  for (;;) Line 1420  for (;;)
1420    
1421        /* Chose branch according to the condition */        /* Chose branch according to the condition */
1422    
1423        ecode += condition? 3 : GET(ecode, 1);        ecode += condition? 1 + IMM2_SIZE : GET(ecode, 1);
1424        }        }
1425    
1426      else if (condcode == OP_DEF)     /* DEFINE - always false */      else if (condcode == OP_DEF)     /* DEFINE - always false */
# Line 1250  for (;;) Line 1445  for (;;)
1445          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1446          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1447          }          }
1448        else if (rrc != MATCH_NOMATCH &&  
1449                (rrc != MATCH_THEN || md->start_match_ptr != ecode))        /* PCRE doesn't allow the effect of (*THEN) to escape beyond an
1450          assertion; it is therefore treated as NOMATCH. */
1451    
1452          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1453          {          {
1454          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1455          }          }
# Line 1262  for (;;) Line 1460  for (;;)
1460          }          }
1461        }        }
1462    
1463      /* 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, can
1464      we used to use tail recursion to avoid using another stack frame, except      use tail recursion to avoid using another stack frame, except when there is
1465      when there was unlimited repeat of a possibly empty group. However, that      unlimited repeat of a possibly empty group. In the latter case, a recursive
1466      strategy no longer works because of the possibilty of (*THEN) being      call to match() is always required, unless the second alternative doesn't
1467      encountered in the branch. A recursive call to match() is always required,      exist, in which case we can just plough on. Note that, for compatibility
1468      unless the second alternative doesn't exist, in which case we can just      with Perl, the | in a conditional group is NOT treated as creating two
1469      plough on. */      alternatives. If a THEN is encountered in the branch, it propagates out to
1470        the enclosing alternative (unless nested in a deeper set of alternatives,
1471        of course). */
1472    
1473      if (condition || *ecode == OP_ALT)      if (condition || *ecode == OP_ALT)
1474        {        {
1475        if (op == OP_SCOND) md->match_function_type = MATCH_CBEGROUP;        if (op != OP_SCOND)
1476            {
1477            ecode += 1 + LINK_SIZE;
1478            goto TAIL_RECURSE;
1479            }
1480    
1481          md->match_function_type = MATCH_CBEGROUP;
1482        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49);
       if (rrc == MATCH_THEN && md->start_match_ptr == ecode)  
         rrc = MATCH_NOMATCH;  
1483        RRETURN(rrc);        RRETURN(rrc);
1484        }        }
1485      else                         /* Condition false & no alternative */  
1486         /* Condition false & no alternative; continue after the group. */
1487    
1488        else
1489        {        {
1490        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1491        }        }
# Line 1305  for (;;) Line 1512  for (;;)
1512        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);        md->offset_vector[offset+1] = (int)(eptr - md->start_subject);
1513        if (offset_top <= offset) offset_top = offset + 2;        if (offset_top <= offset) offset_top = offset + 2;
1514        }        }
1515      ecode += 3;      ecode += 1 + IMM2_SIZE;
1516      break;      break;
1517    
1518    
# Line 1325  for (;;) Line 1532  for (;;)
1532           (md->notempty ||           (md->notempty ||
1533             (md->notempty_atstart &&             (md->notempty_atstart &&
1534               mstart == md->start_subject + md->start_offset)))               mstart == md->start_subject + md->start_offset)))
1535        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1536    
1537      /* Otherwise, we have a match. */      /* Otherwise, we have a match. */
1538    
# Line 1334  for (;;) Line 1541  for (;;)
1541      md->start_match_ptr = mstart;       /* and the start (\K can modify) */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1542    
1543      /* For some reason, the macros don't work properly if an expression is      /* For some reason, the macros don't work properly if an expression is
1544      given as the argument to MRRETURN when the heap is in use. */      given as the argument to RRETURN when the heap is in use. */
1545    
1546      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1547      MRRETURN(rrc);      RRETURN(rrc);
1548    
1549      /* Assertion brackets. Check the alternative branches in turn - the      /* Assertion brackets. Check the alternative branches in turn - the
1550      matching won't pass the KET for an assertion. If any one branch matches,      matching won't pass the KET for an assertion. If any one branch matches,
# Line 1352  for (;;) Line 1559  for (;;)
1559    
1560      case OP_ASSERT:      case OP_ASSERT:
1561      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1562        save_mark = md->mark;
1563      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1564        {        {
1565        condassert = TRUE;        condassert = TRUE;
# Line 1367  for (;;) Line 1575  for (;;)
1575          mstart = md->start_match_ptr;   /* In case \K reset it */          mstart = md->start_match_ptr;   /* In case \K reset it */
1576          break;          break;
1577          }          }
1578        if (rrc != MATCH_NOMATCH &&  
1579            (rrc != MATCH_THEN || md->start_match_ptr != ecode))        /* PCRE does not allow THEN to escape beyond an assertion; it is treated
1580          RRETURN(rrc);        as NOMATCH. */
1581    
1582          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1583        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1584          md->mark = save_mark;
1585        }        }
1586      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1587    
1588      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);
1589    
1590      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1591    
# Line 1394  for (;;) Line 1605  for (;;)
1605    
1606      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1607      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1608        save_mark = md->mark;
1609      if (md->match_function_type == MATCH_CONDASSERT)      if (md->match_function_type == MATCH_CONDASSERT)
1610        {        {
1611        condassert = TRUE;        condassert = TRUE;
# Line 1404  for (;;) Line 1616  for (;;)
1616      do      do
1617        {        {
1618        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, NULL, RM5);
1619        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);        md->mark = save_mark;
1620          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) RRETURN(MATCH_NOMATCH);
1621        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1622          {          {
1623          do ecode += GET(ecode,1); while (*ecode == OP_ALT);          do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1624          break;          break;
1625          }          }
1626        if (rrc != MATCH_NOMATCH &&  
1627            (rrc != MATCH_THEN || md->start_match_ptr != ecode))        /* PCRE does not allow THEN to escape beyond an assertion; it is treated
1628          RRETURN(rrc);        as NOMATCH. */
1629    
1630          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1631        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1632        }        }
1633      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 1428  for (;;) Line 1643  for (;;)
1643      back a number of characters, not bytes. */      back a number of characters, not bytes. */
1644    
1645      case OP_REVERSE:      case OP_REVERSE:
1646  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
1647      if (utf8)      if (utf)
1648        {        {
1649        i = GET(ecode, 1);        i = GET(ecode, 1);
1650        while (i-- > 0)        while (i-- > 0)
1651          {          {
1652          eptr--;          eptr--;
1653          if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1654          BACKCHAR(eptr);          BACKCHAR(eptr);
1655          }          }
1656        }        }
# Line 1446  for (;;) Line 1661  for (;;)
1661    
1662        {        {
1663        eptr -= GET(ecode, 1);        eptr -= GET(ecode, 1);
1664        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1665        }        }
1666    
1667      /* Save the earliest consulted character, then skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
# Line 1460  for (;;) Line 1675  for (;;)
1675      function is able to force a failure. */      function is able to force a failure. */
1676    
1677      case OP_CALLOUT:      case OP_CALLOUT:
1678      if (pcre_callout != NULL)      if (PUBL(callout) != NULL)
1679        {        {
1680        pcre_callout_block cb;        PUBL(callout_block) cb;
1681        cb.version          = 1;   /* Version 1 of the callout block */        cb.version          = 2;   /* Version 1 of the callout block */
1682        cb.callout_number   = ecode[1];        cb.callout_number   = ecode[1];
1683        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1684    #ifdef COMPILE_PCRE8
1685        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1686    #else
1687          cb.subject          = (PCRE_SPTR16)md->start_subject;
1688    #endif
1689        cb.subject_length   = (int)(md->end_subject - md->start_subject);        cb.subject_length   = (int)(md->end_subject - md->start_subject);
1690        cb.start_match      = (int)(mstart - md->start_subject);        cb.start_match      = (int)(mstart - md->start_subject);
1691        cb.current_position = (int)(eptr - md->start_subject);        cb.current_position = (int)(eptr - md->start_subject);
# Line 1475  for (;;) Line 1694  for (;;)
1694        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1695        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1696        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1697        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);        cb.mark             = md->nomatch_mark;
1698          if ((rrc = (*PUBL(callout))(&cb)) > 0) RRETURN(MATCH_NOMATCH);
1699        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1700        }        }
1701      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 1500  for (;;) Line 1720  for (;;)
1720    
1721      case OP_RECURSE:      case OP_RECURSE:
1722        {        {
1723          recursion_info *ri;
1724          int recno;
1725    
1726        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1727        new_recursive.group_num = (callpat == md->start_code)? 0 :        recno = (callpat == md->start_code)? 0 :
1728          GET2(callpat, 1 + LINK_SIZE);          GET2(callpat, 1 + LINK_SIZE);
1729    
1730          /* Check for repeating a recursion without advancing the subject pointer.
1731          This should catch convoluted mutual recursions. (Some simple cases are
1732          caught at compile time.) */
1733    
1734          for (ri = md->recursive; ri != NULL; ri = ri->prevrec)
1735            if (recno == ri->group_num && eptr == ri->subject_position)
1736              RRETURN(PCRE_ERROR_RECURSELOOP);
1737    
1738        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1739    
1740          new_recursive.group_num = recno;
1741          new_recursive.subject_position = eptr;
1742        new_recursive.prevrec = md->recursive;        new_recursive.prevrec = md->recursive;
1743        md->recursive = &new_recursive;        md->recursive = &new_recursive;
1744    
# Line 1521  for (;;) Line 1754  for (;;)
1754        else        else
1755          {          {
1756          new_recursive.offset_save =          new_recursive.offset_save =
1757            (int *)(pcre_malloc)(new_recursive.saved_max * sizeof(int));            (int *)(PUBL(malloc))(new_recursive.saved_max * sizeof(int));
1758          if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);          if (new_recursive.offset_save == NULL) RRETURN(PCRE_ERROR_NOMEMORY);
1759          }          }
1760        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
# Line 1536  for (;;) Line 1769  for (;;)
1769        do        do
1770          {          {
1771          if (cbegroup) md->match_function_type = MATCH_CBEGROUP;          if (cbegroup) md->match_function_type = MATCH_CBEGROUP;
1772          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,          RMATCH(eptr, callpat + PRIV(OP_lengths)[*callpat], offset_top,
1773            md, eptrb, RM6);            md, eptrb, RM6);
1774          memcpy(md->offset_vector, new_recursive.offset_save,          memcpy(md->offset_vector, new_recursive.offset_save,
1775              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1776            md->recursive = new_recursive.prevrec;
1777          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1778            {            {
1779            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
           md->recursive = new_recursive.prevrec;  
1780            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1781              (pcre_free)(new_recursive.offset_save);              (PUBL(free))(new_recursive.offset_save);
1782    
1783            /* Set where we got to in the subject, and reset the start in case            /* Set where we got to in the subject, and reset the start in case
1784            it was changed by \K. This *is* propagated back out of a recursion,            it was changed by \K. This *is* propagated back out of a recursion,
# Line 1555  for (;;) Line 1788  for (;;)
1788            mstart = md->start_match_ptr;            mstart = md->start_match_ptr;
1789            goto RECURSION_MATCHED;        /* Exit loop; end processing */            goto RECURSION_MATCHED;        /* Exit loop; end processing */
1790            }            }
1791          else if (rrc != MATCH_NOMATCH &&  
1792                  (rrc != MATCH_THEN || md->start_match_ptr != ecode))          /* PCRE does not allow THEN or COMMIT to escape beyond a recursion; it
1793            is treated as NOMATCH. */
1794    
1795            else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN &&
1796                     rrc != MATCH_COMMIT)
1797            {            {
1798            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1799            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1800              (pcre_free)(new_recursive.offset_save);              (PUBL(free))(new_recursive.offset_save);
1801            RRETURN(rrc);            RRETURN(rrc);
1802            }            }
1803    
# Line 1572  for (;;) Line 1809  for (;;)
1809        DPRINTF(("Recursion didn't match\n"));        DPRINTF(("Recursion didn't match\n"));
1810        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1811        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1812          (pcre_free)(new_recursive.offset_save);          (PUBL(free))(new_recursive.offset_save);
1813        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1814        }        }
1815    
1816      RECURSION_MATCHED:      RECURSION_MATCHED:
# Line 1642  for (;;) Line 1879  for (;;)
1879        }        }
1880      else saved_eptr = NULL;      else saved_eptr = NULL;
1881    
1882      /* If we are at the end of an assertion group, stop matching and return      /* If we are at the end of an assertion group or a non-capturing atomic
1883      MATCH_MATCH, but record the current high water mark for use by positive      group, stop matching and return MATCH_MATCH, but record the current high
1884      assertions. We also need to record the match start in case it was changed      water mark for use by positive assertions. We also need to record the match
1885      by \K. */      start in case it was changed by \K. */
1886    
1887      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if ((*prev >= OP_ASSERT && *prev <= OP_ASSERTBACK_NOT) ||
1888          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT)           *prev == OP_ONCE_NC)
1889        {        {
1890        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE_NC */
1891        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1892        md->start_match_ptr = mstart;        md->start_match_ptr = mstart;
1893        MRRETURN(MATCH_MATCH);        RRETURN(MATCH_MATCH);         /* Sets md->mark */
1894        }        }
1895    
1896      /* For capturing groups we have to check the group number back at the start      /* For capturing groups we have to check the group number back at the start
# Line 1718  for (;;) Line 1955  for (;;)
1955      /* For an ordinary non-repeating ket, just continue at this level. This      /* For an ordinary non-repeating ket, just continue at this level. This
1956      also happens for a repeating ket if no characters were matched in the      also happens for a repeating ket if no characters were matched in the
1957      group. This is the forcible breaking of infinite loops as implemented in      group. This is the forcible breaking of infinite loops as implemented in
1958      Perl 5.005. For a non-repeating atomic group, establish a backup point by      Perl 5.005. For a non-repeating atomic group that includes captures,
1959      processing the rest of the pattern at a lower level. If this results in a      establish a backup point by processing the rest of the pattern at a lower
1960      NOMATCH return, pass MATCH_ONCE back to the original OP_ONCE level, thereby      level. If this results in a NOMATCH return, pass MATCH_ONCE back to the
1961      bypassing intermediate backup points, but resetting any captures that      original OP_ONCE level, thereby bypassing intermediate backup points, but
1962      happened along the way. */      resetting any captures that happened along the way. */
1963    
1964      if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1965        {        {
# Line 1795  for (;;) Line 2032  for (;;)
2032      /* Not multiline mode: start of subject assertion, unless notbol. */      /* Not multiline mode: start of subject assertion, unless notbol. */
2033    
2034      case OP_CIRC:      case OP_CIRC:
2035      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
2036    
2037      /* Start of subject assertion */      /* Start of subject assertion */
2038    
2039      case OP_SOD:      case OP_SOD:
2040      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);
2041      ecode++;      ecode++;
2042      break;      break;
2043    
2044      /* Multiline mode: start of subject unless notbol, or after any newline. */      /* Multiline mode: start of subject unless notbol, or after any newline. */
2045    
2046      case OP_CIRCM:      case OP_CIRCM:
2047      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
2048      if (eptr != md->start_subject &&      if (eptr != md->start_subject &&
2049          (eptr == md->end_subject || !WAS_NEWLINE(eptr)))          (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
2050        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2051      ecode++;      ecode++;
2052      break;      break;
2053    
2054      /* Start of match assertion */      /* Start of match assertion */
2055    
2056      case OP_SOM:      case OP_SOM:
2057      if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);
2058      ecode++;      ecode++;
2059      break;      break;
2060    
# Line 1833  for (;;) Line 2070  for (;;)
2070    
2071      case OP_DOLLM:      case OP_DOLLM:
2072      if (eptr < md->end_subject)      if (eptr < md->end_subject)
2073        { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }        {
2074          if (!IS_NEWLINE(eptr))
2075            {
2076            if (md->partial != 0 &&
2077                eptr + 1 >= md->end_subject &&
2078                NLBLOCK->nltype == NLTYPE_FIXED &&
2079                NLBLOCK->nllen == 2 &&
2080                *eptr == NLBLOCK->nl[0])
2081              {
2082              md->hitend = TRUE;
2083              if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2084              }
2085            RRETURN(MATCH_NOMATCH);
2086            }
2087          }
2088      else      else
2089        {        {
2090        if (md->noteol) MRRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
2091        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2092        }        }
2093      ecode++;      ecode++;
# Line 1846  for (;;) Line 2097  for (;;)
2097      subject unless noteol is set. */      subject unless noteol is set. */
2098    
2099      case OP_DOLL:      case OP_DOLL:
2100      if (md->noteol) MRRETURN(MATCH_NOMATCH);      if (md->noteol) RRETURN(MATCH_NOMATCH);
2101      if (!md->endonly) goto ASSERT_NL_OR_EOS;      if (!md->endonly) goto ASSERT_NL_OR_EOS;
2102    
2103      /* ... else fall through for endonly */      /* ... else fall through for endonly */
# Line 1854  for (;;) Line 2105  for (;;)
2105      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
2106    
2107      case OP_EOD:      case OP_EOD:
2108      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);
2109      SCHECK_PARTIAL();      SCHECK_PARTIAL();
2110      ecode++;      ecode++;
2111      break;      break;
# Line 1865  for (;;) Line 2116  for (;;)
2116      ASSERT_NL_OR_EOS:      ASSERT_NL_OR_EOS:
2117      if (eptr < md->end_subject &&      if (eptr < md->end_subject &&
2118          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
2119        MRRETURN(MATCH_NOMATCH);        {
2120          if (md->partial != 0 &&
2121              eptr + 1 >= md->end_subject &&
2122              NLBLOCK->nltype == NLTYPE_FIXED &&
2123              NLBLOCK->nllen == 2 &&
2124              *eptr == NLBLOCK->nl[0])
2125            {
2126            md->hitend = TRUE;
2127            if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2128            }
2129          RRETURN(MATCH_NOMATCH);
2130          }
2131    
2132      /* Either at end of string or \n before end. */      /* Either at end of string or \n before end. */
2133    
# Line 1884  for (;;) Line 2146  for (;;)
2146        be "non-word" characters. Remember the earliest consulted character for        be "non-word" characters. Remember the earliest consulted character for
2147        partial matching. */        partial matching. */
2148    
2149  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2150        if (utf8)        if (utf)
2151          {          {
2152          /* Get status of previous character */          /* Get status of previous character */
2153    
2154          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
2155            {            {
2156            USPTR lastptr = eptr - 1;            PCRE_PUCHAR lastptr = eptr - 1;
2157            while((*lastptr & 0xc0) == 0x80) lastptr--;            BACKCHAR(lastptr);
2158            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;            if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
2159            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
2160  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 1957  for (;;) Line 2219  for (;;)
2219              }              }
2220            else            else
2221  #endif  #endif
2222            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);            prev_is_word = MAX_255(eptr[-1])
2223                && ((md->ctypes[eptr[-1]] & ctype_word) != 0);
2224            }            }
2225    
2226          /* Get status of next character */          /* Get status of next character */
# Line 1980  for (;;) Line 2243  for (;;)
2243            }            }
2244          else          else
2245  #endif  #endif
2246          cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);          cur_is_word = MAX_255(*eptr)
2247              && ((md->ctypes[*eptr] & ctype_word) != 0);
2248          }          }
2249    
2250        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
2251    
2252        if ((*ecode++ == OP_WORD_BOUNDARY)?        if ((*ecode++ == OP_WORD_BOUNDARY)?
2253             cur_is_word == prev_is_word : cur_is_word != prev_is_word)             cur_is_word == prev_is_word : cur_is_word != prev_is_word)
2254          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2255        }        }
2256      break;      break;
2257    
2258      /* Match a single character type; inline for speed */      /* Match any single character type except newline; have to take care with
2259        CRLF newlines and partial matching. */
2260    
2261      case OP_ANY:      case OP_ANY:
2262      if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
2263        if (md->partial != 0 &&
2264            eptr + 1 >= md->end_subject &&
2265            NLBLOCK->nltype == NLTYPE_FIXED &&
2266            NLBLOCK->nllen == 2 &&
2267            *eptr == NLBLOCK->nl[0])
2268          {
2269          md->hitend = TRUE;
2270          if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2271          }
2272    
2273      /* Fall through */      /* Fall through */
2274    
2275        /* Match any single character whatsoever. */
2276    
2277      case OP_ALLANY:      case OP_ALLANY:
2278      if (eptr++ >= md->end_subject)      if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */
2279        {        {                            /* not be updated before SCHECK_PARTIAL. */
2280        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2281        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2282        }        }
2283      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;      eptr++;
2284    #ifdef SUPPORT_UTF
2285        if (utf) ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
2286    #endif
2287      ecode++;      ecode++;
2288      break;      break;
2289    
# Line 2011  for (;;) Line 2291  for (;;)
2291      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
2292    
2293      case OP_ANYBYTE:      case OP_ANYBYTE:
2294      if (eptr++ >= md->end_subject)      if (eptr >= md->end_subject)   /* DO NOT merge the eptr++ here; it must */
2295        {        {                            /* not be updated before SCHECK_PARTIAL. */
2296        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2297        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2298        }        }
2299        eptr++;
2300      ecode++;      ecode++;
2301      break;      break;
2302    
# Line 2023  for (;;) Line 2304  for (;;)
2304      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2305        {        {
2306        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2307        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2308        }        }
2309      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2310      if (      if (
2311  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2312         c < 256 &&         c < 256 &&
2313  #endif  #endif
2314         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
2315         )         )
2316        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2317      ecode++;      ecode++;
2318      break;      break;
2319    
# Line 2040  for (;;) Line 2321  for (;;)
2321      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2322        {        {
2323        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2324        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2325        }        }
2326      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2327      if (      if (
2328  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2329         c >= 256 ||         c > 255 ||
2330  #endif  #endif
2331         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
2332         )         )
2333        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2334      ecode++;      ecode++;
2335      break;      break;
2336    
# Line 2057  for (;;) Line 2338  for (;;)
2338      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2339        {        {
2340        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2341        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2342        }        }
2343      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2344      if (      if (
2345  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2346         c < 256 &&         c < 256 &&
2347  #endif  #endif
2348         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
2349         )         )
2350        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2351      ecode++;      ecode++;
2352      break;      break;
2353    
# Line 2074  for (;;) Line 2355  for (;;)
2355      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2356        {        {
2357        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2358        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2359        }        }
2360      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2361      if (      if (
2362  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2363         c >= 256 ||         c > 255 ||
2364  #endif  #endif
2365         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
2366         )         )
2367        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2368      ecode++;      ecode++;
2369      break;      break;
2370    
# Line 2091  for (;;) Line 2372  for (;;)
2372      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2373        {        {
2374        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2375        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2376        }        }
2377      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2378      if (      if (
2379  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2380         c < 256 &&         c < 256 &&
2381  #endif  #endif
2382         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
2383         )         )
2384        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2385      ecode++;      ecode++;
2386      break;      break;
2387    
# Line 2108  for (;;) Line 2389  for (;;)
2389      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2390        {        {
2391        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2392        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2393        }        }
2394      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2395      if (      if (
2396  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !(defined COMPILE_PCRE8)
2397         c >= 256 ||         c > 255 ||
2398  #endif  #endif
2399         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
2400         )         )
2401        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2402      ecode++;      ecode++;
2403      break;      break;
2404    
# Line 2125  for (;;) Line 2406  for (;;)
2406      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2407        {        {
2408        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2409        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2410        }        }
2411      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2412      switch(c)      switch(c)
2413        {        {
2414        default: MRRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2415    
2416        case 0x000d:        case 0x000d:
2417        if (eptr < md->end_subject && *eptr == 0x0a) eptr++;        if (eptr >= md->end_subject)
2418            {
2419            SCHECK_PARTIAL();
2420            }
2421          else if (*eptr == 0x0a) eptr++;
2422        break;        break;
2423    
2424        case 0x000a:        case 0x000a:
# Line 2144  for (;;) Line 2429  for (;;)
2429        case 0x0085:        case 0x0085:
2430        case 0x2028:        case 0x2028:
2431        case 0x2029:        case 0x2029:
2432        if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);        if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
2433        break;        break;
2434        }        }
2435      ecode++;      ecode++;
# Line 2154  for (;;) Line 2439  for (;;)
2439      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2440        {        {
2441        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2442        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2443        }        }
2444      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2445      switch(c)      switch(c)
# Line 2179  for (;;) Line 2464  for (;;)
2464        case 0x202f:    /* NARROW NO-BREAK SPACE */        case 0x202f:    /* NARROW NO-BREAK SPACE */
2465        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */        case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2466        case 0x3000:    /* IDEOGRAPHIC SPACE */        case 0x3000:    /* IDEOGRAPHIC SPACE */
2467        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2468        }        }
2469      ecode++;      ecode++;
2470      break;      break;
# Line 2188  for (;;) Line 2473  for (;;)
2473      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2474        {        {
2475        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2476        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2477        }        }
2478      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2479      switch(c)      switch(c)
2480        {        {
2481        default: MRRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2482        case 0x09:      /* HT */        case 0x09:      /* HT */
2483        case 0x20:      /* SPACE */        case 0x20:      /* SPACE */
2484        case 0xa0:      /* NBSP */        case 0xa0:      /* NBSP */
# Line 2222  for (;;) Line 2507  for (;;)
2507      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2508        {        {
2509        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2510        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2511        }        }
2512      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2513      switch(c)      switch(c)
# Line 2235  for (;;) Line 2520  for (;;)
2520        case 0x85:      /* NEL */        case 0x85:      /* NEL */
2521        case 0x2028:    /* LINE SEPARATOR */        case 0x2028:    /* LINE SEPARATOR */
2522        case 0x2029:    /* PARAGRAPH SEPARATOR */        case 0x2029:    /* PARAGRAPH SEPARATOR */
2523        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2524        }        }
2525      ecode++;      ecode++;
2526      break;      break;
# Line 2244  for (;;) Line 2529  for (;;)
2529      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2530        {        {
2531        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2532        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2533        }        }
2534      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2535      switch(c)      switch(c)
2536        {        {
2537        default: MRRETURN(MATCH_NOMATCH);        default: RRETURN(MATCH_NOMATCH);
2538        case 0x0a:      /* LF */        case 0x0a:      /* LF */
2539        case 0x0b:      /* VT */        case 0x0b:      /* VT */
2540        case 0x0c:      /* FF */        case 0x0c:      /* FF */
# Line 2271  for (;;) Line 2556  for (;;)
2556      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2557        {        {
2558        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2559        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2560        }        }
2561      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2562        {        {
# Line 2280  for (;;) Line 2565  for (;;)
2565        switch(ecode[1])        switch(ecode[1])
2566          {          {
2567          case PT_ANY:          case PT_ANY:
2568          if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);          if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);
2569          break;          break;
2570    
2571          case PT_LAMP:          case PT_LAMP:
2572          if ((prop->chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
2573               prop->chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2574               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2575            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2576          break;          break;
2577    
2578          case PT_GC:          case PT_GC:
2579          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))          if ((ecode[2] != PRIV(ucp_gentype)[prop->chartype]) == (op == OP_PROP))
2580            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2581          break;          break;
2582    
2583          case PT_PC:          case PT_PC:
2584          if ((ecode[2] != prop->chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2585            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2586          break;          break;
2587    
2588          case PT_SC:          case PT_SC:
2589          if ((ecode[2] != prop->script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2590            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2591          break;          break;
2592    
2593          /* These are specials */          /* These are specials */
2594    
2595          case PT_ALNUM:          case PT_ALNUM:
2596          if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2597               _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))               PRIV(ucp_gentype)[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2598            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2599          break;          break;
2600    
2601          case PT_SPACE:    /* Perl space */          case PT_SPACE:    /* Perl space */
2602          if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2603               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)               c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2604                 == (op == OP_NOTPROP))                 == (op == OP_NOTPROP))
2605            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2606          break;          break;
2607    
2608          case PT_PXSPACE:  /* POSIX space */          case PT_PXSPACE:  /* POSIX space */
2609          if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_Z ||
2610               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||               c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2611               c == CHAR_FF || c == CHAR_CR)               c == CHAR_FF || c == CHAR_CR)
2612                 == (op == OP_NOTPROP))                 == (op == OP_NOTPROP))
2613            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2614          break;          break;
2615    
2616          case PT_WORD:          case PT_WORD:
2617          if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||          if ((PRIV(ucp_gentype)[prop->chartype] == ucp_L ||
2618               _pcre_ucp_gentype[prop->chartype] == ucp_N ||               PRIV(ucp_gentype)[prop->chartype] == ucp_N ||
2619               c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))               c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2620            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2621          break;          break;
2622    
2623          /* This should never occur */          /* This should never occur */
# Line 2352  for (;;) Line 2637  for (;;)
2637      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
2638        {        {
2639        SCHECK_PARTIAL();        SCHECK_PARTIAL();
2640        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2641        }        }
2642      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2643      if (UCD_CATEGORY(c) == ucp_M) MRRETURN(MATCH_NOMATCH);      if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH);
2644      while (eptr < md->end_subject)      while (eptr < md->end_subject)
2645        {        {
2646        int len = 1;        int len = 1;
2647        if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }        if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
2648        if (UCD_CATEGORY(c) != ucp_M) break;        if (UCD_CATEGORY(c) != ucp_M) break;
2649        eptr += len;        eptr += len;
2650        }        }
2651        CHECK_PARTIAL();
2652      ecode++;      ecode++;
2653      break;      break;
2654  #endif  #endif
# Line 2380  for (;;) Line 2666  for (;;)
2666      case OP_REFI:      case OP_REFI:
2667      caseless = op == OP_REFI;      caseless = op == OP_REFI;
2668      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */      offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2669      ecode += 3;      ecode += 1 + IMM2_SIZE;
2670    
2671      /* If the reference is unset, there are two possibilities:      /* If the reference is unset, there are two possibilities:
2672    
# Line 2420  for (;;) Line 2706  for (;;)
2706        case OP_CRMINRANGE:        case OP_CRMINRANGE:
2707        minimize = (*ecode == OP_CRMINRANGE);        minimize = (*ecode == OP_CRMINRANGE);
2708        min = GET2(ecode, 1);        min = GET2(ecode, 1);
2709        max = GET2(ecode, 3);        max = GET2(ecode, 1 + IMM2_SIZE);
2710        if (max == 0) max = INT_MAX;        if (max == 0) max = INT_MAX;
2711        ecode += 5;        ecode += 1 + 2 * IMM2_SIZE;
2712        break;        break;
2713    
2714        default:               /* No repeat follows */        default:               /* No repeat follows */
2715        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((length = match_ref(offset, eptr, length, md, caseless)) < 0)
2716          {          {
2717            if (length == -2) eptr = md->end_subject;   /* Partial match */
2718          CHECK_PARTIAL();          CHECK_PARTIAL();
2719          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2720          }          }
2721        eptr += length;        eptr += length;
2722        continue;              /* With the main loop */        continue;              /* With the main loop */
2723        }        }
2724    
2725      /* Handle repeated back references. If the length of the reference is      /* Handle repeated back references. If the length of the reference is
2726      zero, just continue with the main loop. */      zero, just continue with the main loop. If the length is negative, it
2727        means the reference is unset in non-Java-compatible mode. If the minimum is
2728        zero, we can continue at the same level without recursion. For any other
2729        minimum, carrying on will result in NOMATCH. */
2730    
2731      if (length == 0) continue;      if (length == 0) continue;
2732        if (length < 0 && min == 0) continue;
2733    
2734      /* First, ensure the minimum number of matches are present. We get back      /* First, ensure the minimum number of matches are present. We get back
2735      the length of the reference string explicitly rather than passing the      the length of the reference string explicitly rather than passing the
# Line 2449  for (;;) Line 2740  for (;;)
2740        int slength;        int slength;
2741        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)        if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2742          {          {
2743            if (slength == -2) eptr = md->end_subject;   /* Partial match */
2744          CHECK_PARTIAL();          CHECK_PARTIAL();
2745          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2746          }          }
2747        eptr += slength;        eptr += slength;
2748        }        }
# Line 2469  for (;;) Line 2761  for (;;)
2761          int slength;          int slength;
2762          RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM14);
2763          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2764          if (fi >= max) MRRETURN(MATCH_NOMATCH);          if (fi >= max) RRETURN(MATCH_NOMATCH);
2765          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2766            {            {
2767              if (slength == -2) eptr = md->end_subject;   /* Partial match */
2768            CHECK_PARTIAL();            CHECK_PARTIAL();
2769            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2770            }            }
2771          eptr += slength;          eptr += slength;
2772          }          }
# Line 2490  for (;;) Line 2783  for (;;)
2783          int slength;          int slength;
2784          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)          if ((slength = match_ref(offset, eptr, length, md, caseless)) < 0)
2785            {            {
2786            CHECK_PARTIAL();            /* Can't use CHECK_PARTIAL because we don't want to update eptr in
2787              the soft partial matching case. */
2788    
2789              if (slength == -2 && md->partial != 0 &&
2790                  md->end_subject > md->start_used_ptr)
2791                {
2792                md->hitend = TRUE;
2793                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
2794                }
2795            break;            break;
2796            }            }
2797          eptr += slength;          eptr += slength;
2798          }          }
2799    
2800        while (eptr >= pp)        while (eptr >= pp)
2801          {          {
2802          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);          RMATCH(eptr, ecode, offset_top, md, eptrb, RM15);
2803          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2804          eptr -= length;          eptr -= length;
2805          }          }
2806        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
2807        }        }
2808      /* Control never gets here */      /* Control never gets here */
2809    
# Line 2519  for (;;) Line 2821  for (;;)
2821      case OP_NCLASS:      case OP_NCLASS:
2822      case OP_CLASS:      case OP_CLASS:
2823        {        {
2824          /* The data variable is saved across frames, so the byte map needs to
2825          be stored there. */
2826    #define BYTE_MAP ((pcre_uint8 *)data)
2827        data = ecode + 1;                /* Save for matching */        data = ecode + 1;                /* Save for matching */
2828        ecode += 33;                     /* Advance past the item */        ecode += 1 + (32 / sizeof(pcre_uchar)); /* Advance past the item */
2829    
2830        switch (*ecode)        switch (*ecode)
2831          {          {
# Line 2541  for (;;) Line 2846  for (;;)
2846          case OP_CRMINRANGE:          case OP_CRMINRANGE:
2847          minimize = (*ecode == OP_CRMINRANGE);          minimize = (*ecode == OP_CRMINRANGE);
2848          min = GET2(ecode, 1);          min = GET2(ecode, 1);
2849          max = GET2(ecode, 3);          max = GET2(ecode, 1 + IMM2_SIZE);
2850          if (max == 0) max = INT_MAX;          if (max == 0) max = INT_MAX;
2851          ecode += 5;          ecode += 1 + 2 * IMM2_SIZE;
2852          break;          break;
2853    
2854          default:               /* No repeat follows */          default:               /* No repeat follows */
# Line 2553  for (;;) Line 2858  for (;;)
2858    
2859        /* First, ensure the minimum number of matches are present. */        /* First, ensure the minimum number of matches are present. */
2860    
2861  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2862        /* UTF-8 mode */        if (utf)
       if (utf8)  
2863          {          {
2864          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2865            {            {
2866            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2867              {              {
2868              SCHECK_PARTIAL();              SCHECK_PARTIAL();
2869              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2870              }              }
2871            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2872            if (c > 255)            if (c > 255)
2873              {              {
2874              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2875              }              }
2876            else            else
2877              {              if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
             if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);  
             }  
2878            }            }
2879          }          }
2880        else        else
2881  #endif  #endif
2882        /* Not UTF-8 mode */        /* Not UTF mode */
2883          {          {
2884          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2885            {            {
2886            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
2887              {              {
2888              SCHECK_PARTIAL();              SCHECK_PARTIAL();
2889              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2890              }              }
2891            c = *eptr++;            c = *eptr++;
2892            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);  #ifndef COMPILE_PCRE8
2893              if (c > 255)
2894                {
2895                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2896                }
2897              else
2898    #endif
2899                if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2900            }            }
2901          }          }
2902    
# Line 2601  for (;;) Line 2910  for (;;)
2910    
2911        if (minimize)        if (minimize)
2912          {          {
2913  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2914          /* UTF-8 mode */          if (utf)
         if (utf8)  
2915            {            {
2916            for (fi = min;; fi++)            for (fi = min;; fi++)
2917              {              {
2918              RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM16);
2919              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2920              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2921              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
2922                {                {
2923                SCHECK_PARTIAL();                SCHECK_PARTIAL();
2924                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2925                }                }
2926              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2927              if (c > 255)              if (c > 255)
2928                {                {
2929                if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2930                }                }
2931              else              else
2932                {                if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
               if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);  
               }  
2933              }              }
2934            }            }
2935          else          else
2936  #endif  #endif
2937          /* Not UTF-8 mode */          /* Not UTF mode */
2938            {            {
2939            for (fi = min;; fi++)            for (fi = min;; fi++)
2940              {              {
2941              RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM17);
2942              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2943              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2944              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
2945                {                {
2946                SCHECK_PARTIAL();                SCHECK_PARTIAL();
2947                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2948                }                }
2949              c = *eptr++;              c = *eptr++;
2950              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);  #ifndef COMPILE_PCRE8
2951                if (c > 255)
2952                  {
2953                  if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);
2954                  }
2955                else
2956    #endif
2957                  if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2958              }              }
2959            }            }
2960          /* Control never gets here */          /* Control never gets here */
# Line 2653  for (;;) Line 2966  for (;;)
2966          {          {
2967          pp = eptr;          pp = eptr;
2968    
2969  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
2970          /* UTF-8 mode */          if (utf)
         if (utf8)  
2971            {            {
2972            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2973              {              {
# Line 2671  for (;;) Line 2983  for (;;)
2983                if (op == OP_CLASS) break;                if (op == OP_CLASS) break;
2984                }                }
2985              else              else
2986                {                if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break;
               if ((data[c/8] & (1 << (c&7))) == 0) break;  
               }  
2987              eptr += len;              eptr += len;
2988              }              }
2989            for (;;)            for (;;)
# Line 2686  for (;;) Line 2996  for (;;)
2996            }            }
2997          else          else
2998  #endif  #endif
2999            /* Not UTF-8 mode */            /* Not UTF mode */
3000            {            {
3001            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3002              {              {
# Line 2696  for (;;) Line 3006  for (;;)
3006                break;                break;
3007                }                }
3008              c = *eptr;              c = *eptr;
3009              if ((data[c/8] & (1 << (c&7))) == 0) break;  #ifndef COMPILE_PCRE8
3010                if (c > 255)
3011                  {
3012                  if (op == OP_CLASS) break;
3013                  }
3014                else
3015    #endif
3016                  if ((BYTE_MAP[c/8] & (1 << (c&7))) == 0) break;
3017              eptr++;              eptr++;
3018              }              }
3019            while (eptr >= pp)            while (eptr >= pp)
# Line 2707  for (;;) Line 3024  for (;;)
3024              }              }
3025            }            }
3026    
3027          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3028          }          }
3029    #undef BYTE_MAP
3030        }        }
3031      /* Control never gets here */      /* Control never gets here */
3032    
# Line 2717  for (;;) Line 3035  for (;;)
3035      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
3036      mode, because Unicode properties are supported in non-UTF-8 mode. */      mode, because Unicode properties are supported in non-UTF-8 mode. */
3037    
3038  #ifdef SUPPORT_UTF8  #if defined SUPPORT_UTF || !defined COMPILE_PCRE8
3039      case OP_XCLASS:      case OP_XCLASS:
3040        {        {
3041        data = ecode + 1 + LINK_SIZE;                /* Save for matching */        data = ecode + 1 + LINK_SIZE;                /* Save for matching */
# Line 2742  for (;;) Line 3060  for (;;)
3060          case OP_CRMINRANGE:          case OP_CRMINRANGE:
3061          minimize = (*ecode == OP_CRMINRANGE);          minimize = (*ecode == OP_CRMINRANGE);
3062          min = GET2(ecode, 1);          min = GET2(ecode, 1);
3063          max = GET2(ecode, 3);          max = GET2(ecode, 1 + IMM2_SIZE);
3064          if (max == 0) max = INT_MAX;          if (max == 0) max = INT_MAX;
3065          ecode += 5;          ecode += 1 + 2 * IMM2_SIZE;
3066          break;          break;
3067    
3068          default:               /* No repeat follows */          default:               /* No repeat follows */
# Line 2759  for (;;) Line 3077  for (;;)
3077          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
3078            {            {
3079            SCHECK_PARTIAL();            SCHECK_PARTIAL();
3080            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
3081            }            }
3082          GETCHARINCTEST(c, eptr);          GETCHARINCTEST(c, eptr);
3083          if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);          if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH);
3084          }          }
3085    
3086        /* If max == min we can continue with the main loop without the        /* If max == min we can continue with the main loop without the
# Line 2779  for (;;) Line 3097  for (;;)
3097            {            {
3098            RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM20);
3099            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3100            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3101            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3102              {              {
3103              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3104              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3105              }              }
3106            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3107            if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);            if (!PRIV(xclass)(c, data, utf)) RRETURN(MATCH_NOMATCH);
3108            }            }
3109          /* Control never gets here */          /* Control never gets here */
3110          }          }
# Line 2804  for (;;) Line 3122  for (;;)
3122              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3123              break;              break;
3124              }              }
3125    #ifdef SUPPORT_UTF
3126            GETCHARLENTEST(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
3127            if (!_pcre_xclass(c, data)) break;  #else
3128              c = *eptr;
3129    #endif
3130              if (!PRIV(xclass)(c, data, utf)) break;
3131            eptr += len;            eptr += len;
3132            }            }
3133          for(;;)          for(;;)
# Line 2813  for (;;) Line 3135  for (;;)
3135            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM21);
3136            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3137            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
3138            if (utf8) BACKCHAR(eptr);  #ifdef SUPPORT_UTF
3139              if (utf) BACKCHAR(eptr);
3140    #endif
3141            }            }
3142          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3143          }          }
3144    
3145        /* Control never gets here */        /* Control never gets here */
# Line 2825  for (;;) Line 3149  for (;;)
3149      /* Match a single character, casefully */      /* Match a single character, casefully */
3150    
3151      case OP_CHAR:      case OP_CHAR:
3152  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3153      if (utf8)      if (utf)
3154        {        {
3155        length = 1;        length = 1;
3156        ecode++;        ecode++;
# Line 2834  for (;;) Line 3158  for (;;)
3158        if (length > md->end_subject - eptr)        if (length > md->end_subject - eptr)
3159          {          {
3160          CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */          CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
3161          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3162          }          }
3163        while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
3164        }        }
3165      else      else
3166  #endif  #endif
3167        /* Not UTF mode */
     /* Non-UTF-8 mode */  
3168        {        {
3169        if (md->end_subject - eptr < 1)        if (md->end_subject - eptr < 1)
3170          {          {
3171          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
3172          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3173          }          }
3174        if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
3175        ecode += 2;        ecode += 2;
3176        }        }
3177      break;      break;
3178    
3179      /* Match a single character, caselessly */      /* Match a single character, caselessly. If we are at the end of the
3180        subject, give up immediately. */
3181    
3182      case OP_CHARI:      case OP_CHARI:
3183  #ifdef SUPPORT_UTF8      if (eptr >= md->end_subject)
3184      if (utf8)        {
3185          SCHECK_PARTIAL();
3186          RRETURN(MATCH_NOMATCH);
3187          }
3188    
3189    #ifdef SUPPORT_UTF
3190        if (utf)
3191        {        {
3192        length = 1;        length = 1;
3193        ecode++;        ecode++;
3194        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
3195    
       if (length > md->end_subject - eptr)  
         {  
         CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */  
         MRRETURN(MATCH_NOMATCH);  
         }  
   
3196        /* 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
3197        can use the fast lookup table. */        we know that its other case must also be one byte long, so we can use the
3198          fast lookup table. We know that there is at least one byte left in the
3199          subject. */
3200    
3201        if (fc < 128)        if (fc < 128)
3202          {          {
3203          if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);          if (md->lcc[fc]
3204                != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH);
3205            ecode++;
3206            eptr++;
3207          }          }
3208    
3209        /* Otherwise we must pick up the subject character */        /* Otherwise we must pick up the subject character. Note that we cannot
3210          use the value of "length" to check for sufficient bytes left, because the
3211          other case of the character may have more or fewer bytes.  */
3212    
3213        else        else
3214          {          {
# Line 2893  for (;;) Line 3224  for (;;)
3224  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3225            if (dc != UCD_OTHERCASE(fc))            if (dc != UCD_OTHERCASE(fc))
3226  #endif  #endif
3227              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3228            }            }
3229          }          }
3230        }        }
3231      else      else
3232  #endif   /* SUPPORT_UTF8 */  #endif   /* SUPPORT_UTF */
3233    
3234      /* Non-UTF-8 mode */      /* Not UTF mode */
3235        {        {
3236        if (md->end_subject - eptr < 1)        if (TABLE_GET(ecode[1], md->lcc, ecode[1])
3237          {            != TABLE_GET(*eptr, md->lcc, *eptr)) RRETURN(MATCH_NOMATCH);
3238          SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */        eptr++;
         MRRETURN(MATCH_NOMATCH);  
         }  
       if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);  
3239        ecode += 2;        ecode += 2;
3240        }        }
3241      break;      break;
# Line 2917  for (;;) Line 3245  for (;;)
3245      case OP_EXACT:      case OP_EXACT:
3246      case OP_EXACTI:      case OP_EXACTI:
3247      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3248      ecode += 3;      ecode += 1 + IMM2_SIZE;
3249      goto REPEATCHAR;      goto REPEATCHAR;
3250    
3251      case OP_POSUPTO:      case OP_POSUPTO:
# Line 2932  for (;;) Line 3260  for (;;)
3260      min = 0;      min = 0;
3261      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3262      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;      minimize = *ecode == OP_MINUPTO || *ecode == OP_MINUPTOI;
3263      ecode += 3;      ecode += 1 + IMM2_SIZE;
3264      goto REPEATCHAR;      goto REPEATCHAR;
3265    
3266      case OP_POSSTAR:      case OP_POSSTAR:
# Line 2980  for (;;) Line 3308  for (;;)
3308      /* Common code for all repeated single-character matches. */      /* Common code for all repeated single-character matches. */
3309    
3310      REPEATCHAR:      REPEATCHAR:
3311  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3312      if (utf8)      if (utf)
3313        {        {
3314        length = 1;        length = 1;
3315        charptr = ecode;        charptr = ecode;
# Line 2997  for (;;) Line 3325  for (;;)
3325          unsigned int othercase;          unsigned int othercase;
3326          if (op >= OP_STARI &&     /* Caseless */          if (op >= OP_STARI &&     /* Caseless */
3327              (othercase = UCD_OTHERCASE(fc)) != fc)              (othercase = UCD_OTHERCASE(fc)) != fc)
3328            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = PRIV(ord2utf)(othercase, occhars);
3329          else oclength = 0;          else oclength = 0;
3330  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3331    
3332          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3333            {            {
3334            if (eptr <= md->end_subject - length &&            if (eptr <= md->end_subject - length &&
3335              memcmp(eptr, charptr, length) == 0) eptr += length;              memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
3336  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3337            else if (oclength > 0 &&            else if (oclength > 0 &&
3338                     eptr <= md->end_subject - oclength &&                     eptr <= md->end_subject - oclength &&
3339                     memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                     memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
3340  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3341            else            else
3342              {              {
3343              CHECK_PARTIAL();              CHECK_PARTIAL();
3344              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3345              }              }
3346            }            }
3347    
# Line 3025  for (;;) Line 3353  for (;;)
3353              {              {
3354              RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM22);
3355              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3356              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3357              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
3358                memcmp(eptr, charptr, length) == 0) eptr += length;                memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
3359  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3360              else if (oclength > 0 &&              else if (oclength > 0 &&
3361                       eptr <= md->end_subject - oclength &&                       eptr <= md->end_subject - oclength &&
3362                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                       memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
3363  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3364              else              else
3365                {                {
3366                CHECK_PARTIAL();                CHECK_PARTIAL();
3367                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3368                }                }
3369              }              }
3370            /* Control never gets here */            /* Control never gets here */
# Line 3048  for (;;) Line 3376  for (;;)
3376            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3377              {              {
3378              if (eptr <= md->end_subject - length &&              if (eptr <= md->end_subject - length &&
3379                  memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, IN_UCHARS(length)) == 0) eptr += length;
3380  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3381              else if (oclength > 0 &&              else if (oclength > 0 &&
3382                       eptr <= md->end_subject - oclength &&                       eptr <= md->end_subject - oclength &&
3383                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;                       memcmp(eptr, occhars, IN_UCHARS(oclength)) == 0) eptr += oclength;
3384  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
3385              else              else
3386                {                {
# Line 3067  for (;;) Line 3395  for (;;)
3395              {              {
3396              RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM23);
3397              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3398              if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }              if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
3399  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
3400              eptr--;              eptr--;
3401              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 3084  for (;;) Line 3412  for (;;)
3412        value of fc will always be < 128. */        value of fc will always be < 128. */
3413        }        }
3414      else      else
3415  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF */
3416          /* When not in UTF-8 mode, load a single-byte character. */
3417      /* When not in UTF-8 mode, load a single-byte character. */        fc = *ecode++;
   
     fc = *ecode++;  
3418    
3419      /* 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 one character, though we may
3420      may not be in UTF-8 mode. The code is duplicated for the caseless and      or may not be in UTF mode. The code is duplicated for the caseless and
3421      caseful cases, for speed, since matching characters is likely to be quite      caseful cases, for speed, since matching characters is likely to be quite
3422      common. First, ensure the minimum number of matches are present. If min =      common. First, ensure the minimum number of matches are present. If min =
3423      max, continue at the same level without recursing. Otherwise, if      max, continue at the same level without recursing. Otherwise, if
# Line 3104  for (;;) Line 3430  for (;;)
3430    
3431      if (op >= OP_STARI)  /* Caseless */      if (op >= OP_STARI)  /* Caseless */
3432        {        {
3433        fc = md->lcc[fc];  #ifdef COMPILE_PCRE8
3434          /* fc must be < 128 if UTF is enabled. */
3435          foc = md->fcc[fc];
3436    #else
3437    #ifdef SUPPORT_UTF
3438    #ifdef SUPPORT_UCP
3439          if (utf && fc > 127)
3440            foc = UCD_OTHERCASE(fc);
3441    #else
3442          if (utf && fc > 127)
3443            foc = fc;
3444    #endif /* SUPPORT_UCP */
3445          else
3446    #endif /* SUPPORT_UTF */
3447            foc = TABLE_GET(fc, md->fcc, fc);
3448    #endif /* COMPILE_PCRE8 */
3449    
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            {            {
3454            SCHECK_PARTIAL();            SCHECK_PARTIAL();
3455            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
3456            }            }
3457          if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);          if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH);
3458            eptr++;
3459          }          }
3460        if (min == max) continue;        if (min == max) continue;
3461        if (minimize)        if (minimize)
# Line 3121  for (;;) Line 3464  for (;;)
3464            {            {
3465            RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM24);
3466            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3467            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3468            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3469              {              {
3470              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3471              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3472              }              }
3473            if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);            if (fc != *eptr && foc != *eptr) RRETURN(MATCH_NOMATCH);
3474              eptr++;
3475            }            }
3476          /* Control never gets here */          /* Control never gets here */
3477          }          }
# Line 3141  for (;;) Line 3485  for (;;)
3485              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3486              break;              break;
3487              }              }
3488            if (fc != md->lcc[*eptr]) break;            if (fc != *eptr && foc != *eptr) break;
3489            eptr++;            eptr++;
3490            }            }
3491    
# Line 3153  for (;;) Line 3497  for (;;)
3497            eptr--;            eptr--;
3498            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3499            }            }
3500          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3501          }          }
3502        /* Control never gets here */        /* Control never gets here */
3503        }        }
# Line 3167  for (;;) Line 3511  for (;;)
3511          if (eptr >= md->end_subject)          if (eptr >= md->end_subject)
3512            {            {
3513            SCHECK_PARTIAL();            SCHECK_PARTIAL();
3514            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
3515            }            }
3516          if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);          if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
3517          }          }
3518    
3519        if (min == max) continue;        if (min == max) continue;
# Line 3180  for (;;) Line 3524  for (;;)
3524            {            {
3525            RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);            RMATCH(eptr, ecode, offset_top, md, eptrb, RM26);
3526            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3527            if (fi >= max) MRRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3528            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3529              {              {
3530              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3531              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3532              }              }
3533            if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
3534            }            }
3535          /* Control never gets here */          /* Control never gets here */
3536          }          }
# Line 3211  for (;;) Line 3555  for (;;)
3555            eptr--;            eptr--;
3556            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3557            }            }
3558          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3559          }          }
3560        }        }
3561      /* Control never gets here */      /* Control never gets here */
# Line 3224  for (;;) Line 3568  for (;;)
3568      if (eptr >= md->end_subject)      if (eptr >= md->end_subject)
3569        {        {
3570        SCHECK_PARTIAL();        SCHECK_PARTIAL();
3571        MRRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
3572        }        }
3573      ecode++;  #ifdef SUPPORT_UTF
3574      GETCHARINCTEST(c, eptr);      if (utf)
     if (op == OP_NOTI)         /* The caseless case */  
3575        {        {
3576  #ifdef SUPPORT_UTF8        register unsigned int ch, och;
3577        if (c < 256)  
3578  #endif        ecode++;
3579        c = md->lcc[c];        GETCHARINC(ch, ecode);
3580        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);        GETCHARINC(c, eptr);
3581    
3582          if (op == OP_NOT)
3583            {
3584            if (ch == c) RRETURN(MATCH_NOMATCH);
3585            }
3586          else
3587            {
3588    #ifdef SUPPORT_UCP
3589            if (ch > 127)
3590              och = UCD_OTHERCASE(ch);
3591    #else
3592            if (ch > 127)
3593              och = ch;
3594    #endif /* SUPPORT_UCP */
3595            else
3596              och = TABLE_GET(ch, md->fcc, ch);
3597            if (ch == c || och == c) RRETURN(MATCH_NOMATCH);
3598            }
3599        }        }
3600      else    /* Caseful */      else
3601    #endif
3602        {        {
3603        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);        register unsigned int ch = ecode[1];
3604          c = *eptr++;
3605          if (ch == c || (op == OP_NOTI && TABLE_GET(ch, md->fcc, ch) == c))
3606            RRETURN(MATCH_NOMATCH);
3607          ecode += 2;
3608        }        }
3609      break;      break;
3610    
# Line 3252  for (;;) Line 3618  for (;;)
3618      case OP_NOTEXACT:      case OP_NOTEXACT:
3619      case OP_NOTEXACTI:      case OP_NOTEXACTI:
3620      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3621      ecode += 3;      ecode += 1 + IMM2_SIZE;
3622      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3623    
3624      case OP_NOTUPTO:      case OP_NOTUPTO:
# Line 3262  for (;;) Line 3628  for (;;)
3628      min = 0;      min = 0;
3629      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3630      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;      minimize = *ecode == OP_NOTMINUPTO || *ecode == OP_NOTMINUPTOI;
3631      ecode += 3;      ecode += 1 + IMM2_SIZE;
3632      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3633    
3634      case OP_NOTPOSSTAR:      case OP_NOTPOSSTAR:
# Line 3294  for (;;) Line 3660  for (;;)
3660      possessive = TRUE;      possessive = TRUE;
3661      min = 0;      min = 0;
3662      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3663      ecode += 3;      ecode += 1 + IMM2_SIZE;
3664      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3665    
3666      case OP_NOTSTAR:      case OP_NOTSTAR:
# Line 3318  for (;;) Line 3684  for (;;)
3684      /* Common code for all repeated single-byte matches. */      /* Common code for all repeated single-byte matches. */
3685    
3686      REPEATNOTCHAR:      REPEATNOTCHAR:
3687      fc = *ecode++;      GETCHARINCTEST(fc, ecode);
3688    
3689      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
3690      since matching characters is likely to be quite common. First, ensure the      since matching characters is likely to be quite common. First, ensure the
# Line 3333  for (;;) Line 3699  for (;;)
3699    
3700      if (op >= OP_NOTSTARI)     /* Caseless */      if (op >= OP_NOTSTARI)     /* Caseless */
3701        {        {
3702        fc = md->lcc[fc];  #ifdef SUPPORT_UTF
3703    #ifdef SUPPORT_UCP
3704          if (utf && fc > 127)
3705            foc = UCD_OTHERCASE(fc);
3706    #else
3707          if (utf && fc > 127)
3708            foc = fc;
3709    #endif /* SUPPORT_UCP */
3710          else
3711    #endif /* SUPPORT_UTF */
3712            foc = TABLE_GET(fc, md->fcc, fc);
3713    
3714  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3715        /* UTF-8 mode */        if (utf)
       if (utf8)  
3716          {          {
3717          register unsigned int d;          register unsigned int d;
3718          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
# Line 3345  for (;;) Line 3720  for (;;)
3720            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3721              {              {
3722              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3723              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3724              }              }
3725            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3726            if (d < 256) d = md->lcc[d];            if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
           if (fc == d) MRRETURN(MATCH_NOMATCH);  
3727            }            }
3728          }          }
3729        else        else
3730  #endif  #endif
3731          /* Not UTF mode */
       /* Not UTF-8 mode */  
3732          {          {
3733          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3734            {            {
3735            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3736              {              {
3737              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3738              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3739              }              }
3740            if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);            if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH);
3741              eptr++;
3742            }            }
3743          }          }
3744    
# Line 3372  for (;;) Line 3746  for (;;)
3746    
3747        if (minimize)        if (minimize)
3748          {          {
3749  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3750          /* UTF-8 mode */          if (utf)
         if (utf8)  
3751            {            {
3752            register unsigned int d;            register unsigned int d;
3753            for (fi = min;; fi++)            for (fi = min;; fi++)
3754              {              {
3755              RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM28);
3756              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3757              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3758              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3759                {                {
3760                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3761                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3762                }                }
3763              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3764              if (d < 256) d = md->lcc[d];              if (fc == d || (unsigned int)foc == d) RRETURN(MATCH_NOMATCH);
             if (fc == d) MRRETURN(MATCH_NOMATCH);  
3765              }              }
3766            }            }
3767          else          else
3768  #endif  #endif
3769          /* Not UTF-8 mode */          /* Not UTF mode */
3770            {            {
3771            for (fi = min;; fi++)            for (fi = min;; fi++)
3772              {              {
3773              RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM29);
3774              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3775              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3776              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3777                {                {
3778                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3779                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3780                }                }
3781              if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);              if (fc == *eptr || foc == *eptr) RRETURN(MATCH_NOMATCH);
3782                eptr++;
3783              }              }
3784            }            }
3785          /* Control never gets here */          /* Control never gets here */
# Line 3418  for (;;) Line 3791  for (;;)
3791          {          {
3792          pp = eptr;          pp = eptr;
3793    
3794  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3795          /* UTF-8 mode */          if (utf)
         if (utf8)  
3796            {            {
3797            register unsigned int d;            register unsigned int d;
3798            for (i = min; i < max; i++)            for (i = min; i < max; i++)
# Line 3432  for (;;) Line 3804  for (;;)
3804                break;                break;
3805                }                }
3806              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3807              if (d < 256) d = md->lcc[d];              if (fc == d || (unsigned int)foc == d) break;
             if (fc == d) break;  
3808              eptr += len;              eptr += len;
3809              }              }
3810          if (possessive) continue;            if (possessive) continue;
3811          for(;;)            for(;;)
3812              {              {
3813              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM30);
3814              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
# Line 3447  for (;;) Line 3818  for (;;)
3818            }            }
3819          else          else
3820  #endif  #endif
3821          /* Not UTF-8 mode */          /* Not UTF mode */
3822            {            {
3823            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3824              {              {
# Line 3456  for (;;) Line 3827  for (;;)
3827                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3828                break;                break;
3829                }                }
3830              if (fc == md->lcc[*eptr]) break;              if (fc == *eptr || foc == *eptr) break;
3831              eptr++;              eptr++;
3832              }              }
3833            if (possessive) continue;            if (possessive) continue;
# Line 3468  for (;;) Line 3839  for (;;)
3839              }              }
3840            }            }
3841    
3842          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3843          }          }
3844        /* Control never gets here */        /* Control never gets here */
3845        }        }
# Line 3477  for (;;) Line 3848  for (;;)
3848    
3849      else      else
3850        {        {
3851  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3852        /* UTF-8 mode */        if (utf)
       if (utf8)  
3853          {          {
3854          register unsigned int d;          register unsigned int d;
3855          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
# Line 3487  for (;;) Line 3857  for (;;)
3857            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3858              {              {
3859              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3860              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3861              }              }
3862            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3863            if (fc == d) MRRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
3864            }            }
3865          }          }
3866        else        else
3867  #endif  #endif
3868        /* Not UTF-8 mode */        /* Not UTF mode */
3869          {          {
3870          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3871            {            {
3872            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
3873              {              {
3874              SCHECK_PARTIAL();              SCHECK_PARTIAL();
3875              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3876              }              }
3877            if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3878            }            }
3879          }          }
3880    
# Line 3512  for (;;) Line 3882  for (;;)
3882    
3883        if (minimize)        if (minimize)
3884          {          {
3885  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3886          /* UTF-8 mode */          if (utf)
         if (utf8)  
3887            {            {
3888            register unsigned int d;            register unsigned int d;
3889            for (fi = min;; fi++)            for (fi = min;; fi++)
3890              {              {
3891              RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM32);
3892              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3893              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3894              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3895                {                {
3896                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3897                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3898                }                }
3899              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3900              if (fc == d) MRRETURN(MATCH_NOMATCH);              if (fc == d) RRETURN(MATCH_NOMATCH);
3901              }              }
3902            }            }
3903          else          else
3904  #endif  #endif
3905          /* Not UTF-8 mode */          /* Not UTF mode */
3906            {            {
3907            for (fi = min;; fi++)            for (fi = min;; fi++)
3908              {              {
3909              RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);              RMATCH(eptr, ecode, offset_top, md, eptrb, RM33);
3910              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3911              if (fi >= max) MRRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3912              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
3913                {                {
3914                SCHECK_PARTIAL();                SCHECK_PARTIAL();
3915                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3916                }                }
3917              if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);              if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3918              }              }
3919            }            }
3920          /* Control never gets here */          /* Control never gets here */
# Line 3557  for (;;) Line 3926  for (;;)
3926          {          {
3927          pp = eptr;          pp = eptr;
3928    
3929  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
3930          /* UTF-8 mode */          if (utf)
         if (utf8)  
3931            {            {
3932            register unsigned int d;            register unsigned int d;
3933            for (i = min; i < max; i++)            for (i = min; i < max; i++)
# Line 3585  for (;;) Line 3953  for (;;)
3953            }            }
3954          else          else
3955  #endif  #endif
3956          /* Not UTF-8 mode */          /* Not UTF mode */
3957            {            {
3958            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3959              {              {
# Line 3606  for (;;) Line 3974  for (;;)
3974              }              }
3975            }            }
3976    
3977          MRRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
3978          }          }
3979        }        }
3980      /* Control never gets here */      /* Control never gets here */
# Line 3618  for (;;) Line 3986  for (;;)
3986      case OP_TYPEEXACT:      case OP_TYPEEXACT:
3987      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
3988      minimize = TRUE;      minimize = TRUE;
3989      ecode += 3;      ecode += 1 + IMM2_SIZE;
3990      goto REPEATTYPE;      goto REPEATTYPE;
3991    
3992      case OP_TYPEUPTO:      case OP_TYPEUPTO:
# Line 3626  for (;;) Line 3994  for (;;)
3994      min = 0;      min = 0;
3995      max = GET2(ecode, 1);      max = GET2(ecode, 1);
3996      minimize = *ecode == OP_TYPEMINUPTO;      minimize = *ecode == OP_TYPEMINUPTO;
3997      ecode += 3;      ecode += 1 + IMM2_SIZE;
3998      goto REPEATTYPE;      goto REPEATTYPE;
3999    
4000      case OP_TYPEPOSSTAR:      case OP_TYPEPOSSTAR:
# Line 3654  for (;;) Line 4022  for (;;)
4022      possessive = TRUE;      possessive = TRUE;
4023      min = 0;      min = 0;
4024      max = GET2(ecode, 1);      max = GET2(ecode, 1);
4025      ecode += 3;      ecode += 1 + IMM2_SIZE;
4026      goto REPEATTYPE;      goto REPEATTYPE;
4027    
4028      case OP_TYPESTAR:      case OP_TYPESTAR:
# Line 3700  for (;;) Line 4068  for (;;)
4068          switch(prop_type)          switch(prop_type)
4069            {            {
4070            case PT_ANY:            case PT_ANY:
4071            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
4072            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
4073              {              {
4074              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4075                {                {
4076                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4077                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4078                }                }
4079              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4080              }              }
# Line 3719  for (;;) Line 4087  for (;;)
4087              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4088                {                {
4089                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4090                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4091                }                }
4092              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4093              chartype = UCD_CHARTYPE(c);              chartype = UCD_CHARTYPE(c);
4094              if ((chartype == ucp_Lu ||              if ((chartype == ucp_Lu ||
4095                   chartype == ucp_Ll ||                   chartype == ucp_Ll ||
4096                   chartype == ucp_Lt) == prop_fail_result)                   chartype == ucp_Lt) == prop_fail_result)
4097                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4098              }              }
4099            break;            break;
4100    
# Line 3736  for (;;) Line 4104  for (;;)
4104              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4105                {                {
4106                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4107                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4108                }                }
4109              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4110              if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result)              if ((UCD_CATEGORY(c) == prop_value) == prop_fail_result)
4111                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4112              }              }
4113            break;            break;
4114    
# Line 3750  for (;;) Line 4118  for (;;)
4118              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4119                {                {
4120                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4121                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4122                }                }
4123              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4124              if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result)              if ((UCD_CHARTYPE(c) == prop_value) == prop_fail_result)
4125                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4126              }              }
4127            break;            break;
4128    
# Line 3764  for (;;) Line 4132  for (;;)
4132              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4133                {                {
4134                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4135                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4136                }                }
4137              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4138              if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result)              if ((UCD_SCRIPT(c) == prop_value) == prop_fail_result)
4139                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4140              }              }
4141            break;            break;
4142    
# Line 3779  for (;;) Line 4147  for (;;)
4147              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4148                {                {
4149                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4150                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4151                }                }
4152              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4153              category = UCD_CATEGORY(c);              category = UCD_CATEGORY(c);
4154              if ((category == ucp_L || category == ucp_N) == prop_fail_result)              if ((category == ucp_L || category == ucp_N) == prop_fail_result)
4155                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4156              }              }
4157            break;            break;
4158    
# Line 3794  for (;;) Line 4162  for (;;)
4162              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4163                {                {
4164                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4165                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4166                }                }
4167              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4168              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4169                   c == CHAR_FF || c == CHAR_CR)                   c == CHAR_FF || c == CHAR_CR)
4170                     == prop_fail_result)                     == prop_fail_result)
4171                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4172              }              }
4173            break;            break;
4174    
# Line 3810  for (;;) Line 4178  for (;;)
4178              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4179                {                {
4180                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4181                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4182                }                }
4183              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4184              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||              if ((UCD_CATEGORY(c) == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
4185                   c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)                   c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
4186                     == prop_fail_result)                     == prop_fail_result)
4187                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4188              }              }
4189            break;            break;
4190    
# Line 3827  for (;;) Line 4195  for (;;)
4195              if (eptr >= md->end_subject)              if (eptr >= md->end_subject)
4196                {                {
4197                SCHECK_PARTIAL();                SCHECK_PARTIAL();
4198                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4199                }                }
4200              GETCHARINCTEST(c, eptr);              GETCHARINCTEST(c, eptr);
4201              category = UCD_CATEGORY(c);              category = UCD_CATEGORY(c);
4202              if ((category == ucp_L || category == ucp_N || c == CHAR_UNDERSCORE)              if ((category == ucp_L || category == ucp_N || c == CHAR_UNDERSCORE)
4203                     == prop_fail_result)                     == prop_fail_result)
4204                MRRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4205              }              }
4206            break;            break;
4207    
# Line 3854  for (;;) Line 4222  for (;;)
4222            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4223              {              {
4224              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4225              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4226              }              }
4227            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
4228            if (UCD_CATEGORY(c) == ucp_M) MRRETURN(MATCH_NOMATCH);            if (UCD_CATEGORY(c) == ucp_M) RRETURN(MATCH_NOMATCH);
4229            while (eptr < md->end_subject)            while (eptr < md->end_subject)
4230              {              {
4231              int len = 1;              int len = 1;
4232              if (!utf8) c = *eptr; else { GETCHARLEN(c, eptr, len); }              if (!utf) c = *eptr; else { GETCHARLEN(c, eptr, len); }
4233              if (UCD_CATEGORY(c) != ucp_M) break;              if (UCD_CATEGORY(c) != ucp_M) break;
4234              eptr += len;              eptr += len;
4235              }              }
4236              CHECK_PARTIAL();
4237            }            }
4238          }          }
4239    
# Line 3873  for (;;) Line 4242  for (;;)
4242    
4243  /* Handle all other cases when the coding is UTF-8 */  /* Handle all other cases when the coding is UTF-8 */
4244    
4245  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF
4246        if (utf8) switch(ctype)        if (utf) switch(ctype)
4247          {          {
4248          case OP_ANY:          case OP_ANY:
4249          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
# Line 3882  for (;;) Line 4251  for (;;)
4251            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4252              {              {
4253              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4254              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4255                }
4256              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4257              if (md->partial != 0 &&
4258                  eptr + 1 >= md->end_subject &&
4259                  NLBLOCK->nltype == NLTYPE_FIXED &&
4260                  NLBLOCK->nllen == 2 &&
4261                  *eptr == NLBLOCK->nl[0])
4262                {
4263                md->hitend = TRUE;
4264                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4265              }              }
           if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);  
4266            eptr++;            eptr++;
4267            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4268            }            }
4269          break;          break;
4270    
# Line 3896  for (;;) Line 4274  for (;;)
4274            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4275              {              {
4276              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4277              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4278              }              }
4279            eptr++;            eptr++;
4280            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4281            }            }
4282          break;          break;
4283    
4284          case OP_ANYBYTE:          case OP_ANYBYTE:
4285          if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);          if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
4286          eptr += min;          eptr += min;
4287          break;          break;
4288    
# Line 3914  for (;;) Line 4292  for (;;)
4292            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4293              {              {
4294              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4295              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4296              }              }
4297            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4298            switch(c)            switch(c)
4299              {              {
4300              default: MRRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
4301    
4302              case 0x000d:              case 0x000d:
4303              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
# Line 3933  for (;;) Line 4311  for (;;)
4311              case 0x0085:              case 0x0085:
4312              case 0x2028:              case 0x2028:
4313              case 0x2029:              case 0x2029:
4314              if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);              if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4315              break;              break;
4316              }              }
4317            }            }
# Line 3945  for (;;) Line 4323  for (;;)
4323            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4324              {              {
4325              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4326              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4327              }              }
4328            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4329            switch(c)            switch(c)
# Line 3970  for (;;) Line 4348  for (;;)
4348              case 0x202f:    /* NARROW NO-BREAK SPACE */              case 0x202f:    /* NARROW NO-BREAK SPACE */
4349              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */              case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4350              case 0x3000:    /* IDEOGRAPHIC SPACE */              case 0x3000:    /* IDEOGRAPHIC SPACE */
4351              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4352              }              }
4353            }            }
4354          break;          break;
# Line 3981  for (;;) Line 4359  for (;;)
4359            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4360              {              {
4361              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4362              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4363              }              }
4364            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4365            switch(c)            switch(c)
4366              {              {
4367              default: MRRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
4368              case 0x09:      /* HT */              case 0x09:      /* HT */
4369              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4370              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
# Line 4017  for (;;) Line 4395  for (;;)
4395            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4396              {              {
4397              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4398              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4399              }              }
4400            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4401            switch(c)            switch(c)
# Line 4030  for (;;) Line 4408  for (;;)
4408              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4409              case 0x2028:    /* LINE SEPARATOR */              case 0x2028:    /* LINE SEPARATOR */
4410              case 0x2029:    /* PARAGRAPH SEPARATOR */              case 0x2029:    /* PARAGRAPH SEPARATOR */
4411              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4412              }              }
4413            }            }
4414          break;          break;
# Line 4041  for (;;) Line 4419  for (;;)
4419            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4420              {              {
4421              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4422              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4423              }              }
4424            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4425            switch(c)            switch(c)
4426              {              {
4427              default: MRRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
4428              case 0x0a:      /* LF */              case 0x0a:      /* LF */
4429              case 0x0b:      /* VT */              case 0x0b:      /* VT */
4430              case 0x0c:      /* FF */              case 0x0c:      /* FF */
# Line 4065  for (;;) Line 4443  for (;;)
4443            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4444              {              {
4445              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4446              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4447              }              }
4448            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
4449            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
4450              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4451            }            }
4452          break;          break;
4453    
# Line 4079  for (;;) Line 4457  for (;;)
4457            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4458              {              {
4459              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4460              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4461              }              }
4462            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_digit) == 0)
4463              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4464              eptr++;
4465            /* 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 */
4466            }            }
4467          break;          break;
# Line 4093  for (;;) Line 4472  for (;;)
4472            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4473              {              {
4474              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4475              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4476              }              }
4477            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
4478              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4479            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            eptr++;
4480              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4481            }            }
4482          break;          break;
4483    
# Line 4107  for (;;) Line 4487  for (;;)
4487            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4488              {              {
4489              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4490              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4491              }              }
4492            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_space) == 0)
4493              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4494              eptr++;
4495            /* 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 */
4496            }            }
4497          break;          break;
# Line 4121  for (;;) Line 4502  for (;;)
4502            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4503              {              {
4504              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4505              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4506              }              }
4507            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)            if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
4508              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4509            while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);            eptr++;
4510              ACROSSCHAR(eptr < md->end_subject, *eptr, eptr++);
4511            }            }
4512          break;          break;
4513    
# Line 4135  for (;;) Line 4517  for (;;)
4517            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4518              {              {
4519              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4520              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4521              }              }
4522            if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)            if (*eptr >= 128 || (md->ctypes[*eptr] & ctype_word) == 0)
4523              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4524              eptr++;
4525            /* 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 */
4526            }            }
4527          break;          break;
# Line 4148  for (;;) Line 4531  for (;;)
4531          }  /* End switch(ctype) */          }  /* End switch(ctype) */
4532    
4533        else        else
4534  #endif     /* SUPPORT_UTF8 */  #endif     /* SUPPORT_UTF */
4535    
4536        /* 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
4537        than OP_PROP and OP_NOTPROP. */        than OP_PROP and OP_NOTPROP. */
# Line 4161  for (;;) Line 4544  for (;;)
4544            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4545              {              {
4546              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4547              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4548                }
4549              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
4550              if (md->partial != 0 &&
4551                  eptr + 1 >= md->end_subject &&
4552                  NLBLOCK->nltype == NLTYPE_FIXED &&
4553                  NLBLOCK->nllen == 2 &&
4554                  *eptr == NLBLOCK->nl[0])
4555                {
4556                md->hitend = TRUE;
4557                if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);
4558              }              }
           if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);  
4559            eptr++;            eptr++;
4560            }            }
4561          break;          break;
# Line 4172  for (;;) Line 4564  for (;;)
4564          if (eptr > md->end_subject - min)          if (eptr > md->end_subject - min)
4565            {            {
4566            SCHECK_PARTIAL();            SCHECK_PARTIAL();
4567            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
4568            }            }
4569          eptr += min;          eptr += min;
4570          break;          break;
# Line 4181  for (;;) Line 4573  for (;;)
4573          if (eptr > md->end_subject - min)          if (eptr > md->end_subject - min)
4574            {            {
4575            SCHECK_PARTIAL();            SCHECK_PARTIAL();
4576            MRRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
4577            }            }
4578          eptr += min;          eptr += min;
4579          break;          break;
# Line 4192  for (;;) Line 4584  for (;;)
4584            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4585              {              {
4586              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4587              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4588              }              }
4589            switch(*eptr++)            switch(*eptr++)
4590              {              {
4591              default: MRRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
4592    
4593              case 0x000d:              case 0x000d:
4594              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;              if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
# Line 4208  for (;;) Line 4600  for (;;)
4600              case 0x000b:              case 0x000b:
4601              case 0x000c:              case 0x000c:
4602              case 0x0085:              case 0x0085:
4603              if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);  #ifdef COMPILE_PCRE16
4604                case 0x2028:
4605                case 0x2029:
4606    #endif
4607                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4608              break;              break;
4609              }              }
4610            }            }
# Line 4220  for (;;) Line 4616  for (;;)
4616            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4617              {              {
4618              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4619              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4620              }              }
4621            switch(*eptr++)            switch(*eptr++)
4622              {              {
# Line 4228  for (;;) Line 4624  for (;;)
4624              case 0x09:      /* HT */              case 0x09:      /* HT */
4625              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4626              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
4627              MRRETURN(MATCH_NOMATCH);  #ifdef COMPILE_PCRE16
4628                case 0x1680:    /* OGHAM SPACE MARK */
4629                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4630                case 0x2000:    /* EN QUAD */
4631                case 0x2001:    /* EM QUAD */
4632                case 0x2002:    /* EN SPACE */
4633                case 0x2003:    /* EM SPACE */
4634                case 0x2004:    /* THREE-PER-EM SPACE */
4635                case 0x2005:    /* FOUR-PER-EM SPACE */
4636                case 0x2006:    /* SIX-PER-EM SPACE */
4637                case 0x2007:    /* FIGURE SPACE */
4638                case 0x2008:    /* PUNCTUATION SPACE */
4639                case 0x2009:    /* THIN SPACE */
4640                case 0x200A:    /* HAIR SPACE */
4641                case 0x202f:    /* NARROW NO-BREAK SPACE */
4642                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4643                case 0x3000:    /* IDEOGRAPHIC SPACE */
4644    #endif
4645                RRETURN(MATCH_NOMATCH);
4646              }              }
4647            }            }
4648          break;          break;
# Line 4239  for (;;) Line 4653  for (;;)
4653            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4654              {              {
4655              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4656              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4657              }              }
4658            switch(*eptr++)            switch(*eptr++)
4659              {              {
4660              default: MRRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
4661              case 0x09:      /* HT */              case 0x09:      /* HT */
4662              case 0x20:      /* SPACE */              case 0x20:      /* SPACE */
4663              case 0xa0:      /* NBSP */              case 0xa0:      /* NBSP */
4664    #ifdef COMPILE_PCRE16
4665                case 0x1680:    /* OGHAM SPACE MARK */
4666                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
4667                case 0x2000:    /* EN QUAD */
4668                case 0x2001:    /* EM QUAD */
4669                case 0x2002:    /* EN SPACE */
4670                case 0x2003:    /* EM SPACE */
4671                case 0x2004:    /* THREE-PER-EM SPACE */
4672                case 0x2005:    /* FOUR-PER-EM SPACE */
4673                case 0x2006:    /* SIX-PER-EM SPACE */
4674                case 0x2007:    /* FIGURE SPACE */
4675                case 0x2008:    /* PUNCTUATION SPACE */
4676                case 0x2009:    /* THIN SPACE */
4677                case 0x200A:    /* HAIR SPACE */
4678                case 0x202f:    /* NARROW NO-BREAK SPACE */
4679                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4680                case 0x3000:    /* IDEOGRAPHIC SPACE */
4681    #endif
4682              break;              break;
4683              }              }
4684            }            }
# Line 4258  for (;;) Line 4690  for (;;)
4690            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4691              {              {
4692              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4693              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4694              }              }
4695            switch(*eptr++)            switch(*eptr++)
4696              {              {
# Line 4268  for (;;) Line 4700  for (;;)
4700              case 0x0c:      /* FF */              case 0x0c:      /* FF */
4701              case 0x0d:      /* CR */              case 0x0d:      /* CR */
4702              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4703              MRRETURN(MATCH_NOMATCH);  #ifdef COMPILE_PCRE16
4704                case 0x2028:    /* LINE SEPARATOR */
4705                case 0x2029:    /* PARAGRAPH SEPARATOR */
4706    #endif
4707                RRETURN(MATCH_NOMATCH);
4708              }              }
4709            }            }
4710          break;          break;
# Line 4279  for (;;) Line 4715  for (;;)
4715            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4716              {              {
4717              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4718              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4719              }              }
4720            switch(*eptr++)            switch(*eptr++)
4721              {              {
4722              default: MRRETURN(MATCH_NOMATCH);              default: RRETURN(MATCH_NOMATCH);
4723              case 0x0a:      /* LF */              case 0x0a:      /* LF */
4724              case 0x0b:      /* VT */              case 0x0b:      /* VT */
4725              case 0x0c:      /* FF */              case 0x0c:      /* FF */
4726              case 0x0d:      /* CR */              case 0x0d:      /* CR */
4727              case 0x85:      /* NEL */              case 0x85:      /* NEL */
4728    #ifdef COMPILE_PCRE16
4729                case 0x2028:    /* LINE SEPARATOR */
4730                case 0x2029:    /* PARAGRAPH SEPARATOR */
4731    #endif
4732              break;              break;
4733              }              }
4734            }            }
# Line 4300  for (;;) Line 4740  for (;;)
4740            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4741              {              {
4742              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4743              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4744              }              }
4745            if ((md->ctypes[*eptr++] & ctype_digit) != 0) MRRETURN(MATCH_NOMATCH);            if (MAX_255(*eptr) && (md->ctypes[*eptr] & ctype_digit) != 0)
4746                RRETURN(MATCH_NOMATCH);
4747              eptr++;
4748            }            }
4749          break;          break;
4750    
# Line 4312  for (;;) Line 4754  for (;;)
4754            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4755              {              {
4756              SCHECK_PARTIAL();              SCHECK_PARTIAL();
4757              MRRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
4758              }              }
4759            if ((md->ctypes[*eptr++] & ctype_digit) == 0) MRRETURN(MATCH_NOMATCH);            if (!MAX_255(*eptr) || (md->ctypes[*eptr] & ctype_digit) == 0)
4760                RRETURN(MATCH_NOMATCH);
4761              eptr++;
4762            }            }
4763          break;          break;
4764    
# Line 4324  for (;;) Line 4768  for (;;)
4768            if (eptr >= md->end_subject)            if (eptr >= md->end_subject)
4769              {              {
4770              SCHECK_PARTIAL();              SCHECK_PARTIAL();