/[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 87 by nigel, Sat Feb 24 21:41:21 2007 UTC revision 500 by ph10, Sat Mar 6 19:00:29 2010 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2006 University of Cambridge             Copyright (c) 1997-2010 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45    #ifdef HAVE_CONFIG_H
46    #include "config.h"
47    #endif
48    
49    #define NLBLOCK md             /* Block containing newline information */
50    #define PSSTART start_subject  /* Field containing processed string start */
51    #define PSEND   end_subject    /* Field containing processed string end */
52    
53  #include "pcre_internal.h"  #include "pcre_internal.h"
54    
55    /* Undefine some potentially clashing cpp symbols */
56    
57  /* Structure for building a chain of data that actually lives on the  #undef min
58  stack, for holding the values of the subject pointer at the start of each  #undef max
 subpattern, so as to detect when an empty string has been matched by a  
 subpattern - to break infinite loops. When NO_RECURSE is set, these blocks  
 are on the heap, not on the stack. */  
   
 typedef struct eptrblock {  
   struct eptrblock *epb_prev;  
   USPTR epb_saved_eptr;  
 } eptrblock;  
59    
60  /* Flag bits for the match() function */  /* Flag bits for the match() function */
61    
62  #define match_condassert   0x01    /* Called to check a condition assertion */  #define match_condassert     0x01  /* Called to check a condition assertion */
63  #define match_isgroup      0x02    /* Set if start of bracketed group */  #define match_cbegroup       0x02  /* Could-be-empty unlimited repeat group */
64    
65  /* Non-error returns from the match() function. Error returns are externally  /* Non-error returns from the match() function. Error returns are externally
66  defined PCRE_ERROR_xxx codes, which are all negative. */  defined PCRE_ERROR_xxx codes, which are all negative. */
# Line 68  defined PCRE_ERROR_xxx codes, which are Line 68  defined PCRE_ERROR_xxx codes, which are
68  #define MATCH_MATCH        1  #define MATCH_MATCH        1
69  #define MATCH_NOMATCH      0  #define MATCH_NOMATCH      0
70    
71    /* Special internal returns from the match() function. Make them sufficiently
72    negative to avoid the external error codes. */
73    
74    #define MATCH_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 81  static const char rep_max[] = { 0, 0, 0, Line 89  static const char rep_max[] = { 0, 0, 0,
89    
90    
91    
92  #ifdef DEBUG  #ifdef PCRE_DEBUG
93  /*************************************************  /*************************************************
94  *        Debugging function to print chars       *  *        Debugging function to print chars       *
95  *************************************************/  *************************************************/
# Line 101  Returns:     nothing Line 109  Returns:     nothing
109  static void  static void
110  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
111  {  {
112  int c;  unsigned int c;
113  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;
114  while (length-- > 0)  while (length-- > 0)
115    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
# Line 133  match_ref(int offset, register USPTR ept Line 141  match_ref(int offset, register USPTR ept
141  {  {
142  USPTR p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
143    
144  #ifdef DEBUG  #ifdef PCRE_DEBUG
145  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
146    printf("matching subject <null>");    printf("matching subject <null>");
147  else  else
# Line 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 186  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
220  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
221  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256  #ifdef DEBUG  
257  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #ifdef PCRE_DEBUG
258    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
275  #else  #else
276    
277    
278  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
279  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     {\  
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 254  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 269  typedef struct heapframe { Line 322  typedef struct heapframe {
322    
323    /* Function arguments that may change */    /* Function arguments that may change */
324    
325    const uschar *Xeptr;    USPTR Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      USPTR Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
331    int Xflags;    int Xflags;
332    int Xrdepth;    unsigned int Xrdepth;
333    
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    USPTR Xcallpat;
337    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
338    const uschar *Xdata;    USPTR Xcharptr;
339    const uschar *Xnext;  #endif
340    const uschar *Xpp;    USPTR Xdata;
341    const uschar *Xprev;    USPTR Xnext;
342    const uschar *Xsaved_eptr;    USPTR Xpp;
343      USPTR Xprev;
344      USPTR Xsaved_eptr;
345    
346    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
347    
348    BOOL Xcur_is_word;    BOOL Xcur_is_word;
349    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
350    BOOL Xprev_is_word;    BOOL Xprev_is_word;
351    
352    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 358  typedef struct heapframe {
358    int Xprop_category;    int Xprop_category;
359    int Xprop_chartype;    int Xprop_chartype;
360    int Xprop_script;    int Xprop_script;
361    int *Xprop_test_variable;    int Xoclength;
362      uschar Xocchars[8];
363  #endif  #endif
364    
365      int Xcodelink;
366    int Xctype;    int Xctype;
367    int Xfc;    unsigned int Xfc;
368    int Xfi;    int Xfi;
369    int Xlength;    int Xlength;
370    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 378  typedef struct heapframe {
378    
379    eptrblock Xnewptrb;    eptrblock Xnewptrb;
380    
381    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
382    
383    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
384    
385  } heapframe;  } heapframe;
386    
# Line 340  typedef struct heapframe { Line 396  typedef struct heapframe {
396  *         Match from current position            *  *         Match from current position            *
397  *************************************************/  *************************************************/
398    
399  /* On entry ecode points to the first opcode, and eptr to the first character  /* This function is called recursively in many circumstances. Whenever it
 in the subject string, while eptrb holds the value of eptr at the start of the  
 last bracketed group - used for breaking infinite loops matching zero-length  
 strings. This function is called recursively in many circumstances. Whenever it  
400  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
401  same response.  same response. */
402    
403    /* These macros pack up tests that are used for partial matching, and which
404    appears several times in the code. We set the "hit end" flag if the pointer is
405    at the end of the subject and also past the start of the subject (i.e.
406    something has been matched). For hard partial matching, we then return
407    immediately. The second one is used when we already know we are past the end of
408    the subject. */
409    
410    #define CHECK_PARTIAL()\
411      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417  Performance note: It might be tempting to extract commonly used fields from the  #define SCHECK_PARTIAL()\
418  md structure (e.g. utf8, end_subject) into individual variables to improve    if (md->partial != 0 && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424    
425    /* Performance note: It might be tempting to extract commonly used fields from
426    the md structure (e.g. utf8, end_subject) into individual variables to improve
427  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
428  made performance worse.  made performance worse.
429    
430  Arguments:  Arguments:
431     eptr        pointer in subject     eptr        pointer to current character in subject
432     ecode       position in code     ecode       pointer to current position in compiled code
433       mstart      pointer to the current match start position (can be modified
434                     by encountering \K)
435     offset_top  current top pointer     offset_top  current top pointer
436     md          pointer to "static" info for the match     md          pointer to "static" info for the match
437     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 439  Arguments:
439                   brackets - for testing for empty matches                   brackets - for testing for empty matches
440     flags       can contain     flags       can contain
441                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
442                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
443                       group that can match an empty string
444     rdepth      the recursion depth     rdepth      the recursion depth
445    
446  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 372  Returns:       MATCH_MATCH if matched Line 450  Returns:       MATCH_MATCH if matched
450  */  */
451    
452  static int  static int
453  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
454    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
455    int flags, int rdepth)    int flags, unsigned int rdepth)
456  {  {
457  /* 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,
458  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
459  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
460    
461  register int  rrc;    /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
462  register int  i;      /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
463  register int  c;      /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
464  register BOOL utf8;   /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466    BOOL minimize, possessive; /* Quantifier options */
467    int condcode;
468    
469  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
470  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
# Line 398  frame->Xprevframe = NULL;            /* Line 479  frame->Xprevframe = NULL;            /*
479    
480  frame->Xeptr = eptr;  frame->Xeptr = eptr;
481  frame->Xecode = ecode;  frame->Xecode = ecode;
482    frame->Xmstart = mstart;
483  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
484  frame->Xims = ims;  frame->Xims = ims;
485  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 494  HEAP_RECURSE:
494    
495  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
496  #define ecode              frame->Xecode  #define ecode              frame->Xecode
497    #define mstart             frame->Xmstart
498  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
499  #define ims                frame->Xims  #define ims                frame->Xims
500  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 424  HEAP_RECURSE: Line 507  HEAP_RECURSE:
507  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
508  #endif  #endif
509  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
510    #define codelink           frame->Xcodelink
511  #define data               frame->Xdata  #define data               frame->Xdata
512  #define next               frame->Xnext  #define next               frame->Xnext
513  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 434  HEAP_RECURSE: Line 518  HEAP_RECURSE:
518    
519  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
520  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
521  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
522    
523  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 529  HEAP_RECURSE:
529  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
530  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
531  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
532  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
533    #define occhars            frame->Xocchars
534  #endif  #endif
535    
536  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 554  HEAP_RECURSE:
554  get preserved during recursion in the normal way. In this environment, fi and  get preserved during recursion in the normal way. In this environment, fi and
555  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
556    
557  #else  #else         /* NO_RECURSE not defined */
558  #define fi i  #define fi i
559  #define fc c  #define fc c
560    
# Line 489  recursion_info new_recursive;      /* wi Line 573  recursion_info new_recursive;      /* wi
573                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
574  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
575  BOOL condition;  BOOL condition;
 BOOL minimize;  
576  BOOL prev_is_word;  BOOL prev_is_word;
577    
578  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 584  int prop_fail_result;
584  int prop_category;  int prop_category;
585  int prop_chartype;  int prop_chartype;
586  int prop_script;  int prop_script;
587  int *prop_test_variable;  int oclength;
588    uschar occhars[8];
589  #endif  #endif
590    
591    int codelink;
592  int ctype;  int ctype;
593  int length;  int length;
594  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 601  int save_offset1, save_offset2, save_off
601  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
602    
603  eptrblock newptrb;  eptrblock newptrb;
604  #endif  #endif     /* NO_RECURSE */
605    
606  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
607  variables. */  variables. */
# Line 524  variables. */ Line 609  variables. */
609  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
610  prop_value = 0;  prop_value = 0;
611  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
612  #endif  #endif
613    
614    
615    /* This label is used for tail recursion, which is used in a few cases even
616    when NO_RECURSE is not defined, in order to reduce the amount of stack that is
617    used. Thanks to Ian Taylor for noticing this possibility and sending the
618    original patch. */
619    
620    TAIL_RECURSE:
621    
622  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
623  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
624  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
625  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
626  defined). However, RMATCH isn't like a function call because it's quite a  defined). However, RMATCH isn't like a function call because it's quite a
627  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
629    
630    #ifdef SUPPORT_UTF8
631    utf8 = md->utf8;       /* Local copy of the flag */
632    #else
633    utf8 = FALSE;
634    #endif
635    
636  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
637  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
638    
# Line 542  if (md->match_call_count++ >= md->match_ Line 640  if (md->match_call_count++ >= md->match_
640  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);  if (rdepth >= md->match_limit_recursion) RRETURN(PCRE_ERROR_RECURSIONLIMIT);
641    
642  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
 utf8 = md->utf8;       /* Local copy of the flag */  
643    
644  /* At the start of a bracketed group, add the current subject pointer to the  /* At the start of a group with an unlimited repeat that may match an empty
645  stack of such pointers, to be re-instated at the end of the group when we hit  string, the match_cbegroup flag is set. When this is the case, add the current
646  the closing ket. When match() is called in other circumstances, we don't add to  subject pointer to the chain of such remembered pointers, to be checked when we
647  this stack. */  hit the closing ket, in order to break infinite loops that match no characters.
648    When match() is called in other circumstances, don't add to the chain. The
649    match_cbegroup flag must NOT be used with tail recursion, because the memory
650    block that is used is on the stack, so a new one may be required for each
651    match(). */
652    
653  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
654    {    {
   newptrb.epb_prev = eptrb;  
655    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
656      newptrb.epb_prev = eptrb;
657    eptrb = &newptrb;    eptrb = &newptrb;
658    }    }
659    
660  /* Now start processing the operations. */  /* Now start processing the opcodes. */
661    
662  for (;;)  for (;;)
663    {    {
664      minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
   minimize = FALSE;  
   
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. */  
   
   if (md->partial &&  
       eptr >= md->end_subject &&  
       eptr > md->start_match)  
     md->hitend = TRUE;  
   
   /* Opening capturing bracket. If there is space in the offset vector, save  
   the current subject position in the working slot at the top of the vector. We  
   mustn't change the current values of the data slot, because they may be set  
   from a previous iteration of this group, and be referred to by a reference  
   inside the group.  
   
   If the bracket fails to match, we need to restore this value and also the  
   values of the final offsets, in case they were set by a previous iteration of  
   the same bracket.  
   
   If there isn't enough space in the offset vector, treat this as if it were a  
   non-capturing bracket. Don't worry about setting the flag for the error case  
   here; that is handled in the code for KET. */  
666    
667    if (op > OP_BRA)    switch(op)
668      {      {
669      number = op - OP_BRA;      case OP_FAIL:
670        RRETURN(MATCH_NOMATCH);
     /* For extended extraction brackets (large number), we have to fish out the  
     number from a dummy opcode at the start. */  
671    
672      if (number > EXTRACT_BASIC_MAX)      case OP_PRUNE:
673        number = GET2(ecode, 2+LINK_SIZE);      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
674          ims, eptrb, flags, RM51);
675        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
676        RRETURN(MATCH_PRUNE);
677    
678        case OP_COMMIT:
679        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
680          ims, eptrb, flags, RM52);
681        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
682        RRETURN(MATCH_COMMIT);
683    
684        case OP_SKIP:
685        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
686          ims, eptrb, flags, RM53);
687        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
688        md->start_match_ptr = eptr;   /* Pass back current position */
689        RRETURN(MATCH_SKIP);
690    
691        case OP_THEN:
692        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
693          ims, eptrb, flags, RM54);
694        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
695        RRETURN(MATCH_THEN);
696    
697        /* Handle a capturing bracket. If there is space in the offset vector, save
698        the current subject position in the working slot at the top of the vector.
699        We mustn't change the current values of the data slot, because they may be
700        set from a previous iteration of this group, and be referred to by a
701        reference inside the group.
702    
703        If the bracket fails to match, we need to restore this value and also the
704        values of the final offsets, in case they were set by a previous iteration
705        of the same bracket.
706    
707        If there isn't enough space in the offset vector, treat this as if it were
708        a non-capturing bracket. Don't worry about setting the flag for the error
709        case here; that is handled in the code for KET. */
710    
711        case OP_CBRA:
712        case OP_SCBRA:
713        number = GET2(ecode, 1+LINK_SIZE);
714      offset = number << 1;      offset = number << 1;
715    
716  #ifdef DEBUG  #ifdef PCRE_DEBUG
717      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
718        printf("subject=");
719      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
720      printf("\n");      printf("\n");
721  #endif  #endif
# Line 612  for (;;) Line 730  for (;;)
730        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
731        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
732    
733          flags = (op == OP_SCBRA)? match_cbegroup : 0;
734        do        do
735          {          {
736          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
737            match_isgroup);            ims, eptrb, flags, RM1);
738          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
739          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
740          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
741          }          }
# Line 631  for (;;) Line 750  for (;;)
750        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
751        }        }
752    
753      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
754        as a non-capturing bracket. */
755    
756      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
757      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
758    
759    /* Other types of node can be handled by a switch */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
760    
761    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
762      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
763      case OP_BRA:     /* Non-capturing bracket: optimized */  
764      DPRINTF(("start bracket 0\n"));      /* Non-capturing bracket. Loop for all the alternatives. When we get to the
765      do      final alternative within the brackets, we would return the result of a
766        recursive call to match() whatever happened. We can reduce stack usage by
767        turning this into a tail recursion, except in the case when match_cbegroup
768        is set.*/
769    
770        case OP_BRA:
771        case OP_SBRA:
772        DPRINTF(("start non-capturing bracket\n"));
773        flags = (op >= OP_SBRA)? match_cbegroup : 0;
774        for (;;)
775        {        {
776        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
777          match_isgroup);          {
778        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (flags == 0)    /* Not a possibly empty group */
779              {
780              ecode += _pcre_OP_lengths[*ecode];
781              DPRINTF(("bracket 0 tail recursion\n"));
782              goto TAIL_RECURSE;
783              }
784    
785            /* Possibly empty group; can't use tail recursion. */
786    
787            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
788              eptrb, flags, RM48);
789            RRETURN(rrc);
790            }
791    
792          /* For non-final alternatives, continue the loop for a NOMATCH result;
793          otherwise return. */
794    
795          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
796            eptrb, flags, RM2);
797          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
798        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
799        }        }
800      while (*ecode == OP_ALT);      /* Control never reaches here. */
     DPRINTF(("bracket 0 failed\n"));  
     RRETURN(MATCH_NOMATCH);  
801    
802      /* Conditional group: compilation checked that there are no more than      /* Conditional group: compilation checked that there are no more than
803      two branches. If the condition is false, skipping the first branch takes us      two branches. If the condition is false, skipping the first branch takes us
804      past the end if there is only one branch, but that's OK because that is      past the end if there is only one branch, but that's OK because that is
805      exactly what going to the ket would do. */      exactly what going to the ket would do. As there is only one branch to be
806        obeyed, we can use tail recursion to avoid using another stack frame. */
807    
808      case OP_COND:      case OP_COND:
809      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
810        codelink= GET(ecode, 1);
811    
812        /* Because of the way auto-callout works during compile, a callout item is
813        inserted between OP_COND and an assertion condition. */
814    
815        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816          {
817          if (pcre_callout != NULL)
818            {
819            pcre_callout_block cb;
820            cb.version          = 1;   /* Version 1 of the callout block */
821            cb.callout_number   = ecode[LINK_SIZE+2];
822            cb.offset_vector    = md->offset_vector;
823            cb.subject          = (PCRE_SPTR)md->start_subject;
824            cb.subject_length   = md->end_subject - md->start_subject;
825            cb.start_match      = mstart - md->start_subject;
826            cb.current_position = eptr - md->start_subject;
827            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
828            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
829            cb.capture_top      = offset_top/2;
830            cb.capture_last     = md->capture_last;
831            cb.callout_data     = md->callout_data;
832            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
833            if (rrc < 0) RRETURN(rrc);
834            }
835          ecode += _pcre_OP_lengths[OP_CALLOUT];
836          }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840        /* Now see what the actual condition is */
841    
842        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
843          {
844          if (md->recursive == NULL)                /* Not recursing => FALSE */
845            {
846            condition = FALSE;
847            ecode += GET(ecode, 1);
848            }
849          else
850            {
851            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
852            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
853    
854            /* If the test is for recursion into a specific subpattern, and it is
855            false, but the test was set up by name, scan the table to see if the
856            name refers to any other numbers, and test them. The condition is true
857            if any one is set. */
858    
859            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
860              {
861              uschar *slotA = md->name_table;
862              for (i = 0; i < md->name_count; i++)
863                {
864                if (GET2(slotA, 0) == recno) break;
865                slotA += md->name_entry_size;
866                }
867    
868              /* Found a name for the number - there can be only one; duplicate
869              names for different numbers are allowed, but not vice versa. First
870              scan down for duplicates. */
871    
872              if (i < md->name_count)
873                {
874                uschar *slotB = slotA;
875                while (slotB > md->name_table)
876                  {
877                  slotB -= md->name_entry_size;
878                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
879                    {
880                    condition = GET2(slotB, 0) == md->recursive->group_num;
881                    if (condition) break;
882                    }
883                  else break;
884                  }
885    
886                /* Scan up for duplicates */
887    
888                if (!condition)
889                  {
890                  slotB = slotA;
891                  for (i++; i < md->name_count; i++)
892                    {
893                    slotB += md->name_entry_size;
894                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
895                      {
896                      condition = GET2(slotB, 0) == md->recursive->group_num;
897                      if (condition) break;
898                      }
899                    else break;
900                    }
901                  }
902                }
903              }
904    
905            /* Chose branch according to the condition */
906    
907            ecode += condition? 3 : GET(ecode, 1);
908            }
909          }
910    
911        else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
912        {        {
913        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
914        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
915          (md->recursive != NULL) :  
916          (offset < offset_top && md->offset_vector[offset] >= 0);        /* If the numbered capture is unset, but the reference was by name,
917        RMATCH(rrc, eptr, ecode + (condition?        scan the table to see if the name refers to any other numbers, and test
918          (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1))),        them. The condition is true if any one is set. This is tediously similar
919          offset_top, md, ims, eptrb, match_isgroup);        to the code above, but not close enough to try to amalgamate. */
920        RRETURN(rrc);  
921          if (!condition && condcode == OP_NCREF)
922            {
923            int refno = offset >> 1;
924            uschar *slotA = md->name_table;
925    
926            for (i = 0; i < md->name_count; i++)
927              {
928              if (GET2(slotA, 0) == refno) break;
929              slotA += md->name_entry_size;
930              }
931    
932            /* Found a name for the number - there can be only one; duplicate names
933            for different numbers are allowed, but not vice versa. First scan down
934            for duplicates. */
935    
936            if (i < md->name_count)
937              {
938              uschar *slotB = slotA;
939              while (slotB > md->name_table)
940                {
941                slotB -= md->name_entry_size;
942                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
943                  {
944                  offset = GET2(slotB, 0) << 1;
945                  condition = offset < offset_top &&
946                    md->offset_vector[offset] >= 0;
947                  if (condition) break;
948                  }
949                else break;
950                }
951    
952              /* Scan up for duplicates */
953    
954              if (!condition)
955                {
956                slotB = slotA;
957                for (i++; i < md->name_count; i++)
958                  {
959                  slotB += md->name_entry_size;
960                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
961                    {
962                    offset = GET2(slotB, 0) << 1;
963                    condition = offset < offset_top &&
964                      md->offset_vector[offset] >= 0;
965                    if (condition) break;
966                    }
967                  else break;
968                  }
969                }
970              }
971            }
972    
973          /* Chose branch according to the condition */
974    
975          ecode += condition? 3 : GET(ecode, 1);
976          }
977    
978        else if (condcode == OP_DEF)     /* DEFINE - always false */
979          {
980          condition = FALSE;
981          ecode += GET(ecode, 1);
982        }        }
983    
984      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
985      the final argument TRUE causes it to stop at the end of an assertion. */      the final argument match_condassert causes it to stop at the end of an
986        assertion. */
987    
988      else      else
989        {        {
990        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
991            match_condassert | match_isgroup);            match_condassert, RM3);
992        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
993          {          {
994          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
995            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
996          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
997          }          }
998        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
999          {          {
1000          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1001          }          }
1002        else ecode += GET(ecode, 1);        else
1003        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          {
1004          match_isgroup);          condition = FALSE;
1005        RRETURN(rrc);          ecode += codelink;
1006            }
1007        }        }
     /* Control never reaches here */  
1008    
1009      /* Skip over conditional reference or large extraction number data if      /* We are now at the branch that is to be obeyed. As there is only one,
1010      encountered. */      we can use tail recursion to avoid using another stack frame, except when
1011        match_cbegroup is required for an unlimited repeat of a possibly empty
1012        group. If the second alternative doesn't exist, we can just plough on. */
1013    
1014        if (condition || *ecode == OP_ALT)
1015          {
1016          ecode += 1 + LINK_SIZE;
1017          if (op == OP_SCOND)        /* Possibly empty group */
1018            {
1019            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1020            RRETURN(rrc);
1021            }
1022          else                       /* Group must match something */
1023            {
1024            flags = 0;
1025            goto TAIL_RECURSE;
1026            }
1027          }
1028        else                         /* Condition false & no alternative */
1029          {
1030          ecode += 1 + LINK_SIZE;
1031          }
1032        break;
1033    
1034    
1035        /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1036        to close any currently open capturing brackets. */
1037    
1038        case OP_CLOSE:
1039        number = GET2(ecode, 1);
1040        offset = number << 1;
1041    
1042    #ifdef PCRE_DEBUG
1043          printf("end bracket %d at *ACCEPT", number);
1044          printf("\n");
1045    #endif
1046    
1047      case OP_CREF:      md->capture_last = number;
1048      case OP_BRANUMBER:      if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1049          {
1050          md->offset_vector[offset] =
1051            md->offset_vector[md->offset_end - number];
1052          md->offset_vector[offset+1] = eptr - md->start_subject;
1053          if (offset_top <= offset) offset_top = offset + 2;
1054          }
1055      ecode += 3;      ecode += 3;
1056      break;      break;
1057    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
1058    
1059        /* End of the pattern, either real or forced. If we are in a top-level
1060        recursion, we should restore the offsets appropriately and continue from
1061        after the call. */
1062    
1063        case OP_ACCEPT:
1064      case OP_END:      case OP_END:
1065      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
1066        {        {
# Line 713  for (;;) Line 1069  for (;;)
1069        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1070        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1071          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1072        md->start_match = rec->save_start;        offset_top = rec->save_offset_top;
1073        ims = original_ims;        ims = original_ims;
1074        ecode = rec->after_call;        ecode = rec->after_call;
1075        break;        break;
1076        }        }
1077    
1078      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1079      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1080        the subject. In both cases, backtracking will then try other alternatives,
1081        if any. */
1082    
1083        if (eptr == mstart &&
1084            (md->notempty ||
1085              (md->notempty_atstart &&
1086                mstart == md->start_subject + md->start_offset)))
1087          RRETURN(MATCH_NOMATCH);
1088    
1089        /* Otherwise, we have a match. */
1090    
1091      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      md->end_match_ptr = eptr;           /* Record where we ended */
1092      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
1093      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1094      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
1095    
1096      /* Change option settings */      /* Change option settings */
# Line 745  for (;;) Line 1111  for (;;)
1111      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1112      do      do
1113        {        {
1114        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1115          match_isgroup);          RM4);
1116        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH)
1117        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          {
1118            mstart = md->start_match_ptr;   /* In case \K reset it */
1119            break;
1120            }
1121          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1122        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1123        }        }
1124      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 766  for (;;) Line 1136  for (;;)
1136      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1137      continue;      continue;
1138    
1139      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1140        PRUNE, or COMMIT means we must assume failure without checking subsequent
1141        branches. */
1142    
1143      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1144      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1145      do      do
1146        {        {
1147        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1148          match_isgroup);          RM5);
1149        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1150        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1151            {
1152            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1153            break;
1154            }
1155          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1156        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1157        }        }
1158      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 794  for (;;) Line 1171  for (;;)
1171  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1172      if (utf8)      if (utf8)
1173        {        {
1174        c = GET(ecode,1);        i = GET(ecode, 1);
1175        for (i = 0; i < c; i++)        while (i-- > 0)
1176          {          {
1177          eptr--;          eptr--;
1178          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1179          BACKCHAR(eptr)          BACKCHAR(eptr);
1180          }          }
1181        }        }
1182      else      else
# Line 808  for (;;) Line 1185  for (;;)
1185      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */      /* No UTF-8 support, or not in UTF-8 mode: count is byte count */
1186    
1187        {        {
1188        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1189        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1190        }        }
1191    
1192      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1193    
1194        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1195      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1196      break;      break;
1197    
# Line 830  for (;;) Line 1208  for (;;)
1208        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1209        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1210        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1211        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1212        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1213        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1214        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 865  for (;;) Line 1243  for (;;)
1243      case OP_RECURSE:      case OP_RECURSE:
1244        {        {
1245        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1246        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1247            GET2(callpat, 1 + LINK_SIZE);
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (new_recursive.group_num > EXTRACT_BASIC_MAX)  
         new_recursive.group_num = GET2(callpat, 2+LINK_SIZE);  
1248    
1249        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1250    
# Line 897  for (;;) Line 1270  for (;;)
1270    
1271        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1272              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1273        new_recursive.save_start = md->start_match;        new_recursive.save_offset_top = offset_top;
       md->start_match = eptr;  
1274    
1275        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1276        restore the offset and recursion data. */        restore the offset and recursion data. */
1277    
1278        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1279          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1280        do        do
1281          {          {
1282          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1283              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1284          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1285            {            {
1286            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 916  for (;;) Line 1289  for (;;)
1289              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1290            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1291            }            }
1292          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1293            {            {
1294            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1295              if (new_recursive.offset_save != stacksave)
1296                (pcre_free)(new_recursive.offset_save);
1297            RRETURN(rrc);            RRETURN(rrc);
1298            }            }
1299    
# Line 942  for (;;) Line 1317  for (;;)
1317      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1318      Check the alternative branches in turn - the matching won't pass the KET      Check the alternative branches in turn - the matching won't pass the KET
1319      for this kind of subpattern. If any one branch matches, we carry on as at      for this kind of subpattern. If any one branch matches, we carry on as at
1320      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1321        the start-of-match value in case it was changed by \K. */
1322    
1323      case OP_ONCE:      case OP_ONCE:
1324        {      prev = ecode;
1325        prev = ecode;      saved_eptr = eptr;
       saved_eptr = eptr;  
1326    
1327        do      do
1328          {
1329          RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1330          if (rrc == MATCH_MATCH)
1331          {          {
1332          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,          mstart = md->start_match_ptr;
1333            eptrb, match_isgroup);          break;
1334          if (rrc == MATCH_MATCH) break;          }
1335          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1336          ecode += GET(ecode,1);        ecode += GET(ecode,1);
1337          }        }
1338        while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1339    
1340        /* If hit the end of the group (which could be repeated), fail */      /* If hit the end of the group (which could be repeated), fail */
1341    
1342        if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);      if (*ecode != OP_ONCE && *ecode != OP_ALT) RRETURN(MATCH_NOMATCH);
1343    
1344        /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1345        mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1346    
1347        do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1348    
1349        offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1350        eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
1351    
1352        /* For a non-repeating ket, just continue at this level. This also      /* For a non-repeating ket, just continue at this level. This also
1353        happens for a repeating ket if no characters were matched in the group.      happens for a repeating ket if no characters were matched in the group.
1354        This is the forcible breaking of infinite loops as implemented in Perl      This is the forcible breaking of infinite loops as implemented in Perl
1355        5.005. If there is an options reset, it will get obeyed in the normal      5.005. If there is an options reset, it will get obeyed in the normal
1356        course of events. */      course of events. */
1357    
1358        if (*ecode == OP_KET || eptr == saved_eptr)      if (*ecode == OP_KET || eptr == saved_eptr)
1359          {        {
1360          ecode += 1+LINK_SIZE;        ecode += 1+LINK_SIZE;
1361          break;        break;
1362          }        }
1363    
1364        /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1365        preceding bracket, in the appropriate order. We need to reset any options      preceding bracket, in the appropriate order. The second "call" of match()
1366        that changed within the bracket before re-running it, so check the next      uses tail recursion, to avoid using another stack frame. We need to reset
1367        opcode. */      any options that changed within the bracket before re-running it, so
1368        check the next opcode. */
1369    
1370        if (ecode[1+LINK_SIZE] == OP_OPT)      if (ecode[1+LINK_SIZE] == OP_OPT)
1371          {        {
1372          ims = (ims & ~PCRE_IMS) | ecode[4];        ims = (ims & ~PCRE_IMS) | ecode[4];
1373          DPRINTF(("ims set to %02lx at group repeat\n", ims));        DPRINTF(("ims set to %02lx at group repeat\n", ims));
1374          }        }
1375    
1376        if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1377          {        {
1378          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1379          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1380          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        ecode = prev;
1381          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        flags = 0;
1382          }        goto TAIL_RECURSE;
       else  /* OP_KETRMAX */  
         {  
         RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
         if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
         }  
1383        }        }
1384      RRETURN(MATCH_NOMATCH);      else  /* OP_KETRMAX */
1385          {
1386          RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1387          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1388          ecode += 1 + LINK_SIZE;
1389          flags = 0;
1390          goto TAIL_RECURSE;
1391          }
1392        /* Control never gets here */
1393    
1394      /* An alternation is the end of a branch; scan along to find the end of the      /* An alternation is the end of a branch; scan along to find the end of the
1395      bracketed group and go to there. */      bracketed group and go to there. */
# Line 1018  for (;;) Line 1398  for (;;)
1398      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1399      break;      break;
1400    
1401      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1402      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1403      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1404      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1405      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1406    
1407      case OP_BRAZERO:      case OP_BRAZERO:
1408        {        {
1409        next = ecode+1;        next = ecode+1;
1410        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1411        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1412        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1413        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1414        }        }
1415      break;      break;
1416    
1417      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1418        {        {
1419        next = ecode+1;        next = ecode+1;
1420        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1421        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
         match_isgroup);  
1422        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1423        ecode++;        ecode++;
1424        }        }
1425      break;      break;
1426    
1427      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1428      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1429      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1430      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1431          ecode = next + 1 + LINK_SIZE;
1432          }
1433        break;
1434    
1435        /* End of a group, repeated or non-repeating. */
1436    
1437      case OP_KET:      case OP_KET:
1438      case OP_KETRMIN:      case OP_KETRMIN:
1439      case OP_KETRMAX:      case OP_KETRMAX:
1440        {      prev = ecode - GET(ecode, 1);
       prev = ecode - GET(ecode, 1);  
       saved_eptr = eptrb->epb_saved_eptr;  
   
       /* Back up the stack of bracket start pointers. */  
1441    
1442        eptrb = eptrb->epb_prev;      /* If this was a group that remembered the subject start, in order to break
1443        infinite repeats of empty string matches, retrieve the subject start from
1444        the chain. Otherwise, set it NULL. */
1445    
1446        if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev >= OP_SBRA)
1447            *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||        {
1448            *prev == OP_ONCE)        saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1449          {        eptrb = eptrb->epb_prev;              /* Backup to previous group */
1450          md->end_match_ptr = eptr;      /* For ONCE */        }
1451          md->end_offset_top = offset_top;      else saved_eptr = NULL;
         RRETURN(MATCH_MATCH);  
         }  
1452    
1453        /* In all other cases except a conditional group we have to check the      /* If we are at the end of an assertion group or an atomic group, stop
1454        group number back at the start and if necessary complete handling an      matching and return MATCH_MATCH, but record the current high water mark for
1455        extraction by setting the offsets and bumping the high water mark. */      use by positive assertions. We also need to record the match start in case
1456        it was changed by \K. */
1457    
1458        if (*prev != OP_COND)      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1459          {          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
1460          number = *prev - OP_BRA;          *prev == OP_ONCE)
1461          {
1462          md->end_match_ptr = eptr;      /* For ONCE */
1463          md->end_offset_top = offset_top;
1464          md->start_match_ptr = mstart;
1465          RRETURN(MATCH_MATCH);
1466          }
1467    
1468          /* For extended extraction brackets (large number), we have to fish out      /* For capturing groups we have to check the group number back at the start
1469          the number from a dummy opcode at the start. */      and if necessary complete handling an extraction by setting the offsets and
1470        bumping the high water mark. Note that whole-pattern recursion is coded as
1471        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1472        when the OP_END is reached. Other recursion is handled here. */
1473    
1474          if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1475          offset = number << 1;        {
1476          number = GET2(prev, 1+LINK_SIZE);
1477          offset = number << 1;
1478    
1479  #ifdef DEBUG  #ifdef PCRE_DEBUG
1480          printf("end bracket %d", number);        printf("end bracket %d", number);
1481          printf("\n");        printf("\n");
1482  #endif  #endif
1483    
1484          /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1485          of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1486          into group 0, so it won't be picked up here. Instead, we catch it when          {
1487          the OP_END is reached. */          md->offset_vector[offset] =
1488              md->offset_vector[md->offset_end - number];
1489          if (number > 0)          md->offset_vector[offset+1] = eptr - md->start_subject;
1490            {          if (offset_top <= offset) offset_top = offset + 2;
           md->capture_last = number;  
           if (offset >= md->offset_max) md->offset_overflow = TRUE; else  
             {  
             md->offset_vector[offset] =  
               md->offset_vector[md->offset_end - number];  
             md->offset_vector[offset+1] = eptr - md->start_subject;  
             if (offset_top <= offset) offset_top = offset + 2;  
             }  
   
           /* Handle a recursively called group. Restore the offsets  
           appropriately and continue from after the call. */  
   
           if (md->recursive != NULL && md->recursive->group_num == number)  
             {  
             recursion_info *rec = md->recursive;  
             DPRINTF(("Recursion (%d) succeeded - continuing\n", number));  
             md->recursive = rec->prevrec;  
             md->start_match = rec->save_start;  
             memcpy(md->offset_vector, rec->offset_save,  
               rec->saved_max * sizeof(int));  
             ecode = rec->after_call;  
             ims = original_ims;  
             break;  
             }  
           }  
1491          }          }
1492    
1493        /* Reset the value of the ims flags, in case they got changed during        /* Handle a recursively called group. Restore the offsets
1494        the group. */        appropriately and continue from after the call. */
   
       ims = original_ims;  
       DPRINTF(("ims reset to %02lx\n", ims));  
   
       /* For a non-repeating ket, just continue at this level. This also  
       happens for a repeating ket if no characters were matched in the group.  
       This is the forcible breaking of infinite loops as implemented in Perl  
       5.005. If there is an options reset, it will get obeyed in the normal  
       course of events. */  
1495    
1496        if (*ecode == OP_KET || eptr == saved_eptr)        if (md->recursive != NULL && md->recursive->group_num == number)
1497          {          {
1498          ecode += 1 + LINK_SIZE;          recursion_info *rec = md->recursive;
1499            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1500            md->recursive = rec->prevrec;
1501            memcpy(md->offset_vector, rec->offset_save,
1502              rec->saved_max * sizeof(int));
1503            offset_top = rec->save_offset_top;
1504            ecode = rec->after_call;
1505            ims = original_ims;
1506          break;          break;
1507          }          }
1508          }
1509    
1510        /* The repeating kets try the rest of the pattern or restart from the      /* For both capturing and non-capturing groups, reset the value of the ims
1511        preceding bracket, in the appropriate order. */      flags, in case they got changed during the group. */
1512    
1513        if (*ecode == OP_KETRMIN)      ims = original_ims;
1514          {      DPRINTF(("ims reset to %02lx\n", ims));
1515          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);  
1516          if (rrc != MATCH_NOMATCH) RRETURN(rrc);      /* For a non-repeating ket, just continue at this level. This also
1517          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);      happens for a repeating ket if no characters were matched in the group.
1518          if (rrc != MATCH_NOMATCH) RRETURN(rrc);      This is the forcible breaking of infinite loops as implemented in Perl
1519          }      5.005. If there is an options reset, it will get obeyed in the normal
1520        else  /* OP_KETRMAX */      course of events. */
1521          {  
1522          RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);      if (*ecode == OP_KET || eptr == saved_eptr)
1523          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        {
1524          RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        ecode += 1 + LINK_SIZE;
1525          if (rrc != MATCH_NOMATCH) RRETURN(rrc);        break;
         }  
1526        }        }
1527    
1528      RRETURN(MATCH_NOMATCH);      /* The repeating kets try the rest of the pattern or restart from the
1529        preceding bracket, in the appropriate order. In the second case, we can use
1530        tail recursion to avoid using another stack frame, unless we have an
1531        unlimited repeat of a group that can match an empty string. */
1532    
1533      /* Start of subject unless notbol, or after internal newline if multiline */      flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1534    
1535      case OP_CIRC:      if (*ecode == OP_KETRMIN)
1536      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);        {
1537          RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1538          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1539          if (flags != 0)    /* Could match an empty string */
1540            {
1541            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1542            RRETURN(rrc);
1543            }
1544          ecode = prev;
1545          goto TAIL_RECURSE;
1546          }
1547        else  /* OP_KETRMAX */
1548          {
1549          RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1550          if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1551          ecode += 1 + LINK_SIZE;
1552          flags = 0;
1553          goto TAIL_RECURSE;
1554          }
1555        /* Control never gets here */
1556    
1557        /* Start of subject unless notbol, or after internal newline if multiline */
1558    
1559        case OP_CIRC:
1560        if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);
1561      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1562        {        {
1563        if (eptr != md->start_subject && eptr[-1] != NEWLINE)        if (eptr != md->start_subject &&
1564              (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1565          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1566        ecode++;        ecode++;
1567        break;        break;
# Line 1189  for (;;) Line 1582  for (;;)
1582      ecode++;      ecode++;
1583      break;      break;
1584    
1585        /* Reset the start of match point */
1586    
1587        case OP_SET_SOM:
1588        mstart = eptr;
1589        ecode++;
1590        break;
1591    
1592      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1593      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1594    
# Line 1196  for (;;) Line 1596  for (;;)
1596      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1597        {        {
1598        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1599          { if (*eptr != NEWLINE) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }
1600        else        else
1601          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) RRETURN(MATCH_NOMATCH); }
1602        ecode++;        ecode++;
# Line 1207  for (;;) Line 1607  for (;;)
1607        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) RRETURN(MATCH_NOMATCH);
1608        if (!md->endonly)        if (!md->endonly)
1609          {          {
1610          if (eptr < md->end_subject - 1 ||          if (eptr != md->end_subject &&
1611             (eptr == md->end_subject - 1 && *eptr != NEWLINE))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1612            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1613          ecode++;          ecode++;
1614          break;          break;
1615          }          }
1616        }        }
1617      /* ... else fall through */      /* ... else fall through for endonly */
1618    
1619      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1620    
# Line 1226  for (;;) Line 1626  for (;;)
1626      /* End of subject or ending \n assertion (\Z) */      /* End of subject or ending \n assertion (\Z) */
1627    
1628      case OP_EODN:      case OP_EODN:
1629      if (eptr < md->end_subject - 1 ||      if (eptr != md->end_subject &&
1630         (eptr == md->end_subject - 1 && *eptr != NEWLINE)) RRETURN(MATCH_NOMATCH);          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1631          RRETURN(MATCH_NOMATCH);
1632      ecode++;      ecode++;
1633      break;      break;
1634    
# Line 1239  for (;;) Line 1640  for (;;)
1640    
1641        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1642        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1643        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1644          partial matching. */
1645    
1646  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1647        if (utf8)        if (utf8)
1648          {          {
1649          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1650            {            {
1651            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1652            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1653              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1654            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1655            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1656            }            }
1657          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1658              {
1659              SCHECK_PARTIAL();
1660              cur_is_word = FALSE;
1661              }
1662            else
1663            {            {
1664            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1665            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1260  for (;;) Line 1668  for (;;)
1668        else        else
1669  #endif  #endif
1670    
1671        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1672    
1673          {          {
1674          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1675            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1676          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1677            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1678              }
1679            if (eptr >= md->end_subject)
1680              {
1681              SCHECK_PARTIAL();
1682              cur_is_word = FALSE;
1683              }
1684            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1685          }          }
1686    
1687        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1280  for (;;) Line 1695  for (;;)
1695      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1696    
1697      case OP_ANY:      case OP_ANY:
1698      if ((ims & PCRE_DOTALL) == 0 && eptr < md->end_subject && *eptr == NEWLINE)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1699        /* Fall through */
1700    
1701        case OP_ALLANY:
1702        if (eptr++ >= md->end_subject)
1703          {
1704          SCHECK_PARTIAL();
1705        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1706      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);        }
1707  #ifdef SUPPORT_UTF8      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
 #endif  
1708      ecode++;      ecode++;
1709      break;      break;
1710    
# Line 1294  for (;;) Line 1712  for (;;)
1712      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1713    
1714      case OP_ANYBYTE:      case OP_ANYBYTE:
1715      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1716          {
1717          SCHECK_PARTIAL();
1718          RRETURN(MATCH_NOMATCH);
1719          }
1720      ecode++;      ecode++;
1721      break;      break;
1722    
1723      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1724      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1725          {
1726          SCHECK_PARTIAL();
1727          RRETURN(MATCH_NOMATCH);
1728          }
1729      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1730      if (      if (
1731  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1312  for (;;) Line 1738  for (;;)
1738      break;      break;
1739    
1740      case OP_DIGIT:      case OP_DIGIT:
1741      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1742          {
1743          SCHECK_PARTIAL();
1744          RRETURN(MATCH_NOMATCH);
1745          }
1746      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1747      if (      if (
1748  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1325  for (;;) Line 1755  for (;;)
1755      break;      break;
1756    
1757      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1758      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1759          {
1760          SCHECK_PARTIAL();
1761          RRETURN(MATCH_NOMATCH);
1762          }
1763      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1764      if (      if (
1765  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1338  for (;;) Line 1772  for (;;)
1772      break;      break;
1773    
1774      case OP_WHITESPACE:      case OP_WHITESPACE:
1775      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1776          {
1777          SCHECK_PARTIAL();
1778          RRETURN(MATCH_NOMATCH);
1779          }
1780      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1781      if (      if (
1782  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1351  for (;;) Line 1789  for (;;)
1789      break;      break;
1790    
1791      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1792      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1793          {
1794          SCHECK_PARTIAL();
1795          RRETURN(MATCH_NOMATCH);
1796          }
1797      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1798      if (      if (
1799  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1364  for (;;) Line 1806  for (;;)
1806      break;      break;
1807    
1808      case OP_WORDCHAR:      case OP_WORDCHAR:
1809      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1810          {
1811          SCHECK_PARTIAL();
1812          RRETURN(MATCH_NOMATCH);
1813          }
1814      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1815      if (      if (
1816  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1376  for (;;) Line 1822  for (;;)
1822      ecode++;      ecode++;
1823      break;      break;
1824    
1825        case OP_ANYNL:
1826        if (eptr >= md->end_subject)
1827          {
1828          SCHECK_PARTIAL();
1829          RRETURN(MATCH_NOMATCH);
1830          }
1831        GETCHARINCTEST(c, eptr);
1832        switch(c)
1833          {
1834          default: RRETURN(MATCH_NOMATCH);
1835          case 0x000d:
1836          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1837          break;
1838    
1839          case 0x000a:
1840          break;
1841    
1842          case 0x000b:
1843          case 0x000c:
1844          case 0x0085:
1845          case 0x2028:
1846          case 0x2029:
1847          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1848          break;
1849          }
1850        ecode++;
1851        break;
1852    
1853        case OP_NOT_HSPACE:
1854        if (eptr >= md->end_subject)
1855          {
1856          SCHECK_PARTIAL();
1857          RRETURN(MATCH_NOMATCH);
1858          }
1859        GETCHARINCTEST(c, eptr);
1860        switch(c)
1861          {
1862          default: break;
1863          case 0x09:      /* HT */
1864          case 0x20:      /* SPACE */
1865          case 0xa0:      /* NBSP */
1866          case 0x1680:    /* OGHAM SPACE MARK */
1867          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1868          case 0x2000:    /* EN QUAD */
1869          case 0x2001:    /* EM QUAD */
1870          case 0x2002:    /* EN SPACE */
1871          case 0x2003:    /* EM SPACE */
1872          case 0x2004:    /* THREE-PER-EM SPACE */
1873          case 0x2005:    /* FOUR-PER-EM SPACE */
1874          case 0x2006:    /* SIX-PER-EM SPACE */
1875          case 0x2007:    /* FIGURE SPACE */
1876          case 0x2008:    /* PUNCTUATION SPACE */
1877          case 0x2009:    /* THIN SPACE */
1878          case 0x200A:    /* HAIR SPACE */
1879          case 0x202f:    /* NARROW NO-BREAK SPACE */
1880          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1881          case 0x3000:    /* IDEOGRAPHIC SPACE */
1882          RRETURN(MATCH_NOMATCH);
1883          }
1884        ecode++;
1885        break;
1886    
1887        case OP_HSPACE:
1888        if (eptr >= md->end_subject)
1889          {
1890          SCHECK_PARTIAL();
1891          RRETURN(MATCH_NOMATCH);
1892          }
1893        GETCHARINCTEST(c, eptr);
1894        switch(c)
1895          {
1896          default: RRETURN(MATCH_NOMATCH);
1897          case 0x09:      /* HT */
1898          case 0x20:      /* SPACE */
1899          case 0xa0:      /* NBSP */
1900          case 0x1680:    /* OGHAM SPACE MARK */
1901          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1902          case 0x2000:    /* EN QUAD */
1903          case 0x2001:    /* EM QUAD */
1904          case 0x2002:    /* EN SPACE */
1905          case 0x2003:    /* EM SPACE */
1906          case 0x2004:    /* THREE-PER-EM SPACE */
1907          case 0x2005:    /* FOUR-PER-EM SPACE */
1908          case 0x2006:    /* SIX-PER-EM SPACE */
1909          case 0x2007:    /* FIGURE SPACE */
1910          case 0x2008:    /* PUNCTUATION SPACE */
1911          case 0x2009:    /* THIN SPACE */
1912          case 0x200A:    /* HAIR SPACE */
1913          case 0x202f:    /* NARROW NO-BREAK SPACE */
1914          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1915          case 0x3000:    /* IDEOGRAPHIC SPACE */
1916          break;
1917          }
1918        ecode++;
1919        break;
1920    
1921        case OP_NOT_VSPACE:
1922        if (eptr >= md->end_subject)
1923          {
1924          SCHECK_PARTIAL();
1925          RRETURN(MATCH_NOMATCH);
1926          }
1927        GETCHARINCTEST(c, eptr);
1928        switch(c)
1929          {
1930          default: break;
1931          case 0x0a:      /* LF */
1932          case 0x0b:      /* VT */
1933          case 0x0c:      /* FF */
1934          case 0x0d:      /* CR */
1935          case 0x85:      /* NEL */
1936          case 0x2028:    /* LINE SEPARATOR */
1937          case 0x2029:    /* PARAGRAPH SEPARATOR */
1938          RRETURN(MATCH_NOMATCH);
1939          }
1940        ecode++;
1941        break;
1942    
1943        case OP_VSPACE:
1944        if (eptr >= md->end_subject)
1945          {
1946          SCHECK_PARTIAL();
1947          RRETURN(MATCH_NOMATCH);
1948          }
1949        GETCHARINCTEST(c, eptr);
1950        switch(c)
1951          {
1952          default: RRETURN(MATCH_NOMATCH);
1953          case 0x0a:      /* LF */
1954          case 0x0b:      /* VT */
1955          case 0x0c:      /* FF */
1956          case 0x0d:      /* CR */
1957          case 0x85:      /* NEL */
1958          case 0x2028:    /* LINE SEPARATOR */
1959          case 0x2029:    /* PARAGRAPH SEPARATOR */
1960          break;
1961          }
1962        ecode++;
1963        break;
1964    
1965  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1966      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1967      if the support is in the binary; otherwise a compile-time error occurs. */      if the support is in the binary; otherwise a compile-time error occurs. */
1968    
1969      case OP_PROP:      case OP_PROP:
1970      case OP_NOTPROP:      case OP_NOTPROP:
1971      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1972          {
1973          SCHECK_PARTIAL();
1974          RRETURN(MATCH_NOMATCH);
1975          }
1976      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1977        {        {
1978        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1979    
1980        switch(ecode[1])        switch(ecode[1])
1981          {          {
# Line 1395  for (;;) Line 1984  for (;;)
1984          break;          break;
1985    
1986          case PT_LAMP:          case PT_LAMP:
1987          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1988               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1989               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1990            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1991           break;           break;
1992    
1993          case PT_GC:          case PT_GC:
1994          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1995            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1996          break;          break;
1997    
1998          case PT_PC:          case PT_PC:
1999          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2000            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2001          break;          break;
2002    
2003          case PT_SC:          case PT_SC:
2004          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2005            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
2006          break;          break;
2007    
2008          default:          default:
2009          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
2010          }          }
2011    
2012        ecode += 3;        ecode += 3;
# Line 1429  for (;;) Line 2017  for (;;)
2017      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2018    
2019      case OP_EXTUNI:      case OP_EXTUNI:
2020      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2021          {
2022          SCHECK_PARTIAL();
2023          RRETURN(MATCH_NOMATCH);
2024          }
2025      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2026        {        {
2027        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
2028        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
2029        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2030          {          {
# Line 1442  for (;;) Line 2033  for (;;)
2033            {            {
2034            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
2035            }            }
2036          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
2037          if (category != ucp_M) break;          if (category != ucp_M) break;
2038          eptr += len;          eptr += len;
2039          }          }
# Line 1463  for (;;) Line 2054  for (;;)
2054      case OP_REF:      case OP_REF:
2055        {        {
2056        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2057        ecode += 3;                                 /* Advance past item */        ecode += 3;
2058    
2059          /* If the reference is unset, there are two possibilities:
2060    
2061          (a) In the default, Perl-compatible state, set the length to be longer
2062          than the amount of subject left; this ensures that every attempt at a
2063          match fails. We can't just fail here, because of the possibility of
2064          quantifiers with zero minima.
2065    
2066        /* If the reference is unset, set the length to be longer than the amount        (b) If the JavaScript compatibility flag is set, set the length to zero
2067        of subject left; this ensures that every attempt at a match fails. We        so that the back reference matches an empty string.
2068        can't just fail here, because of the possibility of quantifiers with zero  
2069        minima. */        Otherwise, set the length to the length of what was matched by the
2070          referenced subpattern. */
2071        length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
2072          md->end_subject - eptr + 1 :        if (offset >= offset_top || md->offset_vector[offset] < 0)
2073          md->offset_vector[offset+1] - md->offset_vector[offset];          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
2074          else
2075            length = md->offset_vector[offset+1] - md->offset_vector[offset];
2076    
2077        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
2078    
# Line 1501  for (;;) Line 2101  for (;;)
2101          break;          break;
2102    
2103          default:               /* No repeat follows */          default:               /* No repeat follows */
2104          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2105              {
2106              CHECK_PARTIAL();
2107              RRETURN(MATCH_NOMATCH);
2108              }
2109          eptr += length;          eptr += length;
2110          continue;              /* With the main loop */          continue;              /* With the main loop */
2111          }          }
# Line 1517  for (;;) Line 2121  for (;;)
2121    
2122        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2123          {          {
2124          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2125              {
2126              CHECK_PARTIAL();
2127              RRETURN(MATCH_NOMATCH);
2128              }
2129          eptr += length;          eptr += length;
2130          }          }
2131    
# Line 1532  for (;;) Line 2140  for (;;)
2140          {          {
2141          for (fi = min;; fi++)          for (fi = min;; fi++)
2142            {            {
2143            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2144            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2145            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
2146              if (!match_ref(offset, eptr, length, md, ims))
2147                {
2148                CHECK_PARTIAL();
2149              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2150                }
2151            eptr += length;            eptr += length;
2152            }            }
2153          /* Control never gets here */          /* Control never gets here */
# Line 1548  for (;;) Line 2160  for (;;)
2160          pp = eptr;          pp = eptr;
2161          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2162            {            {
2163            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2164                {
2165                CHECK_PARTIAL();
2166                break;
2167                }
2168            eptr += length;            eptr += length;
2169            }            }
2170          while (eptr >= pp)          while (eptr >= pp)
2171            {            {
2172            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2173            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2174            eptr -= length;            eptr -= length;
2175            }            }
# Line 1562  for (;;) Line 2178  for (;;)
2178        }        }
2179      /* Control never gets here */      /* Control never gets here */
2180    
   
   
2181      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2182      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2183      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1618  for (;;) Line 2232  for (;;)
2232          {          {
2233          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2234            {            {
2235            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2236                {
2237                SCHECK_PARTIAL();
2238                RRETURN(MATCH_NOMATCH);
2239                }
2240            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2241            if (c > 255)            if (c > 255)
2242              {              {
# Line 1636  for (;;) Line 2254  for (;;)
2254          {          {
2255          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2256            {            {
2257            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2258                {
2259                SCHECK_PARTIAL();
2260                RRETURN(MATCH_NOMATCH);
2261                }
2262            c = *eptr++;            c = *eptr++;
2263            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2264            }            }
# Line 1658  for (;;) Line 2280  for (;;)
2280            {            {
2281            for (fi = min;; fi++)            for (fi = min;; fi++)
2282              {              {
2283              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2284              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2285              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2286                if (eptr >= md->end_subject)
2287                  {
2288                  SCHECK_PARTIAL();
2289                  RRETURN(MATCH_NOMATCH);
2290                  }
2291              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2292              if (c > 255)              if (c > 255)
2293                {                {
# Line 1678  for (;;) Line 2305  for (;;)
2305            {            {
2306            for (fi = min;; fi++)            for (fi = min;; fi++)
2307              {              {
2308              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2309              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2310              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2311                if (eptr >= md->end_subject)
2312                  {
2313                  SCHECK_PARTIAL();
2314                  RRETURN(MATCH_NOMATCH);
2315                  }
2316              c = *eptr++;              c = *eptr++;
2317              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2318              }              }
# Line 1701  for (;;) Line 2333  for (;;)
2333            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2334              {              {
2335              int len = 1;              int len = 1;
2336              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2337                  {
2338                  SCHECK_PARTIAL();
2339                  break;
2340                  }
2341              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2342              if (c > 255)              if (c > 255)
2343                {                {
# Line 1715  for (;;) Line 2351  for (;;)
2351              }              }
2352            for (;;)            for (;;)
2353              {              {
2354              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2355              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2356              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2357              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1727  for (;;) Line 2363  for (;;)
2363            {            {
2364            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2365              {              {
2366              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2367                  {
2368                  SCHECK_PARTIAL();
2369                  break;
2370                  }
2371              c = *eptr;              c = *eptr;
2372              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2373              eptr++;              eptr++;
2374              }              }
2375            while (eptr >= pp)            while (eptr >= pp)
2376              {              {
2377              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2378              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2379              eptr--;              eptr--;
2380              }              }
# Line 1747  for (;;) Line 2387  for (;;)
2387    
2388    
2389      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2390      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2391        mode, because Unicode properties are supported in non-UTF-8 mode. */
2392    
2393  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2394      case OP_XCLASS:      case OP_XCLASS:
# Line 1788  for (;;) Line 2429  for (;;)
2429    
2430        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2431          {          {
2432          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2433          GETCHARINC(c, eptr);            {
2434              SCHECK_PARTIAL();
2435              RRETURN(MATCH_NOMATCH);
2436              }
2437            GETCHARINCTEST(c, eptr);
2438          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2439          }          }
2440    
# Line 1805  for (;;) Line 2450  for (;;)
2450          {          {
2451          for (fi = min;; fi++)          for (fi = min;; fi++)
2452            {            {
2453            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2454            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2455            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2456            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2457                {
2458                SCHECK_PARTIAL();
2459                RRETURN(MATCH_NOMATCH);
2460                }
2461              GETCHARINCTEST(c, eptr);
2462            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2463            }            }
2464          /* Control never gets here */          /* Control never gets here */
# Line 1822  for (;;) Line 2472  for (;;)
2472          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2473            {            {
2474            int len = 1;            int len = 1;
2475            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2476            GETCHARLEN(c, eptr, len);              {
2477                SCHECK_PARTIAL();
2478                break;
2479                }
2480              GETCHARLENTEST(c, eptr, len);
2481            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2482            eptr += len;            eptr += len;
2483            }            }
2484          for(;;)          for(;;)
2485            {            {
2486            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2487            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2488            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2489            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2490            }            }
2491          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2492          }          }
# Line 1850  for (;;) Line 2504  for (;;)
2504        length = 1;        length = 1;
2505        ecode++;        ecode++;
2506        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2507        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2508            {
2509            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2510            RRETURN(MATCH_NOMATCH);
2511            }
2512        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2513        }        }
2514      else      else
# Line 1858  for (;;) Line 2516  for (;;)
2516    
2517      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2518        {        {
2519        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2520            {
2521            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2522            RRETURN(MATCH_NOMATCH);
2523            }
2524        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2525        ecode += 2;        ecode += 2;
2526        }        }
# Line 1874  for (;;) Line 2536  for (;;)
2536        ecode++;        ecode++;
2537        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2538    
2539        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2540            {
2541            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2542            RRETURN(MATCH_NOMATCH);
2543            }
2544    
2545        /* 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
2546        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1888  for (;;) Line 2554  for (;;)
2554    
2555        else        else
2556          {          {
2557          int dc;          unsigned int dc;
2558          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2559          ecode += length;          ecode += length;
2560    
# Line 1898  for (;;) Line 2564  for (;;)
2564          if (fc != dc)          if (fc != dc)
2565            {            {
2566  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2567            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2568  #endif  #endif
2569              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2570            }            }
# Line 1909  for (;;) Line 2575  for (;;)
2575    
2576      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2577        {        {
2578        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2579            {
2580            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2581            RRETURN(MATCH_NOMATCH);
2582            }
2583        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2584        ecode += 2;        ecode += 2;
2585        }        }
2586      break;      break;
2587    
2588      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2589    
2590      case OP_EXACT:      case OP_EXACT:
2591      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2592      ecode += 3;      ecode += 3;
2593      goto REPEATCHAR;      goto REPEATCHAR;
2594    
2595        case OP_POSUPTO:
2596        possessive = TRUE;
2597        /* Fall through */
2598    
2599      case OP_UPTO:      case OP_UPTO:
2600      case OP_MINUPTO:      case OP_MINUPTO:
2601      min = 0;      min = 0;
# Line 1930  for (;;) Line 2604  for (;;)
2604      ecode += 3;      ecode += 3;
2605      goto REPEATCHAR;      goto REPEATCHAR;
2606    
2607        case OP_POSSTAR:
2608        possessive = TRUE;
2609        min = 0;
2610        max = INT_MAX;
2611        ecode++;
2612        goto REPEATCHAR;
2613    
2614        case OP_POSPLUS:
2615        possessive = TRUE;
2616        min = 1;
2617        max = INT_MAX;
2618        ecode++;
2619        goto REPEATCHAR;
2620    
2621        case OP_POSQUERY:
2622        possessive = TRUE;
2623        min = 0;
2624        max = 1;
2625        ecode++;
2626        goto REPEATCHAR;
2627    
2628      case OP_STAR:      case OP_STAR:
2629      case OP_MINSTAR:      case OP_MINSTAR:
2630      case OP_PLUS:      case OP_PLUS:
# Line 1938  for (;;) Line 2633  for (;;)
2633      case OP_MINQUERY:      case OP_MINQUERY:
2634      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2635      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2636    
2637      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2638      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2639      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2640    
2641      /* Common code for all repeated single-character matches. We can give      /* Common code for all repeated single-character matches. */
     up quickly if there are fewer than the minimum number of characters left in  
     the subject. */  
2642    
2643      REPEATCHAR:      REPEATCHAR:
2644  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1953  for (;;) Line 2647  for (;;)
2647        length = 1;        length = 1;
2648        charptr = ecode;        charptr = ecode;
2649        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2650        ecode += length;        ecode += length;
2651    
2652        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1961  for (;;) Line 2654  for (;;)
2654    
2655        if (length > 1)        if (length > 1)
2656          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2657  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2658          int othercase;          unsigned int othercase;
2659          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2660              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2661            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2662            else oclength = 0;
2663  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2664    
2665          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2666            {            {
2667            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2668            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2669            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2670              else if (oclength > 0 &&
2671                       eptr <= md->end_subject - oclength &&
2672                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2673    #endif  /* SUPPORT_UCP */
2674            else            else
2675              {              {
2676              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2677              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2678              }              }
2679            }            }
2680    
# Line 1990  for (;;) Line 2684  for (;;)
2684            {            {
2685            for (fi = min;; fi++)            for (fi = min;; fi++)
2686              {              {
2687              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2688              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2689              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2690              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2691              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2692              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2693                else if (oclength > 0 &&
2694                         eptr <= md->end_subject - oclength &&
2695                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2696    #endif  /* SUPPORT_UCP */
2697              else              else
2698                {                {
2699                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2700                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2701                }                }
2702              }              }
2703            /* Control never gets here */            /* Control never gets here */
2704            }            }
2705          else  
2706            else  /* Maximize */
2707            {            {
2708            pp = eptr;            pp = eptr;
2709            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2710              {              {
2711              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2712              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2713              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2714                else if (oclength > 0 &&
2715                         eptr <= md->end_subject - oclength &&
2716                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2717    #endif  /* SUPPORT_UCP */
2718              else              else
2719                {                {
2720                if (memcmp(eptr, occhars, oclength) != 0) break;                CHECK_PARTIAL();
2721                eptr += oclength;                break;
2722                }                }
2723              }              }
2724            while (eptr >= pp)  
2725             {            if (possessive) continue;
2726             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
2727             if (rrc != MATCH_NOMATCH) RRETURN(rrc);            for(;;)
2728             eptr -= length;              {
2729             }              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2730            RRETURN(MATCH_NOMATCH);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2731                if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2732    #ifdef SUPPORT_UCP
2733                eptr--;
2734                BACKCHAR(eptr);
2735    #else   /* without SUPPORT_UCP */
2736                eptr -= length;
2737    #endif  /* SUPPORT_UCP */
2738                }
2739            }            }
2740          /* Control never gets here */          /* Control never gets here */
2741          }          }
# Line 2037  for (;;) Line 2748  for (;;)
2748  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2749    
2750      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2751        {  
2752        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2753    
2754      /* The value of fc at this point is always less than 256, though we may or      /* The value of fc at this point is always less than 256, though we may or
2755      may not be in UTF-8 mode. The code is duplicated for the caseless and      may not be in UTF-8 mode. The code is duplicated for the caseless and
# Line 2058  for (;;) Line 2767  for (;;)
2767        {        {
2768        fc = md->lcc[fc];        fc = md->lcc[fc];
2769        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2770            {
2771            if (eptr >= md->end_subject)
2772              {
2773              SCHECK_PARTIAL();
2774              RRETURN(MATCH_NOMATCH);
2775              }
2776          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2777            }
2778        if (min == max) continue;        if (min == max) continue;
2779        if (minimize)        if (minimize)
2780          {          {
2781          for (fi = min;; fi++)          for (fi = min;; fi++)
2782            {            {
2783            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2784            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2785            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2786                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2787                {
2788                SCHECK_PARTIAL();
2789              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2790                }
2791              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2792            }            }
2793          /* Control never gets here */          /* Control never gets here */
2794          }          }
2795        else        else  /* Maximize */
2796          {          {
2797          pp = eptr;          pp = eptr;
2798          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2799            {            {
2800            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2801                {
2802                SCHECK_PARTIAL();
2803                break;
2804                }
2805              if (fc != md->lcc[*eptr]) break;
2806            eptr++;            eptr++;
2807            }            }
2808    
2809            if (possessive) continue;
2810    
2811          while (eptr >= pp)          while (eptr >= pp)
2812            {            {
2813            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2814            eptr--;            eptr--;
2815            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2816            }            }
# Line 2095  for (;;) Line 2823  for (;;)
2823    
2824      else      else
2825        {        {
2826        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2827            {
2828            if (eptr >= md->end_subject)
2829              {
2830              SCHECK_PARTIAL();
2831              RRETURN(MATCH_NOMATCH);
2832              }
2833            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2834            }
2835    
2836        if (min == max) continue;        if (min == max) continue;
2837    
2838        if (minimize)        if (minimize)
2839          {          {
2840          for (fi = min;; fi++)          for (fi = min;; fi++)
2841            {            {
2842            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2843            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2844            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2845              if (eptr >= md->end_subject)
2846                {
2847                SCHECK_PARTIAL();
2848              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2849                }
2850              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2851            }            }
2852          /* Control never gets here */          /* Control never gets here */
2853          }          }
2854        else        else  /* Maximize */
2855          {          {
2856          pp = eptr;          pp = eptr;
2857          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2858            {            {
2859            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
2860                {
2861                SCHECK_PARTIAL();
2862                break;
2863                }
2864              if (fc != *eptr) break;
2865            eptr++;            eptr++;
2866            }            }
2867            if (possessive) continue;
2868    
2869          while (eptr >= pp)          while (eptr >= pp)
2870            {            {
2871            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2872            eptr--;            eptr--;
2873            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2874            }            }
# Line 2131  for (;;) Line 2881  for (;;)
2881      checking can be multibyte. */      checking can be multibyte. */
2882    
2883      case OP_NOT:      case OP_NOT:
2884      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2885          {
2886          SCHECK_PARTIAL();
2887          RRETURN(MATCH_NOMATCH);
2888          }
2889      ecode++;      ecode++;
2890      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2891      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2168  for (;;) Line 2922  for (;;)
2922      ecode += 3;      ecode += 3;
2923      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2924    
2925      case OP_NOTSTAR:      case OP_NOTPOSSTAR:
2926      case OP_NOTMINSTAR:      possessive = TRUE;
2927      case OP_NOTPLUS:      min = 0;
2928      case OP_NOTMINPLUS:      max = INT_MAX;
2929      case OP_NOTQUERY:      ecode++;
2930      case OP_NOTMINQUERY:      goto REPEATNOTCHAR;
2931    
2932        case OP_NOTPOSPLUS:
2933        possessive = TRUE;
2934        min = 1;
2935        max = INT_MAX;
2936        ecode++;
2937        goto REPEATNOTCHAR;
2938    
2939        case OP_NOTPOSQUERY:
2940        possessive = TRUE;
2941        min = 0;
2942        max = 1;
2943        ecode++;
2944        goto REPEATNOTCHAR;
2945    
2946        case OP_NOTPOSUPTO:
2947        possessive = TRUE;
2948        min = 0;
2949        max = GET2(ecode, 1);
2950        ecode += 3;
2951        goto REPEATNOTCHAR;
2952    
2953        case OP_NOTSTAR:
2954        case OP_NOTMINSTAR:
2955        case OP_NOTPLUS:
2956        case OP_NOTMINPLUS:
2957        case OP_NOTQUERY:
2958        case OP_NOTMINQUERY:
2959      c = *ecode++ - OP_NOTSTAR;      c = *ecode++ - OP_NOTSTAR;
2960      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2961      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2962      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2963      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2964    
2965      /* Common code for all repeated single-byte matches. We can give up quickly      /* Common code for all repeated single-byte matches. */
     if there are fewer than the minimum number of bytes left in the  
     subject. */  
2966    
2967      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2968      fc = *ecode++;      fc = *ecode++;
2969    
2970      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
# Line 2207  for (;;) Line 2986  for (;;)
2986        /* UTF-8 mode */        /* UTF-8 mode */
2987        if (utf8)        if (utf8)
2988          {          {
2989          register int d;          register unsigned int d;
2990          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2991            {            {
2992              if (eptr >= md->end_subject)
2993                {
2994                SCHECK_PARTIAL();
2995                RRETURN(MATCH_NOMATCH);
2996                }
2997            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2998            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2999            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2221  for (;;) Line 3005  for (;;)
3005        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3006          {          {
3007          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3008              {
3009              if (eptr >= md->end_subject)
3010                {
3011                SCHECK_PARTIAL();
3012                RRETURN(MATCH_NOMATCH);
3013                }
3014            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
3015              }
3016          }          }
3017    
3018        if (min == max) continue;        if (min == max) continue;
# Line 2232  for (;;) Line 3023  for (;;)
3023          /* UTF-8 mode */          /* UTF-8 mode */
3024          if (utf8)          if (utf8)
3025            {            {
3026            register int d;            register unsigned int d;
3027            for (fi = min;; fi++)            for (fi = min;; fi++)
3028              {              {
3029              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3030              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3031                if (fi >= max) RRETURN(MATCH_NOMATCH);
3032                if (eptr >= md->end_subject)
3033                  {
3034                  SCHECK_PARTIAL();
3035                  RRETURN(MATCH_NOMATCH);
3036                  }
3037              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3038              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3039              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3040              }              }
3041            }            }
3042          else          else
# Line 2249  for (;;) Line 3045  for (;;)
3045            {            {
3046            for (fi = min;; fi++)            for (fi = min;; fi++)
3047              {              {
3048              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3049              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3050              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
3051                if (eptr >= md->end_subject)
3052                  {
3053                  SCHECK_PARTIAL();
3054                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3055                  }
3056                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
3057              }              }
3058            }            }
3059          /* Control never gets here */          /* Control never gets here */
# Line 2268  for (;;) Line 3069  for (;;)
3069          /* UTF-8 mode */          /* UTF-8 mode */
3070          if (utf8)          if (utf8)
3071            {            {
3072            register int d;            register unsigned int d;
3073            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3074              {              {
3075              int len = 1;              int len = 1;
3076              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3077                  {
3078                  SCHECK_PARTIAL();
3079                  break;
3080                  }
3081              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3082              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3083              if (fc == d) break;              if (fc == d) break;
3084              eptr += len;              eptr += len;
3085              }              }
3086            for(;;)          if (possessive) continue;
3087            for(;;)
3088              {              {
3089              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
3090              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3091              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3092              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2292  for (;;) Line 3098  for (;;)
3098            {            {
3099            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3100              {              {
3101              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3102                  {
3103                  SCHECK_PARTIAL();
3104                  break;
3105                  }
3106                if (fc == md->lcc[*eptr]) break;
3107              eptr++;              eptr++;
3108              }              }
3109              if (possessive) continue;
3110            while (eptr >= pp)            while (eptr >= pp)
3111              {              {
3112              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
3113              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3114              eptr--;              eptr--;
3115              }              }
# Line 2316  for (;;) Line 3128  for (;;)
3128        /* UTF-8 mode */        /* UTF-8 mode */
3129        if (utf8)        if (utf8)
3130          {          {
3131          register int d;          register unsigned int d;
3132          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3133            {            {
3134              if (eptr >= md->end_subject)
3135                {
3136                SCHECK_PARTIAL();
3137                RRETURN(MATCH_NOMATCH);
3138                }
3139            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3140            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
3141            }            }
# Line 2328  for (;;) Line 3145  for (;;)
3145        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3146          {          {
3147          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3148              {
3149              if (eptr >= md->end_subject)
3150                {
3151                SCHECK_PARTIAL();
3152                RRETURN(MATCH_NOMATCH);
3153                }
3154            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3155              }
3156          }          }
3157    
3158        if (min == max) continue;        if (min == max) continue;
# Line 2339  for (;;) Line 3163  for (;;)
3163          /* UTF-8 mode */          /* UTF-8 mode */
3164          if (utf8)          if (utf8)
3165            {            {
3166            register int d;            register unsigned int d;
3167            for (fi = min;; fi++)            for (fi = min;; fi++)
3168              {              {
3169              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3170              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3171              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3172              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
3173                  {
3174                  SCHECK_PARTIAL();
3175                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3176                  }
3177                GETCHARINC(d, eptr);
3178                if (fc == d) RRETURN(MATCH_NOMATCH);
3179              }              }
3180            }            }
3181          else          else
# Line 2355  for (;;) Line 3184  for (;;)
3184            {            {
3185            for (fi = min;; fi++)            for (fi = min;; fi++)
3186              {              {
3187              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3188              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3189              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
3190                if (eptr >= md->end_subject)
3191                  {
3192                  SCHECK_PARTIAL();
3193                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3194                  }
3195                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3196              }              }
3197            }            }
3198          /* Control never gets here */          /* Control never gets here */
# Line 2374  for (;;) Line 3208  for (;;)
3208          /* UTF-8 mode */          /* UTF-8 mode */
3209          if (utf8)          if (utf8)
3210            {            {
3211            register int d;            register unsigned int d;
3212            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3213              {              {
3214              int len = 1;              int len = 1;
3215              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3216                  {
3217                  SCHECK_PARTIAL();
3218                  break;
3219                  }
3220              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3221              if (fc == d) break;              if (fc == d) break;
3222              eptr += len;              eptr += len;
3223              }              }
3224              if (possessive) continue;
3225            for(;;)            for(;;)
3226              {              {
3227              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3228              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3229              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3230              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2397  for (;;) Line 3236  for (;;)
3236            {            {
3237            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3238              {              {
3239              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3240                  {
3241                  SCHECK_PARTIAL();
3242                  break;
3243                  }
3244                if (fc == *eptr) break;
3245              eptr++;              eptr++;
3246              }              }
3247              if (possessive) continue;
3248            while (eptr >= pp)            while (eptr >= pp)
3249              {              {
3250              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3251              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3252              eptr--;              eptr--;
3253              }              }
# Line 2431  for (;;) Line 3276  for (;;)
3276      ecode += 3;      ecode += 3;
3277      goto REPEATTYPE;      goto REPEATTYPE;
3278    
3279        case OP_TYPEPOSSTAR:
3280        possessive = TRUE;
3281        min = 0;
3282        max = INT_MAX;
3283        ecode++;
3284        goto REPEATTYPE;
3285    
3286        case OP_TYPEPOSPLUS:
3287        possessive = TRUE;
3288        min = 1;
3289        max = INT_MAX;
3290        ecode++;
3291        goto REPEATTYPE;
3292    
3293        case OP_TYPEPOSQUERY:
3294        possessive = TRUE;
3295        min = 0;
3296        max = 1;
3297        ecode++;
3298        goto REPEATTYPE;
3299    
3300        case OP_TYPEPOSUPTO:
3301        possessive = TRUE;
3302        min = 0;
3303        max = GET2(ecode, 1);
3304        ecode += 3;
3305        goto REPEATTYPE;
3306    
3307      case OP_TYPESTAR:      case OP_TYPESTAR:
3308      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3309      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2462  for (;;) Line 3335  for (;;)
3335    
3336      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3337      code for maximizing the speed, and do the type test once at the start      code for maximizing the speed, and do the type test once at the start
3338      (i.e. keep it out of the loop). Also we can test that there are at least      (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
     the minimum number of bytes before we start. This isn't as effective in  
     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that  
3339      is tidier. Also separate the UCP code, which can be the same for both UTF-8      is tidier. Also separate the UCP code, which can be the same for both UTF-8
3340      and single-bytes. */      and single-bytes. */
3341    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3342      if (min > 0)      if (min > 0)
3343        {        {
3344  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2480  for (;;) Line 3350  for (;;)
3350            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3351            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3352              {              {
3353              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3354              GETCHARINC(c, eptr);                {
3355                  SCHECK_PARTIAL();
3356                  RRETURN(MATCH_NOMATCH);
3357                  }
3358                GETCHARINCTEST(c, eptr);
3359              }              }
3360            break;            break;
3361    
3362            case PT_LAMP:            case PT_LAMP:
3363            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3364              {              {
3365              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3366              GETCHARINC(c, eptr);                {
3367              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3368                  RRETURN(MATCH_NOMATCH);
3369                  }
3370                GETCHARINCTEST(c, eptr);
3371                prop_chartype = UCD_CHARTYPE(c);
3372              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3373                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3374                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2501  for (;;) Line 3379  for (;;)
3379            case PT_GC:            case PT_GC:
3380            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3381              {              {
3382              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3383              GETCHARINC(c, eptr);                {
3384              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3385                  RRETURN(MATCH_NOMATCH);
3386                  }
3387                GETCHARINCTEST(c, eptr);
3388                prop_category = UCD_CATEGORY(c);
3389              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3390                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3391              }              }
# Line 2512  for (;;) Line 3394  for (;;)
3394            case PT_PC:            case PT_PC:
3395            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3396              {              {
3397              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3398              GETCHARINC(c, eptr);                {
3399              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3400                  RRETURN(MATCH_NOMATCH);
3401                  }
3402                GETCHARINCTEST(c, eptr);
3403                prop_chartype = UCD_CHARTYPE(c);
3404              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3405                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3406              }              }
# Line 2523  for (;;) Line 3409  for (;;)
3409            case PT_SC:            case PT_SC:
3410            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3411              {              {
3412              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3413              GETCHARINC(c, eptr);                {
3414              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3415                  RRETURN(MATCH_NOMATCH);
3416                  }
3417                GETCHARINCTEST(c, eptr);
3418                prop_script = UCD_SCRIPT(c);
3419              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3420                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3421              }              }
# Line 2533  for (;;) Line 3423  for (;;)
3423    
3424            default:            default:
3425            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3426            }            }
3427          }          }
3428    
# Line 2544  for (;;) Line 3433  for (;;)
3433          {          {
3434          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3435            {            {
3436              if (eptr >= md->end_subject)
3437                {
3438                SCHECK_PARTIAL();
3439                RRETURN(MATCH_NOMATCH);
3440                }
3441            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3442            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3443            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3444            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3445              {              {
3446              int len = 1;              int len = 1;
3447              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3448                {                else { GETCHARLEN(c, eptr, len); }
3449                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3450              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3451              eptr += len;              eptr += len;
3452              }              }
# Line 2572  for (;;) Line 3464  for (;;)
3464          case OP_ANY:          case OP_ANY:
3465          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3466            {            {
3467            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3468               (*eptr++ == NEWLINE && (ims & PCRE_DOTALL) == 0))              {
3469                SCHECK_PARTIAL();
3470              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3471                }
3472              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3473              eptr++;
3474              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3475              }
3476            break;
3477    
3478            case OP_ALLANY:
3479            for (i = 1; i <= min; i++)
3480              {
3481              if (eptr >= md->end_subject)
3482                {
3483                SCHECK_PARTIAL();
3484                RRETURN(MATCH_NOMATCH);
3485                }
3486              eptr++;
3487            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3488            }            }
3489          break;          break;
3490    
3491          case OP_ANYBYTE:          case OP_ANYBYTE:
3492            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3493          eptr += min;          eptr += min;
3494          break;          break;
3495    
3496            case OP_ANYNL:
3497            for (i = 1; i <= min; i++)
3498              {
3499              if (eptr >= md->end_subject)
3500                {
3501                SCHECK_PARTIAL();
3502                RRETURN(MATCH_NOMATCH);
3503                }
3504              GETCHARINC(c, eptr);
3505              switch(c)
3506                {
3507                default: RRETURN(MATCH_NOMATCH);
3508                case 0x000d:
3509                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3510                break;
3511    
3512                case 0x000a:
3513                break;
3514    
3515                case 0x000b:
3516                case 0x000c:
3517                case 0x0085:
3518                case 0x2028:
3519                case 0x2029:
3520                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3521                break;
3522                }
3523              }
3524            break;
3525    
3526            case OP_NOT_HSPACE:
3527            for (i = 1; i <= min; i++)
3528              {
3529              if (eptr >= md->end_subject)
3530                {
3531                SCHECK_PARTIAL();
3532                RRETURN(MATCH_NOMATCH);
3533                }
3534              GETCHARINC(c, eptr);
3535              switch(c)
3536                {
3537                default: break;
3538                case 0x09:      /* HT */
3539                case 0x20:      /* SPACE */
3540                case 0xa0:      /* NBSP */
3541                case 0x1680:    /* OGHAM SPACE MARK */
3542                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3543                case 0x2000:    /* EN QUAD */
3544                case 0x2001:    /* EM QUAD */
3545                case 0x2002:    /* EN SPACE */
3546                case 0x2003:    /* EM SPACE */
3547                case 0x2004:    /* THREE-PER-EM SPACE */
3548                case 0x2005:    /* FOUR-PER-EM SPACE */
3549                case 0x2006:    /* SIX-PER-EM SPACE */
3550                case 0x2007:    /* FIGURE SPACE */
3551                case 0x2008:    /* PUNCTUATION SPACE */
3552                case 0x2009:    /* THIN SPACE */
3553                case 0x200A:    /* HAIR SPACE */
3554                case 0x202f:    /* NARROW NO-BREAK SPACE */
3555                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3556                case 0x3000:    /* IDEOGRAPHIC SPACE */
3557                RRETURN(MATCH_NOMATCH);
3558                }
3559              }
3560            break;
3561    
3562            case OP_HSPACE:
3563            for (i = 1; i <= min; i++)
3564              {
3565              if (eptr >= md->end_subject)
3566                {
3567                SCHECK_PARTIAL();
3568                RRETURN(MATCH_NOMATCH);
3569                }
3570              GETCHARINC(c, eptr);
3571              switch(c)
3572                {
3573                default: RRETURN(MATCH_NOMATCH);
3574                case 0x09:      /* HT */
3575                case 0x20:      /* SPACE */
3576                case 0xa0:      /* NBSP */
3577                case 0x1680:    /* OGHAM SPACE MARK */
3578                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3579                case 0x2000:    /* EN QUAD */
3580                case 0x2001:    /* EM QUAD */
3581                case 0x2002:    /* EN SPACE */
3582                case 0x2003:    /* EM SPACE */
3583                case 0x2004:    /* THREE-PER-EM SPACE */
3584                case 0x2005:    /* FOUR-PER-EM SPACE */
3585                case 0x2006:    /* SIX-PER-EM SPACE */
3586                case 0x2007:    /* FIGURE SPACE */
3587                case 0x2008:    /* PUNCTUATION SPACE */
3588                case 0x2009:    /* THIN SPACE */
3589                case 0x200A:    /* HAIR SPACE */
3590                case 0x202f:    /* NARROW NO-BREAK SPACE */
3591                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3592                case 0x3000:    /* IDEOGRAPHIC SPACE */
3593                break;
3594                }
3595              }
3596            break;
3597    
3598            case OP_NOT_VSPACE:
3599            for (i = 1; i <= min; i++)
3600              {
3601              if (eptr >= md->end_subject)
3602                {
3603                SCHECK_PARTIAL();
3604                RRETURN(MATCH_NOMATCH);
3605                }
3606              GETCHARINC(c, eptr);
3607              switch(c)
3608                {
3609                default: break;
3610                case 0x0a:      /* LF */
3611                case 0x0b:      /* VT */
3612                case 0x0c:      /* FF */
3613                case 0x0d:      /* CR */
3614                case 0x85:      /* NEL */
3615                case 0x2028:    /* LINE SEPARATOR */
3616                case 0x2029:    /* PARAGRAPH SEPARATOR */
3617                RRETURN(MATCH_NOMATCH);
3618                }
3619              }
3620            break;
3621    
3622            case OP_VSPACE:
3623            for (i = 1; i <= min; i++)
3624              {
3625              if (eptr >= md->end_subject)
3626                {
3627                SCHECK_PARTIAL();
3628                RRETURN(MATCH_NOMATCH);
3629                }
3630              GETCHARINC(c, eptr);
3631              switch(c)
3632                {
3633                default: RRETURN(MATCH_NOMATCH);
3634                case 0x0a:      /* LF */
3635                case 0x0b:      /* VT */
3636                case 0x0c:      /* FF */
3637                case 0x0d:      /* CR */
3638                case 0x85:      /* NEL */
3639                case 0x2028:    /* LINE SEPARATOR */
3640                case 0x2029:    /* PARAGRAPH SEPARATOR */
3641                break;
3642                }
3643              }
3644            break;
3645    
3646          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3647          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3648            {            {
3649            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3650                {
3651                SCHECK_PARTIAL();
3652                RRETURN(MATCH_NOMATCH);
3653                }
3654            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3655            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3656              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
# Line 2596  for (;;) Line 3660  for (;;)
3660          case OP_DIGIT:          case OP_DIGIT:
3661          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3662            {            {
3663            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3664               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3665                SCHECK_PARTIAL();
3666                RRETURN(MATCH_NOMATCH);
3667                }
3668              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3669              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3670            /* 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 */
3671            }            }
# Line 2606  for (;;) Line 3674  for (;;)
3674          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3675          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3676            {            {
3677            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3678               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3679                SCHECK_PARTIAL();
3680              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3681            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3682              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3683                RRETURN(MATCH_NOMATCH);
3684              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3685            }            }
3686          break;          break;
3687    
3688          case OP_WHITESPACE:          case OP_WHITESPACE:
3689          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3690            {            {
3691            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3692               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3693                SCHECK_PARTIAL();
3694                RRETURN(MATCH_NOMATCH);
3695                }
3696              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3697              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3698            /* 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 */
3699            }            }
# Line 2626  for (;;) Line 3702  for (;;)
3702          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3703          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3704            {            {
3705            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3706               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))              {
3707                SCHECK_PARTIAL();
3708              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3709            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3710              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0)
3711                RRETURN(MATCH_NOMATCH);
3712              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3713            }            }
3714          break;          break;
3715    
3716          case OP_WORDCHAR:          case OP_WORDCHAR:
3717          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3718            {            {
3719            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3720               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)              {
3721                SCHECK_PARTIAL();
3722                RRETURN(MATCH_NOMATCH);
3723                }
3724              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3725              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3726            /* 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 */
3727            }            }
# Line 2656  for (;;) Line 3740  for (;;)
3740        switch(ctype)        switch(ctype)
3741          {          {
3742          case OP_ANY:          case OP_ANY:
3743          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3744            {            {
3745            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3746              if (*eptr++ == NEWLINE) RRETURN(MATCH_NOMATCH);              {
3747                SCHECK_PARTIAL();
3748                RRETURN(MATCH_NOMATCH);
3749                }
3750              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3751              eptr++;
3752              }
3753            break;
3754    
3755            case OP_ALLANY:
3756            if (eptr > md->end_subject - min)
3757              {
3758              SCHECK_PARTIAL();
3759              RRETURN(MATCH_NOMATCH);
3760            }            }
3761          else eptr += min;          eptr += min;
3762          break;          break;
3763    
3764          case OP_ANYBYTE:          case OP_ANYBYTE:
3765            if (eptr > md->end_subject - min)
3766              {
3767              SCHECK_PARTIAL();
3768              RRETURN(MATCH_NOMATCH);
3769              }
3770          eptr += min;          eptr += min;
3771          break;          break;
3772    
3773            case OP_ANYNL:
3774            for (i = 1; i <= min; i++)
3775              {
3776              if (eptr >= md->end_subject)
3777                {
3778                SCHECK_PARTIAL();
3779                RRETURN(MATCH_NOMATCH);
3780                }
3781              switch(*eptr++)
3782                {
3783                default: RRETURN(MATCH_NOMATCH);
3784                case 0x000d:
3785                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3786                break;
3787                case 0x000a:
3788                break;
3789    
3790                case 0x000b:
3791                case 0x000c:
3792                case 0x0085:
3793                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3794                break;
3795                }
3796              }
3797            break;
3798    
3799            case OP_NOT_HSPACE:
3800            for (i = 1; i <= min; i++)
3801              {
3802              if (eptr >= md->end_subject)
3803                {
3804                SCHECK_PARTIAL();
3805                RRETURN(MATCH_NOMATCH);
3806                }
3807              switch(*eptr++)
3808                {
3809                default: break;
3810                case 0x09:      /* HT */
3811                case 0x20:      /* SPACE */
3812                case 0xa0:      /* NBSP */
3813                RRETURN(MATCH_NOMATCH);
3814                }
3815              }
3816            break;
3817    
3818            case OP_HSPACE:
3819            for (i = 1; i <= min; i++)
3820              {
3821              if (eptr >= md->end_subject)
3822                {
3823                SCHECK_PARTIAL();
3824                RRETURN(MATCH_NOMATCH);
3825                }
3826              switch(*eptr++)
3827                {
3828                default: RRETURN(MATCH_NOMATCH);
3829                case 0x09:      /* HT */
3830                case 0x20:      /* SPACE */
3831                case 0xa0:      /* NBSP */
3832                break;
3833                }
3834              }
3835            break;
3836    
3837            case OP_NOT_VSPACE:
3838            for (i = 1; i <= min; i++)
3839              {
3840              if (eptr >= md->end_subject)
3841                {
3842                SCHECK_PARTIAL();
3843                RRETURN(MATCH_NOMATCH);
3844                }
3845              switch(*eptr++)
3846                {
3847                default: break;
3848                case 0x0a:      /* LF */
3849                case 0x0b:      /* VT */
3850                case 0x0c:      /* FF */
3851                case 0x0d:      /* CR */
3852                case 0x85:      /* NEL */
3853                RRETURN(MATCH_NOMATCH);
3854                }
3855              }
3856            break;
3857    
3858            case OP_VSPACE:
3859            for (i = 1; i <= min; i++)
3860              {
3861              if (eptr >= md->end_subject)
3862                {
3863                SCHECK_PARTIAL();
3864                RRETURN(MATCH_NOMATCH);
3865                }
3866              switch(*eptr++)
3867                {
3868                default: RRETURN(MATCH_NOMATCH);
3869                case 0x0a:      /* LF */
3870                case 0x0b:      /* VT */
3871                case 0x0c:      /* FF */
3872                case 0x0d:      /* CR */
3873                case 0x85:      /* NEL */
3874                break;
3875                }
3876              }
3877            break;
3878    
3879          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3880          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3881              {
3882              if (eptr >= md->end_subject)
3883                {
3884                SCHECK_PARTIAL();
3885                RRETURN(MATCH_NOMATCH);
3886                }
3887            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3888              }
3889          break;          break;
3890    
3891          case OP_DIGIT:          case OP_DIGIT:
3892          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3893              {
3894              if (eptr >= md->end_subject)
3895                {
3896                SCHECK_PARTIAL();
3897                RRETURN(MATCH_NOMATCH);
3898                }
3899            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3900              }
3901          break;          break;
3902    
3903          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3904          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3905              {
3906              if (eptr >= md->end_subject)
3907                {
3908                SCHECK_PARTIAL();
3909                RRETURN(MATCH_NOMATCH);
3910                }
3911            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3912              }
3913          break;          break;
3914    
3915          case OP_WHITESPACE:          case OP_WHITESPACE:
3916          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3917              {
3918              if (eptr >= md->end_subject)
3919                {
3920                SCHECK_PARTIAL();
3921                RRETURN(MATCH_NOMATCH);
3922                }
3923            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3924              }
3925          break;          break;
3926    
3927          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3928          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3929              {
3930              if (eptr >= md->end_subject)
3931                {
3932                SCHECK_PARTIAL();
3933                RRETURN(MATCH_NOMATCH);
3934                }
3935            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3936              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3937              }
3938          break;          break;
3939    
3940          case OP_WORDCHAR:          case OP_WORDCHAR:
3941          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3942              {
3943              if (eptr >= md->end_subject)
3944                {
3945                SCHECK_PARTIAL();
3946                RRETURN(MATCH_NOMATCH);
3947                }
3948            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3949              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3950              }
3951          break;          break;
3952    
3953          default:          default:
# Line 2723  for (;;) Line 3973  for (;;)
3973            case PT_ANY:            case PT_ANY:
3974            for (fi = min;; fi++)            for (fi = min;; fi++)
3975              {              {
3976              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3977              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3978              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3979                if (eptr >= md->end_subject)
3980                  {
3981                  SCHECK_PARTIAL();
3982                  RRETURN(MATCH_NOMATCH);
3983                  }
3984              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3985              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3986              }              }
3987            break;            /* Control never gets here */
3988    
3989            case PT_LAMP:            case PT_LAMP:
3990            for (fi = min;; fi++)            for (fi = min;; fi++)
3991              {              {
3992              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3993              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3994              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3995                if (eptr >= md->end_subject)
3996                  {
3997                  SCHECK_PARTIAL();
3998                  RRETURN(MATCH_NOMATCH);
3999                  }
4000              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
4001              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
4002              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
4003                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
4004                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
4005                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
4006              }              }
4007            break;            /* Control never gets here */
4008    
4009            case PT_GC:            case PT_GC:
4010            for (fi = min;; fi++)            for (fi = min;; fi++)
4011              {              {
4012              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
4013