/[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 91 by nigel, Sat Feb 24 21:41:34 2007 UTC revision 518 by ph10, Tue May 18 15:47:01 2010 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-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  #define NLBLOCK md           /* The block containing newline information */  #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_ACCEPT       (-999)
75    #define MATCH_COMMIT       (-998)
76    #define MATCH_PRUNE        (-997)
77    #define MATCH_SKIP         (-996)
78    #define MATCH_SKIP_ARG     (-995)
79    #define MATCH_THEN         (-994)
80    
81    /* This is a convenience macro for code that occurs many times. */
82    
83    #define MRRETURN(ra) \
84      { \
85      md->mark = markptr; \
86      RRETURN(ra); \
87      }
88    
89  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
90  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
91  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 81  static const char rep_max[] = { 0, 0, 0, Line 99  static const char rep_max[] = { 0, 0, 0,
99    
100    
101    
102  #ifdef DEBUG  #ifdef PCRE_DEBUG
103  /*************************************************  /*************************************************
104  *        Debugging function to print chars       *  *        Debugging function to print chars       *
105  *************************************************/  *************************************************/
# Line 101  Returns:     nothing Line 119  Returns:     nothing
119  static void  static void
120  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
121  {  {
122  int c;  unsigned int c;
123  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;
124  while (length-- > 0)  while (length-- > 0)
125    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 151  match_ref(int offset, register USPTR ept
151  {  {
152  USPTR p = md->start_subject + md->offset_vector[offset];  USPTR p = md->start_subject + md->offset_vector[offset];
153    
154  #ifdef DEBUG  #ifdef PCRE_DEBUG
155  if (eptr >= md->end_subject)  if (eptr >= md->end_subject)
156    printf("matching subject <null>");    printf("matching subject <null>");
157  else  else
# Line 150  printf("\n"); Line 168  printf("\n");
168    
169  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
170    
171  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
172    properly if Unicode properties are supported. Otherwise, we can check only
173    ASCII characters. */
174    
175  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
176    {    {
177    #ifdef SUPPORT_UTF8
178    #ifdef SUPPORT_UCP
179      if (md->utf8)
180        {
181        USPTR endptr = eptr + length;
182        while (eptr < endptr)
183          {
184          int c, d;
185          GETCHARINC(c, eptr);
186          GETCHARINC(d, p);
187          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
188          }
189        }
190      else
191    #endif
192    #endif
193    
194      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
195      is no UCP support. */
196    
197    while (length-- > 0)    while (length-- > 0)
198      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
199    }    }
200    
201    /* In the caseful case, we can just compare the bytes, whether or not we
202    are in UTF-8 mode. */
203    
204  else  else
205    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
206    
# Line 186  calls by keeping local variables that ne Line 230  calls by keeping local variables that ne
230  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
231  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
232  always used to.  always used to.
233    
234    The original heap-recursive code used longjmp(). However, it seems that this
235    can be very slow on some operating systems. Following a suggestion from Stan
236    Switzer, the use of longjmp() has been abolished, at the cost of having to
237    provide a unique number for each call to RMATCH. There is no way of generating
238    a sequence of numbers at compile time in C. I have given them names, to make
239    them stand out more clearly.
240    
241    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
242    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
243    tests. Furthermore, not using longjmp() means that local dynamic variables
244    don't have indeterminate values; this has meant that the frame size can be
245    reduced because the result can be "passed back" by straight setting of the
246    variable instead of being passed in the frame.
247  ****************************************************************************  ****************************************************************************
248  ***************************************************************************/  ***************************************************************************/
249    
250    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
251    below must be updated in sync.  */
252    
253    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
254           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
255           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
256           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
257           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
258           RM51,  RM52, RM53, RM54, RM55, RM56, RM57, RM58 };
259    
260  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
261  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
262    actually used in this definition. */
263    
264  #ifndef NO_RECURSE  #ifndef NO_RECURSE
265  #define REGISTER register  #define REGISTER register
266  #ifdef DEBUG  
267  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #ifdef PCRE_DEBUG
268    #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
269    { \    { \
270    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1); \
272    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
273    }    }
274  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 277  versions and production versions. */
277    return ra; \    return ra; \
278    }    }
279  #else  #else
280  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
281    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,markptr,rc,rd,re,rf,rg,rdepth+1)
282  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
283  #endif  #endif
284    
285  #else  #else
286    
287    
288  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
289  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
290  match(), which never changes. */  argument of match(), which never changes. */
291    
292  #define REGISTER  #define REGISTER
293    
294  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
295    {\    {\
296    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
297    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
298      {\    newframe->Xeptr = ra;\
299      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
300      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
301      newframe->Xoffset_top = rc;\    newframe->Xmarkptr = markptr;\
302      newframe->Xims = re;\    newframe->Xoffset_top = rc;\
303      newframe->Xeptrb = rf;\    newframe->Xims = re;\
304      newframe->Xflags = rg;\    newframe->Xeptrb = rf;\
305      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xflags = rg;\
306      newframe->Xprevframe = frame;\    newframe->Xrdepth = frame->Xrdepth + 1;\
307      frame = newframe;\    newframe->Xprevframe = frame;\
308      DPRINTF(("restarting from line %d\n", __LINE__));\    frame = newframe;\
309      goto HEAP_RECURSE;\    DPRINTF(("restarting from line %d\n", __LINE__));\
310      }\    goto HEAP_RECURSE;\
311    else\    L_##rw:\
312      {\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
313    }    }
314    
315  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 254  match(), which never changes. */ Line 319  match(), which never changes. */
319    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
320    if (frame != NULL)\    if (frame != NULL)\
321      {\      {\
322      frame->Xresult = ra;\      rrc = ra;\
323      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
324      }\      }\
325    return ra;\    return ra;\
326    }    }
# Line 269  typedef struct heapframe { Line 333  typedef struct heapframe {
333    
334    /* Function arguments that may change */    /* Function arguments that may change */
335    
336    const uschar *Xeptr;    USPTR Xeptr;
337    const uschar *Xecode;    const uschar *Xecode;
338      USPTR Xmstart;
339      USPTR Xmarkptr;
340    int Xoffset_top;    int Xoffset_top;
341    long int Xims;    long int Xims;
342    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 279  typedef struct heapframe { Line 345  typedef struct heapframe {
345    
346    /* Function local variables */    /* Function local variables */
347    
348    const uschar *Xcallpat;    USPTR Xcallpat;
349    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
350    const uschar *Xdata;    USPTR Xcharptr;
351    const uschar *Xnext;  #endif
352    const uschar *Xpp;    USPTR Xdata;
353    const uschar *Xprev;    USPTR Xnext;
354    const uschar *Xsaved_eptr;    USPTR Xpp;
355      USPTR Xprev;
356      USPTR Xsaved_eptr;
357    
358    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
359    
360    BOOL Xcur_is_word;    BOOL Xcur_is_word;
361    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
362    BOOL Xprev_is_word;    BOOL Xprev_is_word;
363    
364    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 370  typedef struct heapframe {
370    int Xprop_category;    int Xprop_category;
371    int Xprop_chartype;    int Xprop_chartype;
372    int Xprop_script;    int Xprop_script;
373    int *Xprop_test_variable;    int Xoclength;
374      uschar Xocchars[8];
375  #endif  #endif
376    
377      int Xcodelink;
378    int Xctype;    int Xctype;
379    int Xfc;    unsigned int Xfc;
380    int Xfi;    int Xfi;
381    int Xlength;    int Xlength;
382    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 390  typedef struct heapframe {
390    
391    eptrblock Xnewptrb;    eptrblock Xnewptrb;
392    
393    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
394    
395    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
396    
397  } heapframe;  } heapframe;
398    
# Line 340  typedef struct heapframe { Line 408  typedef struct heapframe {
408  *         Match from current position            *  *         Match from current position            *
409  *************************************************/  *************************************************/
410    
411  /* 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  
412  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
413  same response.  same response. */
414    
415    /* These macros pack up tests that are used for partial matching, and which
416    appears several times in the code. We set the "hit end" flag if the pointer is
417    at the end of the subject and also past the start of the subject (i.e.
418    something has been matched). For hard partial matching, we then return
419    immediately. The second one is used when we already know we are past the end of
420    the subject. */
421    
422    #define CHECK_PARTIAL()\
423      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
424        {\
425        md->hitend = TRUE;\
426        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\
427        }
428    
429    #define SCHECK_PARTIAL()\
430      if (md->partial != 0 && eptr > mstart)\
431        {\
432        md->hitend = TRUE;\
433        if (md->partial > 1) MRRETURN(PCRE_ERROR_PARTIAL);\
434        }
435    
436  Performance note: It might be tempting to extract commonly used fields from the  
437  md structure (e.g. utf8, end_subject) into individual variables to improve  /* Performance note: It might be tempting to extract commonly used fields from
438    the md structure (e.g. utf8, end_subject) into individual variables to improve
439  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
440  made performance worse.  made performance worse.
441    
442  Arguments:  Arguments:
443     eptr        pointer in subject     eptr        pointer to current character in subject
444     ecode       position in code     ecode       pointer to current position in compiled code
445       mstart      pointer to the current match start position (can be modified
446                     by encountering \K)
447       markptr     pointer to the most recent MARK name, or NULL
448     offset_top  current top pointer     offset_top  current top pointer
449     md          pointer to "static" info for the match     md          pointer to "static" info for the match
450     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 452  Arguments:
452                   brackets - for testing for empty matches                   brackets - for testing for empty matches
453     flags       can contain     flags       can contain
454                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
455                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
456                       group that can match an empty string
457     rdepth      the recursion depth     rdepth      the recursion depth
458    
459  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
460                 MATCH_NOMATCH if failed to match  )                 MATCH_NOMATCH if failed to match  )
461                   a negative MATCH_xxx value for PRUNE, SKIP, etc
462                 a negative PCRE_ERROR_xxx value if aborted by an error condition                 a negative PCRE_ERROR_xxx value if aborted by an error condition
463                   (e.g. stopped by repeated call or recursion limit)                   (e.g. stopped by repeated call or recursion limit)
464  */  */
465    
466  static int  static int
467  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
468    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    const uschar *markptr, int offset_top, match_data *md, unsigned long int ims,
469    int flags, unsigned int rdepth)    eptrblock *eptrb, int flags, unsigned int rdepth)
470  {  {
471  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
472  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
473  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
474    
475  register int  rrc;         /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
476  register int  i;           /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
477  register unsigned int  c;  /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
478  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
479    
480    BOOL minimize, possessive; /* Quantifier options */
481    int condcode;
482    
483  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
484  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
485  heap storage. Set up the top-level frame here; others are obtained from the  heap storage. Set up the top-level frame here; others are obtained from the
# Line 398  frame->Xprevframe = NULL;            /* Line 493  frame->Xprevframe = NULL;            /*
493    
494  frame->Xeptr = eptr;  frame->Xeptr = eptr;
495  frame->Xecode = ecode;  frame->Xecode = ecode;
496    frame->Xmstart = mstart;
497    frame->Xmarkptr = markptr;
498  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
499  frame->Xims = ims;  frame->Xims = ims;
500  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 509  HEAP_RECURSE:
509    
510  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
511  #define ecode              frame->Xecode  #define ecode              frame->Xecode
512    #define mstart             frame->Xmstart
513    #define markptr            frame->Xmarkptr
514  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
515  #define ims                frame->Xims  #define ims                frame->Xims
516  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 424  HEAP_RECURSE: Line 523  HEAP_RECURSE:
523  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
524  #endif  #endif
525  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
526    #define codelink           frame->Xcodelink
527  #define data               frame->Xdata  #define data               frame->Xdata
528  #define next               frame->Xnext  #define next               frame->Xnext
529  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 434  HEAP_RECURSE: Line 534  HEAP_RECURSE:
534    
535  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
536  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
537  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
538    
539  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 545  HEAP_RECURSE:
545  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
546  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
547  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
548  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
549    #define occhars            frame->Xocchars
550  #endif  #endif
551    
552  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 570  HEAP_RECURSE:
570  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
571  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
572    
573  #else  #else         /* NO_RECURSE not defined */
574  #define fi i  #define fi i
575  #define fc c  #define fc c
576    
# Line 489  recursion_info new_recursive;      /* wi Line 589  recursion_info new_recursive;      /* wi
589                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
590  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
591  BOOL condition;  BOOL condition;
 BOOL minimize;  
592  BOOL prev_is_word;  BOOL prev_is_word;
593    
594  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 600  int prop_fail_result;
600  int prop_category;  int prop_category;
601  int prop_chartype;  int prop_chartype;
602  int prop_script;  int prop_script;
603  int *prop_test_variable;  int oclength;
604    uschar occhars[8];
605  #endif  #endif
606    
607    int codelink;
608  int ctype;  int ctype;
609  int length;  int length;
610  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 617  int save_offset1, save_offset2, save_off
617  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
618    
619  eptrblock newptrb;  eptrblock newptrb;
620  #endif  #endif     /* NO_RECURSE */
621    
622  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
623  variables. */  variables. */
# Line 524  variables. */ Line 625  variables. */
625  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
626  prop_value = 0;  prop_value = 0;
627  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
628  #endif  #endif
629    
630    
631  /* This label is used for tail recursion, which is used in a few cases even  /* This label is used for tail recursion, which is used in a few cases even
632  when NO_RECURSE is not defined, in order to reduce the amount of stack that is  when NO_RECURSE is not defined, in order to reduce the amount of stack that is
633  used. Thanks to Ian Taylor for noticing this possibility and sending the  used. Thanks to Ian Taylor for noticing this possibility and sending the
# Line 537  TAIL_RECURSE: Line 638  TAIL_RECURSE:
638  /* OK, now we can get on with the real code of the function. Recursive calls  /* OK, now we can get on with the real code of the function. Recursive calls
639  are specified by the macro RMATCH and RRETURN is used to return. When  are specified by the macro RMATCH and RRETURN is used to return. When
640  NO_RECURSE is *not* defined, these just turn into a recursive call to match()  NO_RECURSE is *not* defined, these just turn into a recursive call to match()
641  and a "return", respectively (possibly with some debugging if DEBUG is  and a "return", respectively (possibly with some debugging if PCRE_DEBUG is
642  defined). However, RMATCH isn't like a function call because it's quite a  defined). However, RMATCH isn't like a function call because it's quite a
643  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
644  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
645    
646    #ifdef SUPPORT_UTF8
647    utf8 = md->utf8;       /* Local copy of the flag */
648    #else
649    utf8 = FALSE;
650    #endif
651    
652  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
653  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
654    
# Line 550  if (rdepth >= md->match_limit_recursion) Line 657  if (rdepth >= md->match_limit_recursion)
657    
658  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
659    
660  #ifdef SUPPORT_UTF8  /* At the start of a group with an unlimited repeat that may match an empty
661  utf8 = md->utf8;       /* Local copy of the flag */  string, the match_cbegroup flag is set. When this is the case, add the current
662  #else  subject pointer to the chain of such remembered pointers, to be checked when we
663  utf8 = FALSE;  hit the closing ket, in order to break infinite loops that match no characters.
664  #endif  When match() is called in other circumstances, don't add to the chain. The
665    match_cbegroup flag must NOT be used with tail recursion, because the memory
666  /* At the start of a bracketed group, add the current subject pointer to the  block that is used is on the stack, so a new one may be required for each
667  stack of such pointers, to be re-instated at the end of the group when we hit  match(). */
 the closing ket. When match() is called in other circumstances, we don't add to  
 this stack. */  
668    
669  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
670    {    {
   newptrb.epb_prev = eptrb;  
671    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
672      newptrb.epb_prev = eptrb;
673    eptrb = &newptrb;    eptrb = &newptrb;
674    }    }
675    
676  /* Now start processing the operations. */  /* Now start processing the opcodes. */
677    
678  for (;;)  for (;;)
679    {    {
680      minimize = possessive = FALSE;
681    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. */  
682    
683    if (md->partial &&    switch(op)
       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. */  
   
   if (op > OP_BRA)  
684      {      {
685      number = op - OP_BRA;      case OP_MARK:
686        markptr = ecode + 2;
687      /* For extended extraction brackets (large number), we have to fish out the      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
688      number from a dummy opcode at the start. */        ims, eptrb, flags, RM55);
689    
690      if (number > EXTRACT_BASIC_MAX)      /* A return of MATCH_SKIP_ARG means that matching failed at SKIP with an
691        number = GET2(ecode, 2+LINK_SIZE);      argument, and we must check whether that argument matches this MARK's
692        argument. It is passed back in md->start_match_ptr (an overloading of that
693        variable). If it does match, we reset that variable to the current subject
694        position and return MATCH_SKIP. Otherwise, pass back the return code
695        unaltered. */
696    
697        if (rrc == MATCH_SKIP_ARG &&
698            strcmp((char *)markptr, (char *)(md->start_match_ptr)) == 0)
699          {
700          md->start_match_ptr = eptr;
701          RRETURN(MATCH_SKIP);
702          }
703    
704        if (md->mark == NULL) md->mark = markptr;
705        RRETURN(rrc);
706    
707        case OP_FAIL:
708        MRRETURN(MATCH_NOMATCH);
709    
710        case OP_COMMIT:
711        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
712          ims, eptrb, flags, RM52);
713        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
714        MRRETURN(MATCH_COMMIT);
715    
716        case OP_PRUNE:
717        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
718          ims, eptrb, flags, RM51);
719        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
720        MRRETURN(MATCH_PRUNE);
721    
722        case OP_PRUNE_ARG:
723        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
724          ims, eptrb, flags, RM56);
725        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
726        md->mark = ecode + 2;
727        RRETURN(MATCH_PRUNE);
728    
729        case OP_SKIP:
730        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
731          ims, eptrb, flags, RM53);
732        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
733        md->start_match_ptr = eptr;   /* Pass back current position */
734        MRRETURN(MATCH_SKIP);
735    
736        case OP_SKIP_ARG:
737        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
738          ims, eptrb, flags, RM57);
739        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
740    
741        /* Pass back the current skip name by overloading md->start_match_ptr and
742        returning the special MATCH_SKIP_ARG return code. This will either be
743        caught by a matching MARK, or get to the top, where it is treated the same
744        as PRUNE. */
745    
746        md->start_match_ptr = ecode + 2;
747        RRETURN(MATCH_SKIP_ARG);
748    
749        case OP_THEN:
750        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
751          ims, eptrb, flags, RM54);
752        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
753        MRRETURN(MATCH_THEN);
754    
755        case OP_THEN_ARG:
756        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode] + ecode[1], offset_top, md,
757          ims, eptrb, flags, RM58);
758        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
759        md->mark = ecode + 2;
760        RRETURN(MATCH_THEN);
761    
762        /* Handle a capturing bracket. If there is space in the offset vector, save
763        the current subject position in the working slot at the top of the vector.
764        We mustn't change the current values of the data slot, because they may be
765        set from a previous iteration of this group, and be referred to by a
766        reference inside the group.
767    
768        If the bracket fails to match, we need to restore this value and also the
769        values of the final offsets, in case they were set by a previous iteration
770        of the same bracket.
771    
772        If there isn't enough space in the offset vector, treat this as if it were
773        a non-capturing bracket. Don't worry about setting the flag for the error
774        case here; that is handled in the code for KET. */
775    
776        case OP_CBRA:
777        case OP_SCBRA:
778        number = GET2(ecode, 1+LINK_SIZE);
779      offset = number << 1;      offset = number << 1;
780    
781  #ifdef DEBUG  #ifdef PCRE_DEBUG
782      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
783        printf("subject=");
784      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
785      printf("\n");      printf("\n");
786  #endif  #endif
# Line 624  for (;;) Line 795  for (;;)
795        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
796        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
797    
798          flags = (op == OP_SCBRA)? match_cbegroup : 0;
799        do        do
800          {          {
801          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
802            match_isgroup);            ims, eptrb, flags, RM1);
803          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
804          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
805          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
806          }          }
# Line 640  for (;;) Line 812  for (;;)
812        md->offset_vector[offset+1] = save_offset2;        md->offset_vector[offset+1] = save_offset2;
813        md->offset_vector[md->offset_end - number] = save_offset3;        md->offset_vector[md->offset_end - number] = save_offset3;
814    
815          if (rrc != MATCH_THEN) md->mark = markptr;
816        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
817        }        }
818    
819      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
820        as a non-capturing bracket. */
821    
822      else op = OP_BRA;      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
823      }      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
   
   /* Other types of node can be handled by a switch */  
   
   switch(op)  
     {  
     case OP_BRA:     /* Non-capturing bracket: optimized */  
     DPRINTF(("start bracket 0\n"));  
824    
825      /* Loop for all the alternatives */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
826    
827        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
828        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
829    
830        /* Non-capturing bracket. Loop for all the alternatives. When we get to the
831        final alternative within the brackets, we would return the result of a
832        recursive call to match() whatever happened. We can reduce stack usage by
833        turning this into a tail recursion, except in the case when match_cbegroup
834        is set.*/
835    
836        case OP_BRA:
837        case OP_SBRA:
838        DPRINTF(("start non-capturing bracket\n"));
839        flags = (op >= OP_SBRA)? match_cbegroup : 0;
840      for (;;)      for (;;)
841        {        {
842        /* When we get to the final alternative within the brackets, we would        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
843        return the result of a recursive call to match() whatever happened. We          {
844        can reduce stack usage by turning this into a tail recursion. */          if (flags == 0)    /* Not a possibly empty group */
845              {
846        if (ecode[GET(ecode, 1)] != OP_ALT)            ecode += _pcre_OP_lengths[*ecode];
847         {            DPRINTF(("bracket 0 tail recursion\n"));
848         ecode += 1 + LINK_SIZE;            goto TAIL_RECURSE;
849         flags = match_isgroup;            }
850         DPRINTF(("bracket 0 tail recursion\n"));  
851         goto TAIL_RECURSE;          /* Possibly empty group; can't use tail recursion. */
852         }  
853            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
854              eptrb, flags, RM48);
855            if (rrc == MATCH_NOMATCH) md->mark = markptr;
856            RRETURN(rrc);
857            }
858    
859        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
860        otherwise return. */        otherwise return. */
861    
862        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
863          match_isgroup);          eptrb, flags, RM2);
864        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
865        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
866        }        }
867      /* Control never reaches here. */      /* Control never reaches here. */
# Line 688  for (;;) Line 873  for (;;)
873      obeyed, we can use tail recursion to avoid using another stack frame. */      obeyed, we can use tail recursion to avoid using another stack frame. */
874    
875      case OP_COND:      case OP_COND:
876      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
877        codelink= GET(ecode, 1);
878    
879        /* Because of the way auto-callout works during compile, a callout item is
880        inserted between OP_COND and an assertion condition. */
881    
882        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
883          {
884          if (pcre_callout != NULL)
885            {
886            pcre_callout_block cb;
887            cb.version          = 1;   /* Version 1 of the callout block */
888            cb.callout_number   = ecode[LINK_SIZE+2];
889            cb.offset_vector    = md->offset_vector;
890            cb.subject          = (PCRE_SPTR)md->start_subject;
891            cb.subject_length   = md->end_subject - md->start_subject;
892            cb.start_match      = mstart - md->start_subject;
893            cb.current_position = eptr - md->start_subject;
894            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
895            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
896            cb.capture_top      = offset_top/2;
897            cb.capture_last     = md->capture_last;
898            cb.callout_data     = md->callout_data;
899            if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
900            if (rrc < 0) RRETURN(rrc);
901            }
902          ecode += _pcre_OP_lengths[OP_CALLOUT];
903          }
904    
905        condcode = ecode[LINK_SIZE+1];
906    
907        /* Now see what the actual condition is */
908    
909        if (condcode == OP_RREF || condcode == OP_NRREF)    /* Recursion test */
910          {
911          if (md->recursive == NULL)                /* Not recursing => FALSE */
912            {
913            condition = FALSE;
914            ecode += GET(ecode, 1);
915            }
916          else
917            {
918            int recno = GET2(ecode, LINK_SIZE + 2);   /* Recursion group number*/
919            condition =  (recno == RREF_ANY || recno == md->recursive->group_num);
920    
921            /* If the test is for recursion into a specific subpattern, and it is
922            false, but the test was set up by name, scan the table to see if the
923            name refers to any other numbers, and test them. The condition is true
924            if any one is set. */
925    
926            if (!condition && condcode == OP_NRREF && recno != RREF_ANY)
927              {
928              uschar *slotA = md->name_table;
929              for (i = 0; i < md->name_count; i++)
930                {
931                if (GET2(slotA, 0) == recno) break;
932                slotA += md->name_entry_size;
933                }
934    
935              /* Found a name for the number - there can be only one; duplicate
936              names for different numbers are allowed, but not vice versa. First
937              scan down for duplicates. */
938    
939              if (i < md->name_count)
940                {
941                uschar *slotB = slotA;
942                while (slotB > md->name_table)
943                  {
944                  slotB -= md->name_entry_size;
945                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
946                    {
947                    condition = GET2(slotB, 0) == md->recursive->group_num;
948                    if (condition) break;
949                    }
950                  else break;
951                  }
952    
953                /* Scan up for duplicates */
954    
955                if (!condition)
956                  {
957                  slotB = slotA;
958                  for (i++; i < md->name_count; i++)
959                    {
960                    slotB += md->name_entry_size;
961                    if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
962                      {
963                      condition = GET2(slotB, 0) == md->recursive->group_num;
964                      if (condition) break;
965                      }
966                    else break;
967                    }
968                  }
969                }
970              }
971    
972            /* Chose branch according to the condition */
973    
974            ecode += condition? 3 : GET(ecode, 1);
975            }
976          }
977    
978        else if (condcode == OP_CREF || condcode == OP_NCREF)  /* Group used test */
979        {        {
980        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
981        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
982          (md->recursive != NULL) :  
983          (offset < offset_top && md->offset_vector[offset] >= 0);        /* If the numbered capture is unset, but the reference was by name,
984        ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1));        scan the table to see if the name refers to any other numbers, and test
985        flags = match_isgroup;        them. The condition is true if any one is set. This is tediously similar
986        goto TAIL_RECURSE;        to the code above, but not close enough to try to amalgamate. */
987    
988          if (!condition && condcode == OP_NCREF)
989            {
990            int refno = offset >> 1;
991            uschar *slotA = md->name_table;
992    
993            for (i = 0; i < md->name_count; i++)
994              {
995              if (GET2(slotA, 0) == refno) break;
996              slotA += md->name_entry_size;
997              }
998    
999            /* Found a name for the number - there can be only one; duplicate names
1000            for different numbers are allowed, but not vice versa. First scan down
1001            for duplicates. */
1002    
1003            if (i < md->name_count)
1004              {
1005              uschar *slotB = slotA;
1006              while (slotB > md->name_table)
1007                {
1008                slotB -= md->name_entry_size;
1009                if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1010                  {
1011                  offset = GET2(slotB, 0) << 1;
1012                  condition = offset < offset_top &&
1013                    md->offset_vector[offset] >= 0;
1014                  if (condition) break;
1015                  }
1016                else break;
1017                }
1018    
1019              /* Scan up for duplicates */
1020    
1021              if (!condition)
1022                {
1023                slotB = slotA;
1024                for (i++; i < md->name_count; i++)
1025                  {
1026                  slotB += md->name_entry_size;
1027                  if (strcmp((char *)slotA + 2, (char *)slotB + 2) == 0)
1028                    {
1029                    offset = GET2(slotB, 0) << 1;
1030                    condition = offset < offset_top &&
1031                      md->offset_vector[offset] >= 0;
1032                    if (condition) break;
1033                    }
1034                  else break;
1035                  }
1036                }
1037              }
1038            }
1039    
1040          /* Chose branch according to the condition */
1041    
1042          ecode += condition? 3 : GET(ecode, 1);
1043          }
1044    
1045        else if (condcode == OP_DEF)     /* DEFINE - always false */
1046          {
1047          condition = FALSE;
1048          ecode += GET(ecode, 1);
1049        }        }
1050    
1051      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
1052      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
1053        assertion. */
1054    
1055      else      else
1056        {        {
1057        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
1058            match_condassert | match_isgroup);            match_condassert, RM3);
1059        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
1060          {          {
1061          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
1062            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
1063          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
1064          }          }
1065        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1066          {          {
1067          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
1068          }          }
1069        else ecode += GET(ecode, 1);        else
1070            {
1071            condition = FALSE;
1072            ecode += codelink;
1073            }
1074          }
1075    
1076        /* We are now at the branch that is to be obeyed. As there is only one,      /* We are now at the branch that is to be obeyed. As there is only one,
1077        we can use tail recursion to avoid using another stack frame. */      we can use tail recursion to avoid using another stack frame, except when
1078        match_cbegroup is required for an unlimited repeat of a possibly empty
1079        group. If the second alternative doesn't exist, we can just plough on. */
1080    
1081        if (condition || *ecode == OP_ALT)
1082          {
1083        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1084        flags = match_isgroup;        if (op == OP_SCOND)        /* Possibly empty group */
1085        goto TAIL_RECURSE;          {
1086            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
1087            RRETURN(rrc);
1088            }
1089          else                       /* Group must match something */
1090            {
1091            flags = 0;
1092            goto TAIL_RECURSE;
1093            }
1094        }        }
1095      /* Control never reaches here */      else                         /* Condition false & no alternative */
1096          {
1097          ecode += 1 + LINK_SIZE;
1098          }
1099        break;
1100    
1101    
1102        /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
1103        to close any currently open capturing brackets. */
1104    
1105        case OP_CLOSE:
1106        number = GET2(ecode, 1);
1107        offset = number << 1;
1108    
1109      /* Skip over conditional reference or large extraction number data if  #ifdef PCRE_DEBUG
1110      encountered. */        printf("end bracket %d at *ACCEPT", number);
1111          printf("\n");
1112    #endif
1113    
1114      case OP_CREF:      md->capture_last = number;
1115      case OP_BRANUMBER:      if (offset >= md->offset_max) md->offset_overflow = TRUE; else
1116          {
1117          md->offset_vector[offset] =
1118            md->offset_vector[md->offset_end - number];
1119          md->offset_vector[offset+1] = eptr - md->start_subject;
1120          if (offset_top <= offset) offset_top = offset + 2;
1121          }
1122      ecode += 3;      ecode += 3;
1123      break;      break;
1124    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
1125    
1126        /* End of the pattern, either real or forced. If we are in a top-level
1127        recursion, we should restore the offsets appropriately and continue from
1128        after the call. */
1129    
1130        case OP_ACCEPT:
1131      case OP_END:      case OP_END:
1132      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
1133        {        {
# Line 745  for (;;) Line 1136  for (;;)
1136        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
1137        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
1138          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
1139        md->start_match = rec->save_start;        offset_top = rec->save_offset_top;
1140        ims = original_ims;        ims = original_ims;
1141        ecode = rec->after_call;        ecode = rec->after_call;
1142        break;        break;
1143        }        }
1144    
1145      /* Otherwise, if PCRE_NOTEMPTY is set, fail if we have matched an empty      /* Otherwise, if we have matched an empty string, fail if PCRE_NOTEMPTY is
1146      string - backtracking will then try other alternatives, if any. */      set, or if PCRE_NOTEMPTY_ATSTART is set and we have matched at the start of
1147        the subject. In both cases, backtracking will then try other alternatives,
1148        if any. */
1149    
1150        if (eptr == mstart &&
1151            (md->notempty ||
1152              (md->notempty_atstart &&
1153                mstart == md->start_subject + md->start_offset)))
1154          MRRETURN(MATCH_NOMATCH);
1155    
1156        /* Otherwise, we have a match. */
1157    
1158        md->end_match_ptr = eptr;           /* Record where we ended */
1159        md->end_offset_top = offset_top;    /* and how many extracts were taken */
1160        md->start_match_ptr = mstart;       /* and the start (\K can modify) */
1161    
1162      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      /* For some reason, the macros don't work properly if an expression is
1163      md->end_match_ptr = eptr;          /* Record where we ended */      given as the argument to MRRETURN when the heap is in use. */
1164      md->end_offset_top = offset_top;   /* and how many extracts were taken */  
1165      RRETURN(MATCH_MATCH);      rrc = (op == OP_END)? MATCH_MATCH : MATCH_ACCEPT;
1166        MRRETURN(rrc);
1167    
1168      /* Change option settings */      /* Change option settings */
1169    
# Line 777  for (;;) Line 1183  for (;;)
1183      case OP_ASSERTBACK:      case OP_ASSERTBACK:
1184      do      do
1185        {        {
1186        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1187          match_isgroup);          RM4);
1188        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1189        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          {
1190            mstart = md->start_match_ptr;   /* In case \K reset it */
1191            break;
1192            }
1193          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1194        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
1195        }        }
1196      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
1197      if (*ecode == OP_KET) RRETURN(MATCH_NOMATCH);      if (*ecode == OP_KET) MRRETURN(MATCH_NOMATCH);
1198    
1199      /* If checking an assertion for a condition, return MATCH_MATCH. */      /* If checking an assertion for a condition, return MATCH_MATCH. */
1200    
# Line 798  for (;;) Line 1208  for (;;)
1208      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1209      continue;      continue;
1210    
1211      /* Negative assertion: all branches must fail to match */      /* Negative assertion: all branches must fail to match. Encountering SKIP,
1212        PRUNE, or COMMIT means we must assume failure without checking subsequent
1213        branches. */
1214    
1215      case OP_ASSERT_NOT:      case OP_ASSERT_NOT:
1216      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1217      do      do
1218        {        {
1219        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1220          match_isgroup);          RM5);
1221        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT) MRRETURN(MATCH_NOMATCH);
1222        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc == MATCH_SKIP || rrc == MATCH_PRUNE || rrc == MATCH_COMMIT)
1223            {
1224            do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1225            break;
1226            }
1227          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1228        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1229        }        }
1230      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 826  for (;;) Line 1243  for (;;)
1243  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1244      if (utf8)      if (utf8)
1245        {        {
1246        c = GET(ecode,1);        i = GET(ecode, 1);
1247        for (i = 0; i < c; i++)        while (i-- > 0)
1248          {          {
1249          eptr--;          eptr--;
1250          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1251          BACKCHAR(eptr)          BACKCHAR(eptr);
1252          }          }
1253        }        }
1254      else      else
# Line 840  for (;;) Line 1257  for (;;)
1257      /* 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 */
1258    
1259        {        {
1260        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1261        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) MRRETURN(MATCH_NOMATCH);
1262        }        }
1263    
1264      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1265    
1266        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1267      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1268      break;      break;
1269    
# Line 862  for (;;) Line 1280  for (;;)
1280        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1281        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1282        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1283        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1284        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1285        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1286        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
1287        cb.capture_top      = offset_top/2;        cb.capture_top      = offset_top/2;
1288        cb.capture_last     = md->capture_last;        cb.capture_last     = md->capture_last;
1289        cb.callout_data     = md->callout_data;        cb.callout_data     = md->callout_data;
1290        if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);        if ((rrc = (*pcre_callout)(&cb)) > 0) MRRETURN(MATCH_NOMATCH);
1291        if (rrc < 0) RRETURN(rrc);        if (rrc < 0) RRETURN(rrc);
1292        }        }
1293      ecode += 2 + 2*LINK_SIZE;      ecode += 2 + 2*LINK_SIZE;
# Line 897  for (;;) Line 1315  for (;;)
1315      case OP_RECURSE:      case OP_RECURSE:
1316        {        {
1317        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1318        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1319            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);  
1320    
1321        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1322    
# Line 929  for (;;) Line 1342  for (;;)
1342    
1343        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1344              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1345        new_recursive.save_start = md->start_match;        new_recursive.save_offset_top = offset_top;
       md->start_match = eptr;  
1346    
1347        /* OK, now we can do the recursion. For each top-level alternative we        /* OK, now we can do the recursion. For each top-level alternative we
1348        restore the offset and recursion data. */        restore the offset and recursion data. */
1349    
1350        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1351          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1352        do        do
1353          {          {
1354          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1355              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1356          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH || rrc == MATCH_ACCEPT)
1357            {            {
1358            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
1359            md->recursive = new_recursive.prevrec;            md->recursive = new_recursive.prevrec;
1360            if (new_recursive.offset_save != stacksave)            if (new_recursive.offset_save != stacksave)
1361              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1362            RRETURN(MATCH_MATCH);            MRRETURN(MATCH_MATCH);
1363            }            }
1364          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1365            {            {
1366            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1367              if (new_recursive.offset_save != stacksave)
1368                (pcre_free)(new_recursive.offset_save);
1369            RRETURN(rrc);            RRETURN(rrc);
1370            }            }
1371    
# Line 965  for (;;) Line 1380  for (;;)
1380        md->recursive = new_recursive.prevrec;        md->recursive = new_recursive.prevrec;
1381        if (new_recursive.offset_save != stacksave)        if (new_recursive.offset_save != stacksave)
1382          (pcre_free)(new_recursive.offset_save);          (pcre_free)(new_recursive.offset_save);
1383        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1384        }        }
1385      /* Control never reaches here */      /* Control never reaches here */
1386    
# Line 974  for (;;) Line 1389  for (;;)
1389      a move back into the brackets. Friedl calls these "atomic" subpatterns.      a move back into the brackets. Friedl calls these "atomic" subpatterns.
1390      Check the alternative branches in turn - the matching won't pass the KET      Check the alternative branches in turn - the matching won't pass the KET
1391      for this kind of subpattern. If any one branch matches, we carry on as at      for this kind of subpattern. If any one branch matches, we carry on as at
1392      the end of a normal bracket, leaving the subject pointer. */      the end of a normal bracket, leaving the subject pointer, but resetting
1393        the start-of-match value in case it was changed by \K. */
1394    
1395      case OP_ONCE:      case OP_ONCE:
1396      prev = ecode;      prev = ecode;
# Line 982  for (;;) Line 1398  for (;;)
1398    
1399      do      do
1400        {        {
1401        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
1402          eptrb, match_isgroup);        if (rrc == MATCH_MATCH)  /* Note: _not_ MATCH_ACCEPT */
1403        if (rrc == MATCH_MATCH) break;          {
1404        if (rrc != MATCH_NOMATCH) RRETURN(rrc);          mstart = md->start_match_ptr;
1405            break;
1406            }
1407          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1408        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1409        }        }
1410      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 997  for (;;) Line 1416  for (;;)
1416      /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1417      mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1418    
1419      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1420    
1421      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1422      eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
# Line 1028  for (;;) Line 1447  for (;;)
1447    
1448      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1449        {        {
1450        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM8);
1451        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1452        ecode = prev;        ecode = prev;
1453        flags = match_isgroup;        flags = 0;
1454        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1455        }        }
1456      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1457        {        {
1458        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1459        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1460        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1461        flags = 0;        flags = 0;
# Line 1051  for (;;) Line 1470  for (;;)
1470      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1471      break;      break;
1472    
1473      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1474      that it may occur zero times. It may repeat infinitely, or not at all -      indicating that it may occur zero times. It may repeat infinitely, or not
1475      i.e. it could be ()* or ()? in the pattern. Brackets with fixed upper      at all - i.e. it could be ()* or ()? or even (){0} in the pattern. Brackets
1476      repeat limits are compiled as a number of copies, with the optional ones      with fixed upper repeat limits are compiled as a number of copies, with the
1477      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1478    
1479      case OP_BRAZERO:      case OP_BRAZERO:
1480        {        {
1481        next = ecode+1;        next = ecode+1;
1482        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1483        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1484        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1485        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1486        }        }
1487      break;      break;
1488    
1489      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1490        {        {
1491        next = ecode+1;        next = ecode+1;
1492        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1493        RMATCH(rrc, eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, next + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0, RM11);
         match_isgroup);  
1494        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1495        ecode++;        ecode++;
1496        }        }
1497      break;      break;
1498    
1499      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1500      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1501      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1502      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1503          ecode = next + 1 + LINK_SIZE;
1504          }
1505        break;
1506    
1507        /* End of a group, repeated or non-repeating. */
1508    
1509      case OP_KET:      case OP_KET:
1510      case OP_KETRMIN:      case OP_KETRMIN:
1511      case OP_KETRMAX:      case OP_KETRMAX:
1512      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
     saved_eptr = eptrb->epb_saved_eptr;  
1513    
1514      /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1515        infinite repeats of empty string matches, retrieve the subject start from
1516        the chain. Otherwise, set it NULL. */
1517    
1518        if (*prev >= OP_SBRA)
1519          {
1520          saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1521          eptrb = eptrb->epb_prev;              /* Backup to previous group */
1522          }
1523        else saved_eptr = NULL;
1524    
1525      eptrb = eptrb->epb_prev;      /* If we are at the end of an assertion group or an atomic group, stop
1526        matching and return MATCH_MATCH, but record the current high water mark for
1527        use by positive assertions. We also need to record the match start in case
1528        it was changed by \K. */
1529    
1530      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1531          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1099  for (;;) Line 1533  for (;;)
1533        {        {
1534        md->end_match_ptr = eptr;      /* For ONCE */        md->end_match_ptr = eptr;      /* For ONCE */
1535        md->end_offset_top = offset_top;        md->end_offset_top = offset_top;
1536        RRETURN(MATCH_MATCH);        md->start_match_ptr = mstart;
1537          MRRETURN(MATCH_MATCH);
1538        }        }
1539    
1540      /* In all other cases except a conditional group we have to check the      /* For capturing groups we have to check the group number back at the start
1541      group number back at the start and if necessary complete handling an      and if necessary complete handling an extraction by setting the offsets and
1542      extraction by setting the offsets and bumping the high water mark. */      bumping the high water mark. Note that whole-pattern recursion is coded as
1543        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1544        when the OP_END is reached. Other recursion is handled here. */
1545    
1546      if (*prev != OP_COND)      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1547        {        {
1548        number = *prev - OP_BRA;        number = GET2(prev, 1+LINK_SIZE);
   
       /* For extended extraction brackets (large number), we have to fish out  
       the number from a dummy opcode at the start. */  
   
       if (number > EXTRACT_BASIC_MAX) number = GET2(prev, 2+LINK_SIZE);  
1549        offset = number << 1;        offset = number << 1;
1550    
1551  #ifdef DEBUG  #ifdef PCRE_DEBUG
1552        printf("end bracket %d", number);        printf("end bracket %d", number);
1553        printf("\n");        printf("\n");
1554  #endif  #endif
1555    
1556        /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1557        of recursion. Note that whole-pattern recursion is coded as a recurse        if (offset >= md->offset_max) md->offset_overflow = TRUE; else
       into group 0, so it won't be picked up here. Instead, we catch it when  
       the OP_END is reached. */  
   
       if (number > 0)  
1558          {          {
1559          md->capture_last = number;          md->offset_vector[offset] =
1560          if (offset >= md->offset_max) md->offset_overflow = TRUE; else            md->offset_vector[md->offset_end - number];
1561            {          md->offset_vector[offset+1] = eptr - md->start_subject;
1562            md->offset_vector[offset] =          if (offset_top <= offset) offset_top = offset + 2;
1563              md->offset_vector[md->offset_end - number];          }
1564            md->offset_vector[offset+1] = eptr - md->start_subject;  
1565            if (offset_top <= offset) offset_top = offset + 2;        /* Handle a recursively called group. Restore the offsets
1566            }        appropriately and continue from after the call. */
1567    
1568          /* Handle a recursively called group. Restore the offsets        if (md->recursive != NULL && md->recursive->group_num == number)
1569          appropriately and continue from after the call. */          {
1570            recursion_info *rec = md->recursive;
1571          if (md->recursive != NULL && md->recursive->group_num == number)          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1572            {          md->recursive = rec->prevrec;
1573            recursion_info *rec = md->recursive;          memcpy(md->offset_vector, rec->offset_save,
1574            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));            rec->saved_max * sizeof(int));
1575            md->recursive = rec->prevrec;          offset_top = rec->save_offset_top;
1576            md->start_match = rec->save_start;          ecode = rec->after_call;
1577            memcpy(md->offset_vector, rec->offset_save,          ims = original_ims;
1578              rec->saved_max * sizeof(int));          break;
           ecode = rec->after_call;  
           ims = original_ims;  
           break;  
           }  
1579          }          }
1580        }        }
1581    
1582      /* Reset the value of the ims flags, in case they got changed during      /* For both capturing and non-capturing groups, reset the value of the ims
1583      the group. */      flags, in case they got changed during the group. */
1584    
1585      ims = original_ims;      ims = original_ims;
1586      DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
# Line 1175  for (;;) Line 1599  for (;;)
1599    
1600      /* The repeating kets try the rest of the pattern or restart from the      /* The repeating kets try the rest of the pattern or restart from the
1601      preceding bracket, in the appropriate order. In the second case, we can use      preceding bracket, in the appropriate order. In the second case, we can use
1602      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1603        unlimited repeat of a group that can match an empty string. */
1604    
1605        flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1606    
1607      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1608        {        {
1609        RMATCH(rrc, eptr, ecode + 1+LINK_SIZE, offset_top, md, ims, eptrb, 0);        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM12);
1610        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1611          if (flags != 0)    /* Could match an empty string */
1612            {
1613            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1614            RRETURN(rrc);
1615            }
1616        ecode = prev;        ecode = prev;
       flags = match_isgroup;  
1617        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1618        }        }
1619      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1620        {        {
1621        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1622        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1623        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1624        flags = 0;        flags = 0;
# Line 1198  for (;;) Line 1629  for (;;)
1629      /* Start of subject unless notbol, or after internal newline if multiline */      /* Start of subject unless notbol, or after internal newline if multiline */
1630    
1631      case OP_CIRC:      case OP_CIRC:
1632      if (md->notbol && eptr == md->start_subject) RRETURN(MATCH_NOMATCH);      if (md->notbol && eptr == md->start_subject) MRRETURN(MATCH_NOMATCH);
1633      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1634        {        {
1635        if (eptr != md->start_subject &&        if (eptr != md->start_subject &&
1636            (eptr == md->end_subject ||            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
1637             eptr < md->start_subject + md->nllen ||          MRRETURN(MATCH_NOMATCH);
            !IS_NEWLINE(eptr - md->nllen)))  
         RRETURN(MATCH_NOMATCH);  
1638        ecode++;        ecode++;
1639        break;        break;
1640        }        }
# Line 1214  for (;;) Line 1643  for (;;)
1643      /* Start of subject assertion */      /* Start of subject assertion */
1644    
1645      case OP_SOD:      case OP_SOD:
1646      if (eptr != md->start_subject) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject) MRRETURN(MATCH_NOMATCH);
1647      ecode++;      ecode++;
1648      break;      break;
1649    
1650      /* Start of match assertion */      /* Start of match assertion */
1651    
1652      case OP_SOM:      case OP_SOM:
1653      if (eptr != md->start_subject + md->start_offset) RRETURN(MATCH_NOMATCH);      if (eptr != md->start_subject + md->start_offset) MRRETURN(MATCH_NOMATCH);
1654        ecode++;
1655        break;
1656    
1657        /* Reset the start of match point */
1658    
1659        case OP_SET_SOM:
1660        mstart = eptr;
1661      ecode++;      ecode++;
1662      break;      break;
1663    
# Line 1232  for (;;) Line 1668  for (;;)
1668      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1669        {        {
1670        if (eptr < md->end_subject)        if (eptr < md->end_subject)
1671          { if (!IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH); }          { if (!IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH); }
1672        else        else
1673          { if (md->noteol) RRETURN(MATCH_NOMATCH); }          { if (md->noteol) MRRETURN(MATCH_NOMATCH); }
1674        ecode++;        ecode++;
1675        break;        break;
1676        }        }
1677      else      else
1678        {        {
1679        if (md->noteol) RRETURN(MATCH_NOMATCH);        if (md->noteol) MRRETURN(MATCH_NOMATCH);
1680        if (!md->endonly)        if (!md->endonly)
1681          {          {
1682          if (eptr != md->end_subject &&          if (eptr != md->end_subject &&
1683              (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1684            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
1685          ecode++;          ecode++;
1686          break;          break;
1687          }          }
# Line 1255  for (;;) Line 1691  for (;;)
1691      /* End of subject assertion (\z) */      /* End of subject assertion (\z) */
1692    
1693      case OP_EOD:      case OP_EOD:
1694      if (eptr < md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr < md->end_subject) MRRETURN(MATCH_NOMATCH);
1695      ecode++;      ecode++;
1696      break;      break;
1697    
# Line 1263  for (;;) Line 1699  for (;;)
1699    
1700      case OP_EODN:      case OP_EODN:
1701      if (eptr != md->end_subject &&      if (eptr != md->end_subject &&
1702          (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1703        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1704      ecode++;      ecode++;
1705      break;      break;
1706    
# Line 1276  for (;;) Line 1712  for (;;)
1712    
1713        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1714        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to        It takes a bit more work in UTF-8 mode. Characters > 255 are assumed to
1715        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1716          partial matching. */
1717    
1718  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1719        if (utf8)        if (utf8)
1720          {          {
1721            /* Get status of previous character */
1722    
1723          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1724            {            {
1725            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1726            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1727              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1728            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1729    #ifdef SUPPORT_UCP
1730              if (md->use_ucp)
1731                {
1732                if (c == '_') prev_is_word = TRUE; else
1733                  {
1734                  int cat = UCD_CATEGORY(c);
1735                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1736                  }
1737                }
1738              else
1739    #endif
1740            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1741            }            }
1742          if (eptr >= md->end_subject) cur_is_word = FALSE; else  
1743            /* Get status of next character */
1744    
1745            if (eptr >= md->end_subject)
1746              {
1747              SCHECK_PARTIAL();
1748              cur_is_word = FALSE;
1749              }
1750            else
1751            {            {
1752            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1753    #ifdef SUPPORT_UCP
1754              if (md->use_ucp)
1755                {
1756                if (c == '_') cur_is_word = TRUE; else
1757                  {
1758                  int cat = UCD_CATEGORY(c);
1759                  cur_is_word = (cat == ucp_L || cat == ucp_N);
1760                  }
1761                }
1762              else
1763    #endif
1764            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1765            }            }
1766          }          }
1767        else        else
1768  #endif  #endif
1769    
1770        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode, but we may still have PCRE_UCP set, and for
1771          consistency with the behaviour of \w we do use it in this case. */
1772    
1773          {          {
1774          prev_is_word = (eptr != md->start_subject) &&          /* Get status of previous character */
1775            ((md->ctypes[eptr[-1]] & ctype_word) != 0);  
1776          cur_is_word = (eptr < md->end_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1777            ((md->ctypes[*eptr] & ctype_word) != 0);            {
1778              if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1779    #ifdef SUPPORT_UCP
1780              if (md->use_ucp)
1781                {
1782                c = eptr[-1];
1783                if (c == '_') prev_is_word = TRUE; else
1784                  {
1785                  int cat = UCD_CATEGORY(c);
1786                  prev_is_word = (cat == ucp_L || cat == ucp_N);
1787                  }
1788                }
1789              else
1790    #endif
1791              prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1792              }
1793    
1794            /* Get status of next character */
1795    
1796            if (eptr >= md->end_subject)
1797              {
1798              SCHECK_PARTIAL();
1799              cur_is_word = FALSE;
1800              }
1801            else
1802    #ifdef SUPPORT_UCP
1803            if (md->use_ucp)
1804              {
1805              c = *eptr;
1806              if (c == '_') cur_is_word = TRUE; else
1807                {
1808                int cat = UCD_CATEGORY(c);
1809                cur_is_word = (cat == ucp_L || cat == ucp_N);
1810                }
1811              }
1812            else
1813    #endif
1814            cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1815          }          }
1816    
1817        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
1818    
1819        if ((*ecode++ == OP_WORD_BOUNDARY)?        if ((*ecode++ == OP_WORD_BOUNDARY)?
1820             cur_is_word == prev_is_word : cur_is_word != prev_is_word)             cur_is_word == prev_is_word : cur_is_word != prev_is_word)
1821          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
1822        }        }
1823      break;      break;
1824    
1825      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1826    
1827      case OP_ANY:      case OP_ANY:
1828      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
1829        /* Fall through */
1830    
1831        case OP_ALLANY:
1832        if (eptr++ >= md->end_subject)
1833        {        {
1834        if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))        SCHECK_PARTIAL();
1835          RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1836        }        }
1837      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (utf8) while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
     if (utf8)  
       while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;  
1838      ecode++;      ecode++;
1839      break;      break;
1840    
# Line 1332  for (;;) Line 1842  for (;;)
1842      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1843    
1844      case OP_ANYBYTE:      case OP_ANYBYTE:
1845      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1846          {
1847          SCHECK_PARTIAL();
1848          MRRETURN(MATCH_NOMATCH);
1849          }
1850      ecode++;      ecode++;
1851      break;      break;
1852    
1853      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1854      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1855          {
1856          SCHECK_PARTIAL();
1857          MRRETURN(MATCH_NOMATCH);
1858          }
1859      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1860      if (      if (
1861  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1345  for (;;) Line 1863  for (;;)
1863  #endif  #endif
1864         (md->ctypes[c] & ctype_digit) != 0         (md->ctypes[c] & ctype_digit) != 0
1865         )         )
1866        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1867      ecode++;      ecode++;
1868      break;      break;
1869    
1870      case OP_DIGIT:      case OP_DIGIT:
1871      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1872          {
1873          SCHECK_PARTIAL();
1874          MRRETURN(MATCH_NOMATCH);
1875          }
1876      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1877      if (      if (
1878  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1358  for (;;) Line 1880  for (;;)
1880  #endif  #endif
1881         (md->ctypes[c] & ctype_digit) == 0         (md->ctypes[c] & ctype_digit) == 0
1882         )         )
1883        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1884      ecode++;      ecode++;
1885      break;      break;
1886    
1887      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1888      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1889          {
1890          SCHECK_PARTIAL();
1891          MRRETURN(MATCH_NOMATCH);
1892          }
1893      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1894      if (      if (
1895  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1371  for (;;) Line 1897  for (;;)
1897  #endif  #endif
1898         (md->ctypes[c] & ctype_space) != 0         (md->ctypes[c] & ctype_space) != 0
1899         )         )
1900        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1901      ecode++;      ecode++;
1902      break;      break;
1903    
1904      case OP_WHITESPACE:      case OP_WHITESPACE:
1905      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1906          {
1907          SCHECK_PARTIAL();
1908          MRRETURN(MATCH_NOMATCH);
1909          }
1910      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1911      if (      if (
1912  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1384  for (;;) Line 1914  for (;;)
1914  #endif  #endif
1915         (md->ctypes[c] & ctype_space) == 0         (md->ctypes[c] & ctype_space) == 0
1916         )         )
1917        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1918      ecode++;      ecode++;
1919      break;      break;
1920    
1921      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1922      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1923          {
1924          SCHECK_PARTIAL();
1925          MRRETURN(MATCH_NOMATCH);
1926          }
1927      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1928      if (      if (
1929  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1397  for (;;) Line 1931  for (;;)
1931  #endif  #endif
1932         (md->ctypes[c] & ctype_word) != 0         (md->ctypes[c] & ctype_word) != 0
1933         )         )
1934        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1935      ecode++;      ecode++;
1936      break;      break;
1937    
1938      case OP_WORDCHAR:      case OP_WORDCHAR:
1939      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1940          {
1941          SCHECK_PARTIAL();
1942          MRRETURN(MATCH_NOMATCH);
1943          }
1944      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1945      if (      if (
1946  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1410  for (;;) Line 1948  for (;;)
1948  #endif  #endif
1949         (md->ctypes[c] & ctype_word) == 0         (md->ctypes[c] & ctype_word) == 0
1950         )         )
1951        RRETURN(MATCH_NOMATCH);        MRRETURN(MATCH_NOMATCH);
1952      ecode++;      ecode++;
1953      break;      break;
1954    
1955  #ifdef SUPPORT_UCP      case OP_ANYNL:
1956      /* Check the next character by Unicode property. We will get here only      if (eptr >= md->end_subject)
1957      if the support is in the binary; otherwise a compile-time error occurs. */        {
1958          SCHECK_PARTIAL();
1959      case OP_PROP:        MRRETURN(MATCH_NOMATCH);
1960      case OP_NOTPROP:        }
     if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);  
1961      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1962        switch(c)
1963        {        {
1964        int chartype, script;        default: MRRETURN(MATCH_NOMATCH);
1965        int category = _pcre_ucp_findprop(c, &chartype, &script);        case 0x000d:
1966          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1967          break;
1968    
1969          case 0x000a:
1970          break;
1971    
1972          case 0x000b:
1973          case 0x000c:
1974          case 0x0085:
1975          case 0x2028:
1976          case 0x2029:
1977          if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
1978          break;
1979          }
1980        ecode++;
1981        break;
1982    
1983        case OP_NOT_HSPACE:
1984        if (eptr >= md->end_subject)
1985          {
1986          SCHECK_PARTIAL();
1987          MRRETURN(MATCH_NOMATCH);
1988          }
1989        GETCHARINCTEST(c, eptr);
1990        switch(c)
1991          {
1992          default: break;
1993          case 0x09:      /* HT */
1994          case 0x20:      /* SPACE */
1995          case 0xa0:      /* NBSP */
1996          case 0x1680:    /* OGHAM SPACE MARK */
1997          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1998          case 0x2000:    /* EN QUAD */
1999          case 0x2001:    /* EM QUAD */
2000          case 0x2002:    /* EN SPACE */
2001          case 0x2003:    /* EM SPACE */
2002          case 0x2004:    /* THREE-PER-EM SPACE */
2003          case 0x2005:    /* FOUR-PER-EM SPACE */
2004          case 0x2006:    /* SIX-PER-EM SPACE */
2005          case 0x2007:    /* FIGURE SPACE */
2006          case 0x2008:    /* PUNCTUATION SPACE */
2007          case 0x2009:    /* THIN SPACE */
2008          case 0x200A:    /* HAIR SPACE */
2009          case 0x202f:    /* NARROW NO-BREAK SPACE */
2010          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2011          case 0x3000:    /* IDEOGRAPHIC SPACE */
2012          MRRETURN(MATCH_NOMATCH);
2013          }
2014        ecode++;
2015        break;
2016    
2017        case OP_HSPACE:
2018        if (eptr >= md->end_subject)
2019          {
2020          SCHECK_PARTIAL();
2021          MRRETURN(MATCH_NOMATCH);
2022          }
2023        GETCHARINCTEST(c, eptr);
2024        switch(c)
2025          {
2026          default: MRRETURN(MATCH_NOMATCH);
2027          case 0x09:      /* HT */
2028          case 0x20:      /* SPACE */
2029          case 0xa0:      /* NBSP */
2030          case 0x1680:    /* OGHAM SPACE MARK */
2031          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
2032          case 0x2000:    /* EN QUAD */
2033          case 0x2001:    /* EM QUAD */
2034          case 0x2002:    /* EN SPACE */
2035          case 0x2003:    /* EM SPACE */
2036          case 0x2004:    /* THREE-PER-EM SPACE */
2037          case 0x2005:    /* FOUR-PER-EM SPACE */
2038          case 0x2006:    /* SIX-PER-EM SPACE */
2039          case 0x2007:    /* FIGURE SPACE */
2040          case 0x2008:    /* PUNCTUATION SPACE */
2041          case 0x2009:    /* THIN SPACE */
2042          case 0x200A:    /* HAIR SPACE */
2043          case 0x202f:    /* NARROW NO-BREAK SPACE */
2044          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
2045          case 0x3000:    /* IDEOGRAPHIC SPACE */
2046          break;
2047          }
2048        ecode++;
2049        break;
2050    
2051        case OP_NOT_VSPACE:
2052        if (eptr >= md->end_subject)
2053          {
2054          SCHECK_PARTIAL();
2055          MRRETURN(MATCH_NOMATCH);
2056          }
2057        GETCHARINCTEST(c, eptr);
2058        switch(c)
2059          {
2060          default: break;
2061          case 0x0a:      /* LF */
2062          case 0x0b:      /* VT */
2063          case 0x0c:      /* FF */
2064          case 0x0d:      /* CR */
2065          case 0x85:      /* NEL */
2066          case 0x2028:    /* LINE SEPARATOR */
2067          case 0x2029:    /* PARAGRAPH SEPARATOR */
2068          MRRETURN(MATCH_NOMATCH);
2069          }
2070        ecode++;
2071        break;
2072    
2073        case OP_VSPACE:
2074        if (eptr >= md->end_subject)
2075          {
2076          SCHECK_PARTIAL();
2077          MRRETURN(MATCH_NOMATCH);
2078          }
2079        GETCHARINCTEST(c, eptr);
2080        switch(c)
2081          {
2082          default: MRRETURN(MATCH_NOMATCH);
2083          case 0x0a:      /* LF */
2084          case 0x0b:      /* VT */
2085          case 0x0c:      /* FF */
2086          case 0x0d:      /* CR */
2087          case 0x85:      /* NEL */
2088          case 0x2028:    /* LINE SEPARATOR */
2089          case 0x2029:    /* PARAGRAPH SEPARATOR */
2090          break;
2091          }
2092        ecode++;
2093        break;
2094    
2095    #ifdef SUPPORT_UCP
2096        /* Check the next character by Unicode property. We will get here only
2097        if the support is in the binary; otherwise a compile-time error occurs. */
2098    
2099        case OP_PROP:
2100        case OP_NOTPROP:
2101        if (eptr >= md->end_subject)
2102          {
2103          SCHECK_PARTIAL();
2104          MRRETURN(MATCH_NOMATCH);
2105          }
2106        GETCHARINCTEST(c, eptr);
2107          {
2108          const ucd_record *prop = GET_UCD(c);
2109    
2110        switch(ecode[1])        switch(ecode[1])
2111          {          {
2112          case PT_ANY:          case PT_ANY:
2113          if (op == OP_NOTPROP) RRETURN(MATCH_NOMATCH);          if (op == OP_NOTPROP) MRRETURN(MATCH_NOMATCH);
2114          break;          break;
2115    
2116          case PT_LAMP:          case PT_LAMP:
2117          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
2118               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
2119               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
2120            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2121           break;          break;
2122    
2123          case PT_GC:          case PT_GC:
2124          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
2125            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2126          break;          break;
2127    
2128          case PT_PC:          case PT_PC:
2129          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
2130            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2131          break;          break;
2132    
2133          case PT_SC:          case PT_SC:
2134          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
2135            RRETURN(MATCH_NOMATCH);            MRRETURN(MATCH_NOMATCH);
2136          break;          break;
2137    
2138            /* These are specials */
2139    
2140            case PT_ALNUM:
2141            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2142                 _pcre_ucp_gentype[prop->chartype] == ucp_N) == (op == OP_NOTPROP))
2143              MRRETURN(MATCH_NOMATCH);
2144            break;
2145    
2146            case PT_SPACE:    /* Perl space */
2147            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2148                 c == CHAR_HT || c == CHAR_NL || c == CHAR_FF || c == CHAR_CR)
2149                   == (op == OP_NOTPROP))
2150              MRRETURN(MATCH_NOMATCH);
2151            break;
2152    
2153            case PT_PXSPACE:  /* POSIX space */
2154            if ((_pcre_ucp_gentype[prop->chartype] == ucp_Z ||
2155                 c == CHAR_HT || c == CHAR_NL || c == CHAR_VT ||
2156                 c == CHAR_FF || c == CHAR_CR)
2157                   == (op == OP_NOTPROP))
2158              MRRETURN(MATCH_NOMATCH);
2159            break;
2160    
2161            case PT_WORD:
2162            if ((_pcre_ucp_gentype[prop->chartype] == ucp_L ||
2163                 _pcre_ucp_gentype[prop->chartype] == ucp_N ||
2164                 c == CHAR_UNDERSCORE) == (op == OP_NOTPROP))
2165              MRRETURN(MATCH_NOMATCH);
2166            break;
2167    
2168            /* This should never occur */
2169    
2170          default:          default:
2171          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
2172          }          }
2173    
2174        ecode += 3;        ecode += 3;
# Line 1467  for (;;) Line 2179  for (;;)
2179      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
2180    
2181      case OP_EXTUNI:      case OP_EXTUNI:
2182      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2183          {
2184          SCHECK_PARTIAL();
2185          MRRETURN(MATCH_NOMATCH);
2186          }
2187      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2188        {        {
2189        int chartype, script;        int category = UCD_CATEGORY(c);
2190        int category = _pcre_ucp_findprop(c, &chartype, &script);        if (category == ucp_M) MRRETURN(MATCH_NOMATCH);
       if (category == ucp_M) RRETURN(MATCH_NOMATCH);  
2191        while (eptr < md->end_subject)        while (eptr < md->end_subject)
2192          {          {
2193          int len = 1;          int len = 1;
# Line 1480  for (;;) Line 2195  for (;;)
2195            {            {
2196            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
2197            }            }
2198          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
2199          if (category != ucp_M) break;          if (category != ucp_M) break;
2200          eptr += len;          eptr += len;
2201          }          }
# Line 1501  for (;;) Line 2216  for (;;)
2216      case OP_REF:      case OP_REF:
2217        {        {
2218        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
2219        ecode += 3;                                 /* Advance past item */        ecode += 3;
2220    
2221          /* If the reference is unset, there are two possibilities:
2222    
2223          (a) In the default, Perl-compatible state, set the length to be longer
2224          than the amount of subject left; this ensures that every attempt at a
2225          match fails. We can't just fail here, because of the possibility of
2226          quantifiers with zero minima.
2227    
2228        /* 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
2229        of subject left; this ensures that every attempt at a match fails. We        so that the back reference matches an empty string.
2230        can't just fail here, because of the possibility of quantifiers with zero  
2231        minima. */        Otherwise, set the length to the length of what was matched by the
2232          referenced subpattern. */
2233        length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
2234          md->end_subject - eptr + 1 :        if (offset >= offset_top || md->offset_vector[offset] < 0)
2235          md->offset_vector[offset+1] - md->offset_vector[offset];          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
2236          else
2237            length = md->offset_vector[offset+1] - md->offset_vector[offset];
2238    
2239        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
2240    
# Line 1539  for (;;) Line 2263  for (;;)
2263          break;          break;
2264    
2265          default:               /* No repeat follows */          default:               /* No repeat follows */
2266          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2267              {
2268              CHECK_PARTIAL();
2269              MRRETURN(MATCH_NOMATCH);
2270              }
2271          eptr += length;          eptr += length;
2272          continue;              /* With the main loop */          continue;              /* With the main loop */
2273          }          }
# Line 1555  for (;;) Line 2283  for (;;)
2283    
2284        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2285          {          {
2286          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
2287              {
2288              CHECK_PARTIAL();
2289              MRRETURN(MATCH_NOMATCH);
2290              }
2291          eptr += length;          eptr += length;
2292          }          }
2293    
# Line 1570  for (;;) Line 2302  for (;;)
2302          {          {
2303          for (fi = min;; fi++)          for (fi = min;; fi++)
2304            {            {
2305            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2306            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2307            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2308              RRETURN(MATCH_NOMATCH);            if (!match_ref(offset, eptr, length, md, ims))
2309                {
2310                CHECK_PARTIAL();
2311                MRRETURN(MATCH_NOMATCH);
2312                }
2313            eptr += length;            eptr += length;
2314            }            }
2315          /* Control never gets here */          /* Control never gets here */
# Line 1586  for (;;) Line 2322  for (;;)
2322          pp = eptr;          pp = eptr;
2323          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2324            {            {
2325            if (!match_ref(offset, eptr, length, md, ims)) break;            if (!match_ref(offset, eptr, length, md, ims))
2326                {
2327                CHECK_PARTIAL();
2328                break;
2329                }
2330            eptr += length;            eptr += length;
2331            }            }
2332          while (eptr >= pp)          while (eptr >= pp)
2333            {            {
2334            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2335            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2336            eptr -= length;            eptr -= length;
2337            }            }
2338          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2339          }          }
2340        }        }
2341      /* Control never gets here */      /* Control never gets here */
2342    
   
   
2343      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2344      used when all the characters in the class have values in the range 0-255,      used when all the characters in the class have values in the range 0-255,
2345      and either the matching is caseful, or the characters are in the range      and either the matching is caseful, or the characters are in the range
# Line 1656  for (;;) Line 2394  for (;;)
2394          {          {
2395          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2396            {            {
2397            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2398                {
2399                SCHECK_PARTIAL();
2400                MRRETURN(MATCH_NOMATCH);
2401                }
2402            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2403            if (c > 255)            if (c > 255)
2404              {              {
2405              if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);              if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2406              }              }
2407            else            else
2408              {              {
2409              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2410              }              }
2411            }            }
2412          }          }
# Line 1674  for (;;) Line 2416  for (;;)
2416          {          {
2417          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2418            {            {
2419            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2420                {
2421                SCHECK_PARTIAL();
2422                MRRETURN(MATCH_NOMATCH);
2423                }
2424            c = *eptr++;            c = *eptr++;
2425            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2426            }            }
2427          }          }
2428    
# Line 1696  for (;;) Line 2442  for (;;)
2442            {            {
2443            for (fi = min;; fi++)            for (fi = min;; fi++)
2444              {              {
2445              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2446              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2447              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2448                if (eptr >= md->end_subject)
2449                  {
2450                  SCHECK_PARTIAL();
2451                  MRRETURN(MATCH_NOMATCH);
2452                  }
2453              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2454              if (c > 255)              if (c > 255)
2455                {                {
2456                if (op == OP_CLASS) RRETURN(MATCH_NOMATCH);                if (op == OP_CLASS) MRRETURN(MATCH_NOMATCH);
2457                }                }
2458              else              else
2459                {                {
2460                if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);                if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2461                }                }
2462              }              }
2463            }            }
# Line 1716  for (;;) Line 2467  for (;;)
2467            {            {
2468            for (fi = min;; fi++)            for (fi = min;; fi++)
2469              {              {
2470              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2471              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2472              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2473                if (eptr >= md->end_subject)
2474                  {
2475                  SCHECK_PARTIAL();
2476                  MRRETURN(MATCH_NOMATCH);
2477                  }
2478              c = *eptr++;              c = *eptr++;
2479              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) MRRETURN(MATCH_NOMATCH);
2480              }              }
2481            }            }
2482          /* Control never gets here */          /* Control never gets here */
# Line 1739  for (;;) Line 2495  for (;;)
2495            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2496              {              {
2497              int len = 1;              int len = 1;
2498              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2499                  {
2500                  SCHECK_PARTIAL();
2501                  break;
2502                  }
2503              GETCHARLEN(c, eptr, len);              GETCHARLEN(c, eptr, len);
2504              if (c > 255)              if (c > 255)
2505                {                {
# Line 1753  for (;;) Line 2513  for (;;)
2513              }              }
2514            for (;;)            for (;;)
2515              {              {
2516              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2517              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2518              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2519              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1765  for (;;) Line 2525  for (;;)
2525            {            {
2526            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2527              {              {
2528              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
2529                  {
2530                  SCHECK_PARTIAL();
2531                  break;
2532                  }
2533              c = *eptr;              c = *eptr;
2534              if ((data[c/8] & (1 << (c&7))) == 0) break;              if ((data[c/8] & (1 << (c&7))) == 0) break;
2535              eptr++;              eptr++;
2536              }              }
2537            while (eptr >= pp)            while (eptr >= pp)
2538              {              {
2539              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2540              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2541              eptr--;              eptr--;
2542              }              }
2543            }            }
2544    
2545          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2546          }          }
2547        }        }
2548      /* Control never gets here */      /* Control never gets here */
2549    
2550    
2551      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2552      in UTF-8 mode, because that's the only time it is compiled. */      when UTF-8 mode mode is supported. Nevertheless, we may not be in UTF-8
2553        mode, because Unicode properties are supported in non-UTF-8 mode. */
2554    
2555  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2556      case OP_XCLASS:      case OP_XCLASS:
# Line 1826  for (;;) Line 2591  for (;;)
2591    
2592        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2593          {          {
2594          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2595          GETCHARINC(c, eptr);            {
2596          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            SCHECK_PARTIAL();
2597              MRRETURN(MATCH_NOMATCH);
2598              }
2599            GETCHARINCTEST(c, eptr);
2600            if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2601          }          }
2602    
2603        /* If max == min we can continue with the main loop without the        /* If max == min we can continue with the main loop without the
# Line 1843  for (;;) Line 2612  for (;;)
2612          {          {
2613          for (fi = min;; fi++)          for (fi = min;; fi++)
2614            {            {
2615            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2616            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2617            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2618            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2619            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);              {
2620                SCHECK_PARTIAL();
2621                MRRETURN(MATCH_NOMATCH);
2622                }
2623              GETCHARINCTEST(c, eptr);
2624              if (!_pcre_xclass(c, data)) MRRETURN(MATCH_NOMATCH);
2625            }            }
2626          /* Control never gets here */          /* Control never gets here */
2627          }          }
# Line 1860  for (;;) Line 2634  for (;;)
2634          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2635            {            {
2636            int len = 1;            int len = 1;
2637            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject)
2638            GETCHARLEN(c, eptr, len);              {
2639                SCHECK_PARTIAL();
2640                break;
2641                }
2642              GETCHARLENTEST(c, eptr, len);
2643            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2644            eptr += len;            eptr += len;
2645            }            }
2646          for(;;)          for(;;)
2647            {            {
2648            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2649            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2650            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2651            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2652            }            }
2653          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2654          }          }
2655    
2656        /* Control never gets here */        /* Control never gets here */
# Line 1888  for (;;) Line 2666  for (;;)
2666        length = 1;        length = 1;
2667        ecode++;        ecode++;
2668        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2669        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2670        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);          {
2671            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2672            MRRETURN(MATCH_NOMATCH);
2673            }
2674          while (length-- > 0) if (*ecode++ != *eptr++) MRRETURN(MATCH_NOMATCH);
2675        }        }
2676      else      else
2677  #endif  #endif
2678    
2679      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2680        {        {
2681        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2682        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);          {
2683            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2684            MRRETURN(MATCH_NOMATCH);
2685            }
2686          if (ecode[1] != *eptr++) MRRETURN(MATCH_NOMATCH);
2687        ecode += 2;        ecode += 2;
2688        }        }
2689      break;      break;
# Line 1912  for (;;) Line 2698  for (;;)
2698        ecode++;        ecode++;
2699        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2700    
2701        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2702            {
2703            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2704            MRRETURN(MATCH_NOMATCH);
2705            }
2706    
2707        /* If the pattern character's value is < 128, we have only one byte, and        /* If the pattern character's value is < 128, we have only one byte, and
2708        can use the fast lookup table. */        can use the fast lookup table. */
2709    
2710        if (fc < 128)        if (fc < 128)
2711          {          {
2712          if (md->lcc[*ecode++] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (md->lcc[*ecode++] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2713          }          }
2714    
2715        /* Otherwise we must pick up the subject character */        /* Otherwise we must pick up the subject character */
2716    
2717        else        else
2718          {          {
2719          int dc;          unsigned int dc;
2720          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2721          ecode += length;          ecode += length;
2722    
# Line 1936  for (;;) Line 2726  for (;;)
2726          if (fc != dc)          if (fc != dc)
2727            {            {
2728  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2729            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2730  #endif  #endif
2731              RRETURN(MATCH_NOMATCH);              MRRETURN(MATCH_NOMATCH);
2732            }            }
2733          }          }
2734        }        }
# Line 1947  for (;;) Line 2737  for (;;)
2737    
2738      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2739        {        {
2740        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2741        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2742            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2743            MRRETURN(MATCH_NOMATCH);
2744            }
2745          if (md->lcc[ecode[1]] != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2746        ecode += 2;        ecode += 2;
2747        }        }
2748      break;      break;
2749    
2750      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2751    
2752      case OP_EXACT:      case OP_EXACT:
2753      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2754      ecode += 3;      ecode += 3;
2755      goto REPEATCHAR;      goto REPEATCHAR;
2756    
2757        case OP_POSUPTO:
2758        possessive = TRUE;
2759        /* Fall through */
2760    
2761      case OP_UPTO:      case OP_UPTO:
2762      case OP_MINUPTO:      case OP_MINUPTO:
2763      min = 0;      min = 0;
# Line 1968  for (;;) Line 2766  for (;;)
2766      ecode += 3;      ecode += 3;
2767      goto REPEATCHAR;      goto REPEATCHAR;
2768    
2769        case OP_POSSTAR:
2770        possessive = TRUE;
2771        min = 0;
2772        max = INT_MAX;
2773        ecode++;
2774        goto REPEATCHAR;
2775    
2776        case OP_POSPLUS:
2777        possessive = TRUE;
2778        min = 1;
2779        max = INT_MAX;
2780        ecode++;
2781        goto REPEATCHAR;
2782    
2783        case OP_POSQUERY:
2784        possessive = TRUE;
2785        min = 0;
2786        max = 1;
2787        ecode++;
2788        goto REPEATCHAR;
2789    
2790      case OP_STAR:      case OP_STAR:
2791      case OP_MINSTAR:      case OP_MINSTAR:
2792      case OP_PLUS:      case OP_PLUS:
# Line 1976  for (;;) Line 2795  for (;;)
2795      case OP_MINQUERY:      case OP_MINQUERY:
2796      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2797      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2798    
2799      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2800      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2801      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2802    
2803      /* Common code for all repeated single-character matches. We can give      /* Common code for all repeated single-character matches. */
     up quickly if there are fewer than the minimum number of characters left in  
     the subject. */  
2804    
2805      REPEATCHAR:      REPEATCHAR:
2806  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1991  for (;;) Line 2809  for (;;)
2809        length = 1;        length = 1;
2810        charptr = ecode;        charptr = ecode;
2811        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2812        ecode += length;        ecode += length;
2813    
2814        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1999  for (;;) Line 2816  for (;;)
2816    
2817        if (length > 1)        if (length > 1)
2818          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2819  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2820          int othercase;          unsigned int othercase;
2821          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2822              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2823            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2824            else oclength = 0;
2825  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2826    
2827          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2828            {            {
2829            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2830            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2831            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2832              else if (oclength > 0 &&
2833                       eptr <= md->end_subject - oclength &&
2834                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2835    #endif  /* SUPPORT_UCP */
2836            else            else
2837              {              {
2838              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2839              eptr += oclength;              MRRETURN(MATCH_NOMATCH);
2840              }              }
2841            }            }
2842    
# Line 2028  for (;;) Line 2846  for (;;)
2846            {            {
2847            for (fi = min;; fi++)            for (fi = min;; fi++)
2848              {              {
2849              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2850              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2851              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) MRRETURN(MATCH_NOMATCH);
2852              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2853              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2854              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2855                else if (oclength > 0 &&
2856                         eptr <= md->end_subject - oclength &&
2857                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2858    #endif  /* SUPPORT_UCP */
2859              else              else
2860                {                {
2861                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2862                eptr += oclength;                MRRETURN(MATCH_NOMATCH);
2863                }                }
2864              }              }
2865            /* Control never gets here */            /* Control never gets here */
2866            }            }
2867          else  
2868            else  /* Maximize */
2869            {            {
2870            pp = eptr;            pp = eptr;
2871            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2872              {              {
2873              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2874              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2875              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2876                else if (oclength > 0 &&
2877                         eptr <= md->end_subject - oclength &&
2878                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2879    #endif  /* SUPPORT_UCP */
2880              else              else
2881                {                {
2882                if (memcmp(eptr, occhars, oclength) != 0) break;                CHECK_PARTIAL();
2883                eptr += oclength;                break;
2884                }                }
2885              }              }
2886            while (eptr >= pp)  
2887             {            if (possessive) continue;
2888             RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
2889             if (rrc != MATCH_NOMATCH) RRETURN(rrc);            for(;;)
2890             eptr -= length;              {
2891             }              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2892            RRETURN(MATCH_NOMATCH);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2893                if (eptr == pp) { MRRETURN(MATCH_NOMATCH); }
2894    #ifdef SUPPORT_UCP
2895                eptr--;
2896                BACKCHAR(eptr);
2897    #else   /* without SUPPORT_UCP */
2898                eptr -= length;
2899    #endif  /* SUPPORT_UCP */
2900                }
2901            }            }
2902          /* Control never gets here */          /* Control never gets here */
2903          }          }
# Line 2075  for (;;) Line 2910  for (;;)
2910  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2911    
2912      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2913        {  
2914        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2915    
2916      /* The value of fc at this point is always less than 256, though we may or      /* The value of fc at this point is always less than 256, though we may or
2917      may not be in UTF-8 mode. The code is duplicated for the caseless and      may not be in UTF-8 mode. The code is duplicated for the caseless and
# Line 2096  for (;;) Line 2929  for (;;)
2929        {        {
2930        fc = md->lcc[fc];        fc = md->lcc[fc];
2931        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2932          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          {
2933            if (eptr >= md->end_subject)
2934              {
2935              SCHECK_PARTIAL();
2936              MRRETURN(MATCH_NOMATCH);
2937              }
2938            if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2939            }
2940        if (min == max) continue;        if (min == max) continue;
2941        if (minimize)        if (minimize)
2942          {          {
2943          for (fi = min;; fi++)          for (fi = min;; fi++)
2944            {            {
2945            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2946            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2947            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) MRRETURN(MATCH_NOMATCH);
2948                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2949              RRETURN(MATCH_NOMATCH);              {
2950                SCHECK_PARTIAL();
2951                MRRETURN(MATCH_NOMATCH);
2952                }
2953              if (fc != md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
2954            }            }
2955          /* Control never gets here */          /* Control never gets here */
2956          }          }
2957        else        else  /* Maximize */
2958          {          {
2959          pp = eptr;          pp = eptr;
2960          for (i = min; i < max; i++)          for (i = min; i < max; i++)
2961            {            {
2962            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject)
2963                {
2964                SCHECK_PARTIAL();
2965                break;
2966                }
2967              if (fc != md->lcc[*eptr]) break;
2968            eptr++;            eptr++;
2969            }            }
2970    
2971            if (possessive) continue;
2972    
2973          while (eptr >= pp)          while (eptr >= pp)
2974            {            {
2975            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2976            eptr--;            eptr--;
2977            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2978            }            }
2979          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
2980          }          }
2981        /* Control never gets here */        /* Control never gets here */
2982        }        }
# Line 2133  for (;;) Line 2985  for (;;)
2985    
2986      else      else
2987        {        {
2988        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2989            {
2990            if (eptr >= md->end_subject)
2991              {
2992              SCHECK_PARTIAL();
2993              MRRETURN(MATCH_NOMATCH);
2994              }
2995            if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
2996            }
2997    
2998        if (min == max) continue;        if (min == max) continue;
2999    
3000        if (minimize)        if (minimize)
3001          {          {
3002          for (fi = min;; fi++)          for (fi = min;; fi++)
3003            {            {
3004            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
3005            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3006            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) MRRETURN(MATCH_NOMATCH);
3007              RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3008                {
3009                SCHECK_PARTIAL();
3010                MRRETURN(MATCH_NOMATCH);
3011                }
3012              if (fc != *eptr++) MRRETURN(MATCH_NOMATCH);
3013            }            }
3014          /* Control never gets here */          /* Control never gets here */
3015          }          }
3016        else        else  /* Maximize */
3017          {          {
3018          pp = eptr;          pp = eptr;
3019          for (i = min; i < max; i++)          for (i = min; i < max; i++)
3020            {            {
3021            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject)
3022                {
3023                SCHECK_PARTIAL();
3024                break;
3025                }
3026              if (fc != *eptr) break;
3027            eptr++;            eptr++;
3028            }            }
3029            if (possessive) continue;
3030    
3031          while (eptr >= pp)          while (eptr >= pp)
3032            {            {
3033            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
3034            eptr--;            eptr--;
3035            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3036            }            }
3037          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3038          }          }
3039        }        }
3040      /* Control never gets here */      /* Control never gets here */
# Line 2169  for (;;) Line 3043  for (;;)
3043      checking can be multibyte. */      checking can be multibyte. */
3044    
3045      case OP_NOT:      case OP_NOT:
3046      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
3047          {
3048          SCHECK_PARTIAL();
3049          MRRETURN(MATCH_NOMATCH);
3050          }
3051      ecode++;      ecode++;
3052      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
3053      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2178  for (;;) Line 3056  for (;;)
3056        if (c < 256)        if (c < 256)
3057  #endif  #endif
3058        c = md->lcc[c];        c = md->lcc[c];
3059        if (md->lcc[*ecode++] == c) RRETURN(MATCH_NOMATCH);        if (md->lcc[*ecode++] == c) MRRETURN(MATCH_NOMATCH);
3060        }        }
3061      else      else
3062        {        {
3063        if (*ecode++ == c) RRETURN(MATCH_NOMATCH);        if (*ecode++ == c) MRRETURN(MATCH_NOMATCH);
3064        }        }
3065      break;      break;
3066    
# Line 2206  for (;;) Line 3084  for (;;)
3084      ecode += 3;      ecode += 3;
3085      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
3086    
3087        case OP_NOTPOSSTAR:
3088        possessive = TRUE;
3089        min = 0;
3090        max = INT_MAX;
3091        ecode++;
3092        goto REPEATNOTCHAR;
3093    
3094        case OP_NOTPOSPLUS:
3095        possessive = TRUE;
3096        min = 1;
3097        max = INT_MAX;
3098        ecode++;
3099        goto REPEATNOTCHAR;
3100    
3101        case OP_NOTPOSQUERY:
3102        possessive = TRUE;
3103        min = 0;
3104        max = 1;
3105        ecode++;
3106        goto REPEATNOTCHAR;
3107    
3108        case OP_NOTPOSUPTO:
3109        possessive = TRUE;
3110        min = 0;
3111        max = GET2(ecode, 1);
3112        ecode += 3;
3113        goto REPEATNOTCHAR;
3114    
3115      case OP_NOTSTAR:      case OP_NOTSTAR:
3116      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
3117      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2218  for (;;) Line 3124  for (;;)
3124      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
3125      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
3126    
3127      /* Common code for all repeated single-byte matches. We can give up quickly      /* Common code for all repeated single-byte matches. */
     if there are fewer than the minimum number of bytes left in the  
     subject. */  
3128    
3129      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3130      fc = *ecode++;      fc = *ecode++;
3131    
3132      /* The code is duplicated for the caseless and caseful cases, for speed,      /* The code is duplicated for the caseless and caseful cases, for speed,
# Line 2245  for (;;) Line 3148  for (;;)
3148        /* UTF-8 mode */        /* UTF-8 mode */
3149        if (utf8)        if (utf8)
3150          {          {
3151          register int d;          register unsigned int d;
3152          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3153            {            {
3154              if (eptr >= md->end_subject)
3155                {
3156                SCHECK_PARTIAL();
3157                MRRETURN(MATCH_NOMATCH);
3158                }
3159            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3160            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
3161            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3162            }            }
3163          }          }
3164        else        else
# Line 2259  for (;;) Line 3167  for (;;)
3167        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3168          {          {
3169          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3170            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            {
3171              if (eptr >= md->end_subject)
3172                {
3173                SCHECK_PARTIAL();
3174                MRRETURN(MATCH_NOMATCH);
3175                }
3176              if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3177              }
3178          }          }
3179    
3180        if (min == max) continue;        if (min == max) continue;
# Line 2270  for (;;) Line 3185  for (;;)
3185          /* UTF-8 mode */          /* UTF-8 mode */
3186          if (utf8)          if (utf8)
3187            {            {
3188            register int d;            register unsigned int d;
3189            for (fi = min;; fi++)            for (fi = min;; fi++)
3190              {              {
3191              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
3192              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3193                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3194                if (eptr >= md->end_subject)
3195                  {
3196                  SCHECK_PARTIAL();
3197                  MRRETURN(MATCH_NOMATCH);
3198                  }
3199              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3200              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3201              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3202              }              }
3203            }            }
3204          else          else
# Line 2287  for (;;) Line 3207  for (;;)
3207            {            {
3208            for (fi = min;; fi++)            for (fi = min;; fi++)
3209              {              {
3210              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
3211              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3212              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3213                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3214                  {
3215                  SCHECK_PARTIAL();
3216                  MRRETURN(MATCH_NOMATCH);
3217                  }
3218                if (fc == md->lcc[*eptr++]) MRRETURN(MATCH_NOMATCH);
3219              }              }
3220            }            }
3221          /* Control never gets here */          /* Control never gets here */
# Line 2306  for (;;) Line 3231  for (;;)
3231          /* UTF-8 mode */          /* UTF-8 mode */
3232          if (utf8)          if (utf8)
3233            {            {
3234            register int d;            register unsigned int d;
3235            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3236              {              {
3237              int len = 1;              int len = 1;
3238              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3239                  {
3240                  SCHECK_PARTIAL();
3241                  break;
3242                  }
3243              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3244              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
3245              if (fc == d) break;              if (fc == d) break;
3246              eptr += len;              eptr += len;
3247              }              }
3248            for(;;)          if (possessive) continue;
3249            for(;;)
3250              {              {
3251              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
3252              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3253              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3254              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2330  for (;;) Line 3260  for (;;)
3260            {            {
3261            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3262              {              {
3263              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject)
3264                  {
3265                  SCHECK_PARTIAL();
3266                  break;
3267                  }
3268                if (fc == md->lcc[*eptr]) break;
3269              eptr++;              eptr++;
3270              }              }
3271              if (possessive) continue;
3272            while (eptr >= pp)            while (eptr >= pp)
3273              {              {
3274              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
3275              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3276              eptr--;              eptr--;
3277              }              }
3278            }            }
3279    
3280          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3281          }          }
3282        /* Control never gets here */        /* Control never gets here */
3283        }        }
# Line 2354  for (;;) Line 3290  for (;;)
3290        /* UTF-8 mode */        /* UTF-8 mode */
3291        if (utf8)        if (utf8)
3292          {          {
3293          register int d;          register unsigned int d;
3294          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3295            {            {
3296              if (eptr >= md->end_subject)
3297                {
3298                SCHECK_PARTIAL();
3299                MRRETURN(MATCH_NOMATCH);
3300                }
3301            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
3302            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) MRRETURN(MATCH_NOMATCH);
3303            }            }
3304          }          }
3305        else        else
# Line 2366  for (;;) Line 3307  for (;;)
3307        /* Not UTF-8 mode */        /* Not UTF-8 mode */
3308          {          {
3309          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3310            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            {
3311              if (eptr >= md->end_subject)
3312                {
3313                SCHECK_PARTIAL();
3314                MRRETURN(MATCH_NOMATCH);
3315                }
3316              if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3317              }
3318          }          }
3319    
3320        if (min == max) continue;        if (min == max) continue;
# Line 2377  for (;;) Line 3325  for (;;)
3325          /* UTF-8 mode */          /* UTF-8 mode */
3326          if (utf8)          if (utf8)
3327            {            {
3328            register int d;            register unsigned int d;
3329            for (fi = min;; fi++)            for (fi = min;; fi++)
3330              {              {
3331              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
3332              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3333                if (fi >= max) MRRETURN(MATCH_NOMATCH);
3334                if (eptr >= md->end_subject)
3335                  {
3336                  SCHECK_PARTIAL();
3337                  MRRETURN(MATCH_NOMATCH);
3338                  }
3339              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
3340              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) MRRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
3341              }              }
3342            }            }
3343          else          else
# Line 2393  for (;;) Line 3346  for (;;)
3346            {            {
3347            for (fi = min;; fi++)            for (fi = min;; fi++)
3348              {              {
3349              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3350              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3351              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) MRRETURN(MATCH_NOMATCH);
3352                RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3353                  {
3354                  SCHECK_PARTIAL();
3355                  MRRETURN(MATCH_NOMATCH);
3356                  }
3357                if (fc == *eptr++) MRRETURN(MATCH_NOMATCH);
3358              }              }
3359            }            }
3360          /* Control never gets here */          /* Control never gets here */
# Line 2412  for (;;) Line 3370  for (;;)
3370          /* UTF-8 mode */          /* UTF-8 mode */
3371          if (utf8)          if (utf8)
3372            {            {
3373            register int d;            register unsigned int d;
3374            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3375              {              {
3376              int len = 1;              int len = 1;
3377              if (eptr >= md->end_subject) break;              if (eptr >= md->end_subject)
3378                  {
3379                  SCHECK_PARTIAL();
3380                  break;
3381                  }
3382              GETCHARLEN(d, eptr, len);              GETCHARLEN(d, eptr, len);
3383              if (fc == d) break;              if (fc == d) break;
3384              eptr += len;              eptr += len;
3385              }              }
3386              if (possessive) continue;
3387            for(;;)            for(;;)
3388              {              {
3389              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3390              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3391              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3392              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2435  for (;;) Line 3398  for (;;)
3398            {            {
3399            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3400              {              {
3401              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject)
3402                  {
3403                  SCHECK_PARTIAL();
3404                  break;
3405                  }
3406                if (fc == *eptr) break;
3407              eptr++;              eptr++;
3408              }              }
3409              if (possessive) continue;
3410            while (eptr >= pp)            while (eptr >= pp)
3411              {              {
3412              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3413              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3414              eptr--;              eptr--;
3415              }              }
3416            }            }
3417    
3418          RRETURN(MATCH_NOMATCH);          MRRETURN(MATCH_NOMATCH);
3419          }          }
3420        }        }
3421      /* Control never gets here */      /* Control never gets here */
# Line 2469  for (;;) Line 3438  for (;;)
3438      ecode += 3;      ecode += 3;
3439      goto REPEATTYPE;      goto REPEATTYPE;
3440    
3441        case OP_TYPEPOSSTAR:
3442        possessive = TRUE;
3443        min = 0;
3444        max = INT_MAX;
3445        ecode++;
3446        goto REPEATTYPE;
3447    
3448        case OP_TYPEPOSPLUS:
3449        possessive = TRUE;
3450        min = 1;
3451        max = INT_MAX;
3452        ecode++;
3453        goto REPEATTYPE;
3454    
3455        case OP_TYPEPOSQUERY:
3456        possessive = TRUE;
3457        min = 0;
3458        max = 1;
3459        ecode++;
3460        goto REPEATTYPE;
3461    
3462        case OP_TYPEPOSUPTO:
3463        possessive = TRUE;
3464        min = 0;
3465        max = GET2(ecode, 1);
3466        ecode += 3;
3467        goto REPEATTYPE;
3468    
3469      case OP_TYPESTAR:      case OP_TYPESTAR:
3470      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3471      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2500  for (;;) Line 3497  for (;;)
3497    
3498      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3499      code for maximizing the speed, and do the type test once at the start      code for maximizing the speed, and do the type test once at the start
3500      (i.e. keep it out of the loop). Also we can test that there are at least      (i.e. keep it out of the loop). Separate the UTF-8 code completely as that
     the minimum number of bytes before we start. This isn't as effective in  
     UTF-8 mode, but it does no harm. Separate the UTF-8 code completely as that  
3501      is tidier. Also separate the UCP code, which can be the same for both UTF-8      is tidier. Also separate the UCP code, which can be the same for both UTF-8
3502      and single-bytes. */      and single-bytes. */
3503    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3504      if (min > 0)      if (min > 0)
3505        {        {
3506  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2515  for (;;) Line 3509  for (;;)
3509          switch(prop_type)          switch(prop_type)
3510            {            {
3511            case PT_ANY:            case PT_ANY:
3512            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) MRRETURN(MATCH_NOMATCH);
3513            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3514              {              {
3515              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3516              GETCHARINC(c, eptr);                {
3517                  SCHECK_PARTIAL();
3518                  MRRETURN(MATCH_NOMATCH);
3519                  }
3520                GETCHARINCTEST(c, eptr);
3521              }              }
3522            break;            break;
3523    
3524            case PT_LAMP:            case PT_LAMP:
3525            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3526              {              {
3527              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3528              GETCHARINC(c, eptr);                {
3529              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3530                  MRRETURN(MATCH_NOMATCH);
3531                  }
3532                GETCHARINCTEST(c, eptr);
3533                prop_chartype = UCD_CHARTYPE(c);
3534              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3535                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3536                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3537                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3538              }              }
3539            break;            break;
3540    
3541            case PT_GC:            case PT_GC:
3542            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3543              {              {
3544              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3545              GETCHARINC(c, eptr);                {
3546              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3547                  MRRETURN(MATCH_NOMATCH);
3548                  }
3549                GETCHARINCTEST(c, eptr);
3550                prop_category = UCD_CATEGORY(c);
3551              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3552                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3553              }              }
3554            break;            break;
3555    
3556            case PT_PC:            case PT_PC:
3557            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3558              {              {
3559              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3560              GETCHARINC(c, eptr);                {
3561              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3562                  MRRETURN(MATCH_NOMATCH);
3563                  }
3564                GETCHARINCTEST(c, eptr);
3565                prop_chartype = UCD_CHARTYPE(c);
3566              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3567                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3568              }              }
3569            break;            break;
3570    
3571            case PT_SC:            case PT_SC:
3572            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3573              {              {
3574              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3575              GETCHARINC(c, eptr);                {
3576              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3577                  MRRETURN(MATCH_NOMATCH);
3578                  }
3579                GETCHARINCTEST(c, eptr);
3580                prop_script = UCD_SCRIPT(c);
3581              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3582                RRETURN(MATCH_NOMATCH);                MRRETURN(MATCH_NOMATCH);
3583              }              }
3584            break;            break;
3585    
3586            default:            case PT_ALNUM:
3587            RRETURN(PCRE_ERROR_INTERNAL);            for (i = 1; i <= min; i++)
3588                {
3589                if (eptr >= md->end_subject)
3590                  {
3591                  SCHECK_PARTIAL();
3592                  MRRETURN(MATCH_NOMATCH);
3593                  }
3594                GETCHARINCTEST(c, eptr);
3595                prop_category = UCD_CATEGORY(c);
3596                if ((prop_category == ucp_L || prop_category == ucp_N)
3597                       == prop_fail_result)
3598                  MRRETURN(MATCH_NOMATCH);
3599                }
3600            break;            break;
3601    
3602              case PT_SPACE:    /* Perl space */
3603              for (i = 1; i <= min; i++)
3604                {
3605                if (eptr >= md->end_subject)
3606                  {
3607                  SCHECK_PARTIAL();
3608                  MRRETURN(MATCH_NOMATCH);
3609                  }
3610                GETCHARINCTEST(c, eptr);
3611                prop_category = UCD_CATEGORY(c);
3612                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3613                     c == CHAR_FF || c == CHAR_CR)
3614                       == prop_fail_result)
3615                  MRRETURN(MATCH_NOMATCH);
3616                }
3617              break;
3618    
3619              case PT_PXSPACE:  /* POSIX space */
3620              for (i = 1; i <= min; i++)
3621                {
3622                if (eptr >= md->end_subject)
3623                  {
3624                  SCHECK_PARTIAL();
3625                  MRRETURN(MATCH_NOMATCH);
3626                  }
3627                GETCHARINCTEST(c, eptr);
3628                prop_category = UCD_CATEGORY(c);
3629                if ((prop_category == ucp_Z || c == CHAR_HT || c == CHAR_NL ||
3630                     c == CHAR_VT || c == CHAR_FF || c == CHAR_CR)
3631                       == prop_fail_result)
3632                  MRRETURN(MATCH_NOMATCH);
3633                }
3634              break;
3635    
3636              case PT_WORD:
3637              for (i = 1; i <= min; i++)
3638                {
3639                if (eptr >= md->end_subject)
3640                  {
3641                  SCHECK_PARTIAL();
3642                  MRRETURN(MATCH_NOMATCH);
3643                  }
3644                GETCHARINCTEST(c, eptr);
3645                prop_category = UCD_CATEGORY(c);
3646                if ((prop_category == ucp_L || prop_category == ucp_N ||
3647                     c == CHAR_UNDERSCORE)
3648                       == prop_fail_result)
3649                  MRRETURN(MATCH_NOMATCH);
3650                }
3651              break;
3652    
3653              /* This should not occur */
3654    
3655              default:
3656              RRETURN(PCRE_ERROR_INTERNAL);
3657            }            }
3658          }          }
3659    
# Line 2582  for (;;) Line 3664  for (;;)
3664          {          {
3665          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3666            {            {
3667              if (eptr >= md->end_subject)
3668                {
3669                SCHECK_PARTIAL();
3670                MRRETURN(MATCH_NOMATCH);
3671                }
3672            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3673            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3674            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) MRRETURN(MATCH_NOMATCH);
3675            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3676              {              {
3677              int len = 1;              int len = 1;
3678              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3679                {                else { GETCHARLEN(c, eptr, len); }
3680                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3681              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3682              eptr += len;              eptr += len;
3683              }              }
# Line 2610  for (;;) Line 3695  for (;;)
3695          case OP_ANY:          case OP_ANY:
3696          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3697            {            {
3698            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3699                 ((ims & PCRE_DOTALL) == 0 &&              {
3700                   eptr <= md->end_subject - md->nllen &&              SCHECK_PARTIAL();
3701                   IS_NEWLINE(eptr)))              MRRETURN(MATCH_NOMATCH);
3702              RRETURN(MATCH_NOMATCH);              }
3703              if (IS_NEWLINE(eptr)) MRRETURN(MATCH_NOMATCH);
3704              eptr++;
3705              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3706              }
3707            break;
3708    
3709            case OP_ALLANY:
3710            for (i = 1; i <= min; i++)
3711              {
3712              if (eptr >= md->end_subject)
3713                {
3714                SCHECK_PARTIAL();
3715                MRRETURN(MATCH_NOMATCH);
3716                }
3717            eptr++;            eptr++;
3718            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3719            }            }
3720          break;          break;
3721    
3722          case OP_ANYBYTE:          case OP_ANYBYTE:
3723            if (eptr > md->end_subject - min) MRRETURN(MATCH_NOMATCH);
3724          eptr += min;          eptr += min;
3725          break;          break;
3726    
3727            case OP_ANYNL:
3728            for (i = 1; i <= min; i++)
3729              {
3730              if (eptr >= md->end_subject)
3731                {
3732                SCHECK_PARTIAL();
3733                MRRETURN(MATCH_NOMATCH);
3734                }
3735              GETCHARINC(c, eptr);
3736              switch(c)
3737                {
3738                default: MRRETURN(MATCH_NOMATCH);
3739                case 0x000d:
3740                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3741                break;
3742    
3743                case 0x000a:
3744                break;
3745    
3746                case 0x000b:
3747                case 0x000c:
3748                case 0x0085:
3749                case 0x2028:
3750                case 0x2029:
3751                if (md->bsr_anycrlf) MRRETURN(MATCH_NOMATCH);
3752                break;
3753                }
3754              }
3755            break;
3756    
3757            case OP_NOT_HSPACE:
3758            for (i = 1; i <= min; i++)
3759              {
3760              if (eptr >= md->end_subject)
3761                {
3762                SCHECK_PARTIAL();
3763                MRRETURN(MATCH_NOMATCH);
3764                }
3765              GETCHARINC(c, eptr);
3766              switch(c)
3767                {
3768                default: break;
3769                case 0x09:      /* HT */
3770                case 0x20:      /* SPACE */
3771                case 0xa0:      /* NBSP */
3772                case 0x1680:    /* OGHAM SPACE MARK */
3773                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3774                case 0x2000:    /* EN QUAD */
3775                case 0x2001:    /* EM QUAD */
3776                case 0x2002:    /* EN SPACE */
3777                case 0x2003:    /* EM SPACE */
3778                case 0x2004:    /* THREE-PER-EM SPACE */
3779                case 0x2005:    /* FOUR-PER-EM SPACE */
3780                case 0x2006:    /* SIX-PER-EM SPACE */
3781                case 0x2007:    /* FIGURE SPACE */
3782                case 0x2008:    /* PUNCTUATION SPACE */
3783                case 0x2009:    /* THIN SPACE */
3784                case 0x200A:    /* HAIR SPACE */
3785                case 0x202f:    /* NARROW NO-BREAK SPACE */
3786                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3787                case 0x3000:    /* IDEOGRAPHIC SPACE */
3788                MRRETURN(MATCH_NOMATCH);
3789                }
3790              }
3791            break;
3792    
3793            case OP_HSPACE:
3794            for (i = 1; i <= min; i++)
3795              {
3796              if (eptr >= md->end_subject)
3797                {
3798                SCHECK_PARTIAL();
3799                MRRETURN(MATCH_NOMATCH);
3800                }
3801              GETCHARINC(c, eptr);
3802              switch(c)
3803                {
3804                default: MRRETURN(MATCH_NOMATCH);
3805                case 0x09:      /* HT */
3806                case 0x20:      /* SPACE */
3807                case 0xa0:      /* NBSP */
3808                case 0x1680:    /* OGHAM SPACE MARK */
3809                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3810                case 0x2000:    /* EN QUAD */
3811                case 0x2001:    /* EM QUAD */
3812                case 0x2002:    /* EN SPACE */
3813                case 0x2003:    /* EM SPACE */
3814                case 0x2004:    /* THREE-PER-EM SPACE */
3815                case 0x2005:    /* FOUR-PER-EM SPACE */
3816                case 0x2006:    /* SIX-PER-EM SPACE */
3817                case 0x2007:    /* FIGURE SPACE */
3818                case 0x2008:    /* PUNCTUATION SPACE */
3819                case 0x2009:    /* THIN SPACE */
3820                case 0x200A:    /* HAIR SPACE */
3821                case 0x202f:    /* NARROW NO-BREAK SPACE */
3822                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3823                case 0x3000:    /* IDEOGRAPHIC SPACE */
3824                break;
3825                }
3826              }
3827            break;
3828    
3829            case OP_NOT_VSPACE:
3830            for (i = 1; i <= min; i++)
3831              {
3832              if (eptr >= md->end_subject)
3833                {
3834                SCHECK_PARTIAL();
3835                MRRETURN(MATCH_NOMATCH);
3836                }
3837              GETCHARINC(c, eptr);
3838              switch(c)
3839                {
3840                default: break;
3841                case 0x0a:      /* LF */
3842                case 0x0b:      /* VT */
3843                case 0x0c:      /* FF */
3844                case 0x0d:      /* CR */
3845                case 0x85:      /* NEL */
3846                case 0x2028:    /* LINE SEPARATOR */
3847                case 0x2029:    /* PARAGRAPH SEPARATOR */
3848                MRRETURN(MATCH_NOMATCH);
3849                }
3850              }
3851            break;
3852    
3853            case OP_VSPACE:
3854            for (i = 1; i <= min; i++)
3855              {
3856              if (eptr >= md->end_subject)
3857                {
3858                SCHECK_PARTIAL();
3859                MRRETURN(MATCH_NOMATCH);
3860                }
3861              GETCHARINC(c, eptr);
3862              switch(c)
3863                {
3864                default: MRRETURN(MATCH_NOMATCH);
3865                case 0x0a:      /* LF */