/[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 455 by ph10, Sat Sep 26 19:12:32 2009 UTC
# Line 6  Line 6 
6  and semantics are as close as possible to those of the Perl 5 language.  and semantics are as close as possible to those of the Perl 5 language.
7    
8                         Written by Philip Hazel                         Written by Philip Hazel
9             Copyright (c) 1997-2006 University of Cambridge             Copyright (c) 1997-2009 University of Cambridge
10    
11  -----------------------------------------------------------------------------  -----------------------------------------------------------------------------
12  Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
# Line 42  POSSIBILITY OF SUCH DAMAGE. Line 42  POSSIBILITY OF SUCH DAMAGE.
42  pattern matching using an NFA algorithm, trying to mimic Perl as closely as  pattern matching using an NFA algorithm, trying to mimic Perl as closely as
43  possible. There are also some static supporting functions. */  possible. There are also some static supporting functions. */
44    
45  #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_COMMIT       (-999)
75    #define MATCH_PRUNE        (-998)
76    #define MATCH_SKIP         (-997)
77    #define MATCH_THEN         (-996)
78    
79  /* Maximum number of ints of offset to save on the stack for recursive calls.  /* Maximum number of ints of offset to save on the stack for recursive calls.
80  If the offset vector is bigger, malloc is used. This should be a multiple of 3,  If the offset vector is bigger, malloc is used. This should be a multiple of 3,
81  because the offset vector is always a multiple of 3 long. */  because the offset vector is always a multiple of 3 long. */
# Line 101  Returns:     nothing Line 109  Returns:     nothing
109  static void  static void
110  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)  pchars(const uschar *p, int length, BOOL is_subject, match_data *md)
111  {  {
112  int c;  unsigned int c;
113  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;  if (is_subject && length > md->end_subject - p) length = md->end_subject - p;
114  while (length-- > 0)  while (length-- > 0)
115    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);    if (isprint(c = *(p++))) printf("%c", c); else printf("\\x%02x", c);
# Line 150  printf("\n"); Line 158  printf("\n");
158    
159  if (length > md->end_subject - eptr) return FALSE;  if (length > md->end_subject - eptr) return FALSE;
160    
161  /* Separate the caselesss case for speed */  /* Separate the caseless case for speed. In UTF-8 mode we can only do this
162    properly if Unicode properties are supported. Otherwise, we can check only
163    ASCII characters. */
164    
165  if ((ims & PCRE_CASELESS) != 0)  if ((ims & PCRE_CASELESS) != 0)
166    {    {
167    #ifdef SUPPORT_UTF8
168    #ifdef SUPPORT_UCP
169      if (md->utf8)
170        {
171        USPTR endptr = eptr + length;
172        while (eptr < endptr)
173          {
174          int c, d;
175          GETCHARINC(c, eptr);
176          GETCHARINC(d, p);
177          if (c != d && c != UCD_OTHERCASE(d)) return FALSE;
178          }
179        }
180      else
181    #endif
182    #endif
183    
184      /* The same code works when not in UTF-8 mode and in UTF-8 mode when there
185      is no UCP support. */
186    
187    while (length-- > 0)    while (length-- > 0)
188      if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE;      { if (md->lcc[*p++] != md->lcc[*eptr++]) return FALSE; }
189    }    }
190    
191    /* In the caseful case, we can just compare the bytes, whether or not we
192    are in UTF-8 mode. */
193    
194  else  else
195    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }    { while (length-- > 0) if (*p++ != *eptr++) return FALSE; }
196    
# Line 186  calls by keeping local variables that ne Line 220  calls by keeping local variables that ne
220  obtained from malloc() instead instead of on the stack. Macros are used to  obtained from malloc() instead instead of on the stack. Macros are used to
221  achieve this so that the actual code doesn't look very different to what it  achieve this so that the actual code doesn't look very different to what it
222  always used to.  always used to.
223    
224    The original heap-recursive code used longjmp(). However, it seems that this
225    can be very slow on some operating systems. Following a suggestion from Stan
226    Switzer, the use of longjmp() has been abolished, at the cost of having to
227    provide a unique number for each call to RMATCH. There is no way of generating
228    a sequence of numbers at compile time in C. I have given them names, to make
229    them stand out more clearly.
230    
231    Crude tests on x86 Linux show a small speedup of around 5-8%. However, on
232    FreeBSD, avoiding longjmp() more than halves the time taken to run the standard
233    tests. Furthermore, not using longjmp() means that local dynamic variables
234    don't have indeterminate values; this has meant that the frame size can be
235    reduced because the result can be "passed back" by straight setting of the
236    variable instead of being passed in the frame.
237  ****************************************************************************  ****************************************************************************
238  ***************************************************************************/  ***************************************************************************/
239    
240    /* Numbers for RMATCH calls. When this list is changed, the code at HEAP_RETURN
241    below must be updated in sync.  */
242    
243    enum { RM1=1, RM2,  RM3,  RM4,  RM5,  RM6,  RM7,  RM8,  RM9,  RM10,
244           RM11,  RM12, RM13, RM14, RM15, RM16, RM17, RM18, RM19, RM20,
245           RM21,  RM22, RM23, RM24, RM25, RM26, RM27, RM28, RM29, RM30,
246           RM31,  RM32, RM33, RM34, RM35, RM36, RM37, RM38, RM39, RM40,
247           RM41,  RM42, RM43, RM44, RM45, RM46, RM47, RM48, RM49, RM50,
248           RM51,  RM52, RM53, RM54 };
249    
250  /* These versions of the macros use the stack, as normal. There are debugging  /* These versions of the macros use the stack, as normal. There are debugging
251  versions and production versions. */  versions and production versions. Note that the "rw" argument of RMATCH isn't
252    actuall used in this definition. */
253    
254  #ifndef NO_RECURSE  #ifndef NO_RECURSE
255  #define REGISTER register  #define REGISTER register
256    
257  #ifdef DEBUG  #ifdef DEBUG
258  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
259    { \    { \
260    printf("match() called in line %d\n", __LINE__); \    printf("match() called in line %d\n", __LINE__); \
261    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1); \    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1); \
262    printf("to line %d\n", __LINE__); \    printf("to line %d\n", __LINE__); \
263    }    }
264  #define RRETURN(ra) \  #define RRETURN(ra) \
# Line 208  versions and production versions. */ Line 267  versions and production versions. */
267    return ra; \    return ra; \
268    }    }
269  #else  #else
270  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg) \  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw) \
271    rx = match(ra,rb,rc,rd,re,rf,rg,rdepth+1)    rrc = match(ra,rb,mstart,rc,rd,re,rf,rg,rdepth+1)
272  #define RRETURN(ra) return ra  #define RRETURN(ra) return ra
273  #endif  #endif
274    
275  #else  #else
276    
277    
278  /* These versions of the macros manage a private stack on the heap. Note  /* These versions of the macros manage a private stack on the heap. Note that
279  that the rd argument of RMATCH isn't actually used. It's the md argument of  the "rd" argument of RMATCH isn't actually used in this definition. It's the md
280  match(), which never changes. */  argument of match(), which never changes. */
281    
282  #define REGISTER  #define REGISTER
283    
284  #define RMATCH(rx,ra,rb,rc,rd,re,rf,rg)\  #define RMATCH(ra,rb,rc,rd,re,rf,rg,rw)\
285    {\    {\
286    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\    heapframe *newframe = (pcre_stack_malloc)(sizeof(heapframe));\
287    if (setjmp(frame->Xwhere) == 0)\    frame->Xwhere = rw; \
288      {\    newframe->Xeptr = ra;\
289      newframe->Xeptr = ra;\    newframe->Xecode = rb;\
290      newframe->Xecode = rb;\    newframe->Xmstart = mstart;\
291      newframe->Xoffset_top = rc;\    newframe->Xoffset_top = rc;\
292      newframe->Xims = re;\    newframe->Xims = re;\
293      newframe->Xeptrb = rf;\    newframe->Xeptrb = rf;\
294      newframe->Xflags = rg;\    newframe->Xflags = rg;\
295      newframe->Xrdepth = frame->Xrdepth + 1;\    newframe->Xrdepth = frame->Xrdepth + 1;\
296      newframe->Xprevframe = frame;\    newframe->Xprevframe = frame;\
297      frame = newframe;\    frame = newframe;\
298      DPRINTF(("restarting from line %d\n", __LINE__));\    DPRINTF(("restarting from line %d\n", __LINE__));\
299      goto HEAP_RECURSE;\    goto HEAP_RECURSE;\
300      }\    L_##rw:\
301    else\    DPRINTF(("jumped back to line %d\n", __LINE__));\
     {\  
     DPRINTF(("longjumped back to line %d\n", __LINE__));\  
     frame = md->thisframe;\  
     rx = frame->Xresult;\  
     }\  
302    }    }
303    
304  #define RRETURN(ra)\  #define RRETURN(ra)\
# Line 254  match(), which never changes. */ Line 308  match(), which never changes. */
308    (pcre_stack_free)(newframe);\    (pcre_stack_free)(newframe);\
309    if (frame != NULL)\    if (frame != NULL)\
310      {\      {\
311      frame->Xresult = ra;\      rrc = ra;\
312      md->thisframe = frame;\      goto HEAP_RETURN;\
     longjmp(frame->Xwhere, 1);\  
313      }\      }\
314    return ra;\    return ra;\
315    }    }
# Line 269  typedef struct heapframe { Line 322  typedef struct heapframe {
322    
323    /* Function arguments that may change */    /* Function arguments that may change */
324    
325    const uschar *Xeptr;    USPTR Xeptr;
326    const uschar *Xecode;    const uschar *Xecode;
327      USPTR Xmstart;
328    int Xoffset_top;    int Xoffset_top;
329    long int Xims;    long int Xims;
330    eptrblock *Xeptrb;    eptrblock *Xeptrb;
# Line 279  typedef struct heapframe { Line 333  typedef struct heapframe {
333    
334    /* Function local variables */    /* Function local variables */
335    
336    const uschar *Xcallpat;    USPTR Xcallpat;
337    const uschar *Xcharptr;  #ifdef SUPPORT_UTF8
338    const uschar *Xdata;    USPTR Xcharptr;
339    const uschar *Xnext;  #endif
340    const uschar *Xpp;    USPTR Xdata;
341    const uschar *Xprev;    USPTR Xnext;
342    const uschar *Xsaved_eptr;    USPTR Xpp;
343      USPTR Xprev;
344      USPTR Xsaved_eptr;
345    
346    recursion_info Xnew_recursive;    recursion_info Xnew_recursive;
347    
348    BOOL Xcur_is_word;    BOOL Xcur_is_word;
349    BOOL Xcondition;    BOOL Xcondition;
   BOOL Xminimize;  
350    BOOL Xprev_is_word;    BOOL Xprev_is_word;
351    
352    unsigned long int Xoriginal_ims;    unsigned long int Xoriginal_ims;
# Line 303  typedef struct heapframe { Line 358  typedef struct heapframe {
358    int Xprop_category;    int Xprop_category;
359    int Xprop_chartype;    int Xprop_chartype;
360    int Xprop_script;    int Xprop_script;
361    int *Xprop_test_variable;    int Xoclength;
362      uschar Xocchars[8];
363  #endif  #endif
364    
365      int Xcodelink;
366    int Xctype;    int Xctype;
367    int Xfc;    unsigned int Xfc;
368    int Xfi;    int Xfi;
369    int Xlength;    int Xlength;
370    int Xmax;    int Xmax;
# Line 321  typedef struct heapframe { Line 378  typedef struct heapframe {
378    
379    eptrblock Xnewptrb;    eptrblock Xnewptrb;
380    
381    /* Place to pass back result, and where to jump back to */    /* Where to jump back to */
382    
383    int  Xresult;    int Xwhere;
   jmp_buf Xwhere;  
384    
385  } heapframe;  } heapframe;
386    
# Line 340  typedef struct heapframe { Line 396  typedef struct heapframe {
396  *         Match from current position            *  *         Match from current position            *
397  *************************************************/  *************************************************/
398    
399  /* On entry ecode points to the first opcode, and eptr to the first character  /* This function is called recursively in many circumstances. Whenever it
 in the subject string, while eptrb holds the value of eptr at the start of the  
 last bracketed group - used for breaking infinite loops matching zero-length  
 strings. This function is called recursively in many circumstances. Whenever it  
400  returns a negative (error) response, the outer incarnation must also return the  returns a negative (error) response, the outer incarnation must also return the
401  same response.  same response. */
402    
403    /* These macros pack up tests that are used for partial matching, and which
404    appears several times in the code. We set the "hit end" flag if the pointer is
405    at the end of the subject and also past the start of the subject (i.e.
406    something has been matched). For hard partial matching, we then return
407    immediately. The second one is used when we already know we are past the end of
408    the subject. */
409    
410    #define CHECK_PARTIAL()\
411      if (md->partial != 0 && eptr >= md->end_subject && eptr > mstart)\
412        {\
413        md->hitend = TRUE;\
414        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
415        }
416    
417    #define SCHECK_PARTIAL()\
418      if (md->partial && eptr > mstart)\
419        {\
420        md->hitend = TRUE;\
421        if (md->partial > 1) RRETURN(PCRE_ERROR_PARTIAL);\
422        }
423    
424  Performance note: It might be tempting to extract commonly used fields from the  
425  md structure (e.g. utf8, end_subject) into individual variables to improve  /* Performance note: It might be tempting to extract commonly used fields from
426    the md structure (e.g. utf8, end_subject) into individual variables to improve
427  performance. Tests using gcc on a SPARC disproved this; in the first case, it  performance. Tests using gcc on a SPARC disproved this; in the first case, it
428  made performance worse.  made performance worse.
429    
430  Arguments:  Arguments:
431     eptr        pointer in subject     eptr        pointer to current character in subject
432     ecode       position in code     ecode       pointer to current position in compiled code
433       mstart      pointer to the current match start position (can be modified
434                     by encountering \K)
435     offset_top  current top pointer     offset_top  current top pointer
436     md          pointer to "static" info for the match     md          pointer to "static" info for the match
437     ims         current /i, /m, and /s options     ims         current /i, /m, and /s options
# Line 362  Arguments: Line 439  Arguments:
439                   brackets - for testing for empty matches                   brackets - for testing for empty matches
440     flags       can contain     flags       can contain
441                   match_condassert - this is an assertion condition                   match_condassert - this is an assertion condition
442                   match_isgroup - this is the start of a bracketed group                   match_cbegroup - this is the start of an unlimited repeat
443                       group that can match an empty string
444     rdepth      the recursion depth     rdepth      the recursion depth
445    
446  Returns:       MATCH_MATCH if matched            )  these values are >= 0  Returns:       MATCH_MATCH if matched            )  these values are >= 0
# Line 372  Returns:       MATCH_MATCH if matched Line 450  Returns:       MATCH_MATCH if matched
450  */  */
451    
452  static int  static int
453  match(REGISTER USPTR eptr, REGISTER const uschar *ecode,  match(REGISTER USPTR eptr, REGISTER const uschar *ecode, USPTR mstart,
454    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,    int offset_top, match_data *md, unsigned long int ims, eptrblock *eptrb,
455    int flags, unsigned int rdepth)    int flags, unsigned int rdepth)
456  {  {
457  /* These variables do not need to be preserved over recursion in this function,  /* These variables do not need to be preserved over recursion in this function,
458  so they can be ordinary variables in all cases. Mark them with "register"  so they can be ordinary variables in all cases. Mark some of them with
459  because they are used a lot in loops. */  "register" because they are used a lot in loops. */
460    
461  register int  rrc;         /* Returns from recursive calls */  register int  rrc;         /* Returns from recursive calls */
462  register int  i;           /* Used for loops not involving calls to RMATCH() */  register int  i;           /* Used for loops not involving calls to RMATCH() */
463  register unsigned int  c;  /* Character values not kept over RMATCH() calls */  register unsigned int c;   /* Character values not kept over RMATCH() calls */
464  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */  register BOOL utf8;        /* Local copy of UTF-8 flag for speed */
465    
466    BOOL minimize, possessive; /* Quantifier options */
467    int condcode;
468    
469  /* When recursion is not being used, all "local" variables that have to be  /* When recursion is not being used, all "local" variables that have to be
470  preserved over calls to RMATCH() are part of a "frame" which is obtained from  preserved over calls to RMATCH() are part of a "frame" which is obtained from
471  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 479  frame->Xprevframe = NULL;            /*
479    
480  frame->Xeptr = eptr;  frame->Xeptr = eptr;
481  frame->Xecode = ecode;  frame->Xecode = ecode;
482    frame->Xmstart = mstart;
483  frame->Xoffset_top = offset_top;  frame->Xoffset_top = offset_top;
484  frame->Xims = ims;  frame->Xims = ims;
485  frame->Xeptrb = eptrb;  frame->Xeptrb = eptrb;
# Line 412  HEAP_RECURSE: Line 494  HEAP_RECURSE:
494    
495  #define eptr               frame->Xeptr  #define eptr               frame->Xeptr
496  #define ecode              frame->Xecode  #define ecode              frame->Xecode
497    #define mstart             frame->Xmstart
498  #define offset_top         frame->Xoffset_top  #define offset_top         frame->Xoffset_top
499  #define ims                frame->Xims  #define ims                frame->Xims
500  #define eptrb              frame->Xeptrb  #define eptrb              frame->Xeptrb
# Line 424  HEAP_RECURSE: Line 507  HEAP_RECURSE:
507  #define charptr            frame->Xcharptr  #define charptr            frame->Xcharptr
508  #endif  #endif
509  #define callpat            frame->Xcallpat  #define callpat            frame->Xcallpat
510    #define codelink           frame->Xcodelink
511  #define data               frame->Xdata  #define data               frame->Xdata
512  #define next               frame->Xnext  #define next               frame->Xnext
513  #define pp                 frame->Xpp  #define pp                 frame->Xpp
# Line 434  HEAP_RECURSE: Line 518  HEAP_RECURSE:
518    
519  #define cur_is_word        frame->Xcur_is_word  #define cur_is_word        frame->Xcur_is_word
520  #define condition          frame->Xcondition  #define condition          frame->Xcondition
 #define minimize           frame->Xminimize  
521  #define prev_is_word       frame->Xprev_is_word  #define prev_is_word       frame->Xprev_is_word
522    
523  #define original_ims       frame->Xoriginal_ims  #define original_ims       frame->Xoriginal_ims
# Line 446  HEAP_RECURSE: Line 529  HEAP_RECURSE:
529  #define prop_category      frame->Xprop_category  #define prop_category      frame->Xprop_category
530  #define prop_chartype      frame->Xprop_chartype  #define prop_chartype      frame->Xprop_chartype
531  #define prop_script        frame->Xprop_script  #define prop_script        frame->Xprop_script
532  #define prop_test_variable frame->Xprop_test_variable  #define oclength           frame->Xoclength
533    #define occhars            frame->Xocchars
534  #endif  #endif
535    
536  #define ctype              frame->Xctype  #define ctype              frame->Xctype
# Line 470  HEAP_RECURSE: Line 554  HEAP_RECURSE:
554  get preserved during recursion in the normal way. In this environment, fi and  get preserved during recursion in the normal way. In this environment, fi and
555  i, and fc and c, can be the same variables. */  i, and fc and c, can be the same variables. */
556    
557  #else  #else         /* NO_RECURSE not defined */
558  #define fi i  #define fi i
559  #define fc c  #define fc c
560    
# Line 489  recursion_info new_recursive;      /* wi Line 573  recursion_info new_recursive;      /* wi
573                                     /* that do not have to be preserved over  */                                     /* that do not have to be preserved over  */
574  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */  BOOL cur_is_word;                  /* a recursive call to RMATCH().          */
575  BOOL condition;  BOOL condition;
 BOOL minimize;  
576  BOOL prev_is_word;  BOOL prev_is_word;
577    
578  unsigned long int original_ims;  unsigned long int original_ims;
# Line 501  int prop_fail_result; Line 584  int prop_fail_result;
584  int prop_category;  int prop_category;
585  int prop_chartype;  int prop_chartype;
586  int prop_script;  int prop_script;
587  int *prop_test_variable;  int oclength;
588    uschar occhars[8];
589  #endif  #endif
590    
591    int codelink;
592  int ctype;  int ctype;
593  int length;  int length;
594  int max;  int max;
# Line 516  int save_offset1, save_offset2, save_off Line 601  int save_offset1, save_offset2, save_off
601  int stacksave[REC_STACK_SAVE_MAX];  int stacksave[REC_STACK_SAVE_MAX];
602    
603  eptrblock newptrb;  eptrblock newptrb;
604  #endif  #endif     /* NO_RECURSE */
605    
606  /* These statements are here to stop the compiler complaining about unitialized  /* These statements are here to stop the compiler complaining about unitialized
607  variables. */  variables. */
# Line 524  variables. */ Line 609  variables. */
609  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
610  prop_value = 0;  prop_value = 0;
611  prop_fail_result = 0;  prop_fail_result = 0;
 prop_test_variable = NULL;  
612  #endif  #endif
613    
614    
615  /* This label is used for tail recursion, which is used in a few cases even  /* This label is used for tail recursion, which is used in a few cases even
616  when NO_RECURSE is not defined, in order to reduce the amount of stack that is  when NO_RECURSE is not defined, in order to reduce the amount of stack that is
617  used. Thanks to Ian Taylor for noticing this possibility and sending the  used. Thanks to Ian Taylor for noticing this possibility and sending the
# Line 542  defined). However, RMATCH isn't like a f Line 627  defined). However, RMATCH isn't like a f
627  complicated macro. It has to be used in one particular way. This shouldn't,  complicated macro. It has to be used in one particular way. This shouldn't,
628  however, impact performance when true recursion is being used. */  however, impact performance when true recursion is being used. */
629    
630    #ifdef SUPPORT_UTF8
631    utf8 = md->utf8;       /* Local copy of the flag */
632    #else
633    utf8 = FALSE;
634    #endif
635    
636  /* First check that we haven't called match() too many times, or that we  /* First check that we haven't called match() too many times, or that we
637  haven't exceeded the recursive call limit. */  haven't exceeded the recursive call limit. */
638    
# Line 550  if (rdepth >= md->match_limit_recursion) Line 641  if (rdepth >= md->match_limit_recursion)
641    
642  original_ims = ims;    /* Save for resetting on ')' */  original_ims = ims;    /* Save for resetting on ')' */
643    
644  #ifdef SUPPORT_UTF8  /* At the start of a group with an unlimited repeat that may match an empty
645  utf8 = md->utf8;       /* Local copy of the flag */  string, the match_cbegroup flag is set. When this is the case, add the current
646  #else  subject pointer to the chain of such remembered pointers, to be checked when we
647  utf8 = FALSE;  hit the closing ket, in order to break infinite loops that match no characters.
648  #endif  When match() is called in other circumstances, don't add to the chain. The
649    match_cbegroup flag must NOT be used with tail recursion, because the memory
650  /* 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
651  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. */  
652    
653  if ((flags & match_isgroup) != 0)  if ((flags & match_cbegroup) != 0)
654    {    {
   newptrb.epb_prev = eptrb;  
655    newptrb.epb_saved_eptr = eptr;    newptrb.epb_saved_eptr = eptr;
656      newptrb.epb_prev = eptrb;
657    eptrb = &newptrb;    eptrb = &newptrb;
658    }    }
659    
660  /* Now start processing the operations. */  /* Now start processing the opcodes. */
661    
662  for (;;)  for (;;)
663    {    {
664      minimize = possessive = FALSE;
665    op = *ecode;    op = *ecode;
   minimize = FALSE;  
   
   /* For partial matching, remember if we ever hit the end of the subject after  
   matching at least one subject character. */  
666    
667    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)  
668      {      {
669      number = op - OP_BRA;      case OP_FAIL:
670        RRETURN(MATCH_NOMATCH);
671    
672      /* For extended extraction brackets (large number), we have to fish out the      case OP_PRUNE:
673      number from a dummy opcode at the start. */      RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
674          ims, eptrb, flags, RM51);
675      if (number > EXTRACT_BASIC_MAX)      if (rrc != MATCH_NOMATCH) RRETURN(rrc);
676        number = GET2(ecode, 2+LINK_SIZE);      RRETURN(MATCH_PRUNE);
677    
678        case OP_COMMIT:
679        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
680          ims, eptrb, flags, RM52);
681        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
682        RRETURN(MATCH_COMMIT);
683    
684        case OP_SKIP:
685        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
686          ims, eptrb, flags, RM53);
687        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
688        md->start_match_ptr = eptr;   /* Pass back current position */
689        RRETURN(MATCH_SKIP);
690    
691        case OP_THEN:
692        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
693          ims, eptrb, flags, RM54);
694        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
695        RRETURN(MATCH_THEN);
696    
697        /* Handle a capturing bracket. If there is space in the offset vector, save
698        the current subject position in the working slot at the top of the vector.
699        We mustn't change the current values of the data slot, because they may be
700        set from a previous iteration of this group, and be referred to by a
701        reference inside the group.
702    
703        If the bracket fails to match, we need to restore this value and also the
704        values of the final offsets, in case they were set by a previous iteration
705        of the same bracket.
706    
707        If there isn't enough space in the offset vector, treat this as if it were
708        a non-capturing bracket. Don't worry about setting the flag for the error
709        case here; that is handled in the code for KET. */
710    
711        case OP_CBRA:
712        case OP_SCBRA:
713        number = GET2(ecode, 1+LINK_SIZE);
714      offset = number << 1;      offset = number << 1;
715    
716  #ifdef DEBUG  #ifdef DEBUG
717      printf("start bracket %d subject=", number);      printf("start bracket %d\n", number);
718        printf("subject=");
719      pchars(eptr, 16, TRUE, md);      pchars(eptr, 16, TRUE, md);
720      printf("\n");      printf("\n");
721  #endif  #endif
# Line 624  for (;;) Line 730  for (;;)
730        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));        DPRINTF(("saving %d %d %d\n", save_offset1, save_offset2, save_offset3));
731        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;        md->offset_vector[md->offset_end - number] = eptr - md->start_subject;
732    
733          flags = (op == OP_SCBRA)? match_cbegroup : 0;
734        do        do
735          {          {
736          RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,          RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md,
737            match_isgroup);            ims, eptrb, flags, RM1);
738          if (rrc != MATCH_NOMATCH) RRETURN(rrc);          if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
739          md->capture_last = save_capture_last;          md->capture_last = save_capture_last;
740          ecode += GET(ecode, 1);          ecode += GET(ecode, 1);
741          }          }
# Line 643  for (;;) Line 750  for (;;)
750        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
751        }        }
752    
753      /* Insufficient room for saving captured contents */      /* FALL THROUGH ... Insufficient room for saving captured contents. Treat
754        as a non-capturing bracket. */
     else op = OP_BRA;  
     }  
   
   /* Other types of node can be handled by a switch */  
755    
756    switch(op)      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
757      {      /* VVVVVVVVVVVVVVVVVVVVVVVVV */
     case OP_BRA:     /* Non-capturing bracket: optimized */  
     DPRINTF(("start bracket 0\n"));  
758    
759      /* Loop for all the alternatives */      DPRINTF(("insufficient capture room: treat as non-capturing\n"));
760    
761        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
762        /* VVVVVVVVVVVVVVVVVVVVVVVVV */
763    
764        /* Non-capturing bracket. Loop for all the alternatives. When we get to the
765        final alternative within the brackets, we would return the result of a
766        recursive call to match() whatever happened. We can reduce stack usage by
767        turning this into a tail recursion, except in the case when match_cbegroup
768        is set.*/
769    
770        case OP_BRA:
771        case OP_SBRA:
772        DPRINTF(("start non-capturing bracket\n"));
773        flags = (op >= OP_SBRA)? match_cbegroup : 0;
774      for (;;)      for (;;)
775        {        {
776        /* When we get to the final alternative within the brackets, we would        if (ecode[GET(ecode, 1)] != OP_ALT)   /* Final alternative */
777        return the result of a recursive call to match() whatever happened. We          {
778        can reduce stack usage by turning this into a tail recursion. */          if (flags == 0)    /* Not a possibly empty group */
779              {
780        if (ecode[GET(ecode, 1)] != OP_ALT)            ecode += _pcre_OP_lengths[*ecode];
781         {            DPRINTF(("bracket 0 tail recursion\n"));
782         ecode += 1 + LINK_SIZE;            goto TAIL_RECURSE;
783         flags = match_isgroup;            }
784         DPRINTF(("bracket 0 tail recursion\n"));  
785         goto TAIL_RECURSE;          /* Possibly empty group; can't use tail recursion. */
786         }  
787            RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
788              eptrb, flags, RM48);
789            RRETURN(rrc);
790            }
791    
792        /* For non-final alternatives, continue the loop for a NOMATCH result;        /* For non-final alternatives, continue the loop for a NOMATCH result;
793        otherwise return. */        otherwise return. */
794    
795        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb,        RMATCH(eptr, ecode + _pcre_OP_lengths[*ecode], offset_top, md, ims,
796          match_isgroup);          eptrb, flags, RM2);
797        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
798        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
799        }        }
800      /* Control never reaches here. */      /* Control never reaches here. */
# Line 688  for (;;) Line 806  for (;;)
806      obeyed, we can use tail recursion to avoid using another stack frame. */      obeyed, we can use tail recursion to avoid using another stack frame. */
807    
808      case OP_COND:      case OP_COND:
809      if (ecode[LINK_SIZE+1] == OP_CREF) /* Condition extract or recurse test */      case OP_SCOND:
810        codelink= GET(ecode, 1);
811    
812        /* Because of the way auto-callout works during compile, a callout item is
813        inserted between OP_COND and an assertion condition. */
814    
815        if (ecode[LINK_SIZE+1] == OP_CALLOUT)
816          {
817          if (pcre_callout != NULL)
818            {
819            pcre_callout_block cb;
820            cb.version          = 1;   /* Version 1 of the callout block */
821            cb.callout_number   = ecode[LINK_SIZE+2];
822            cb.offset_vector    = md->offset_vector;
823            cb.subject          = (PCRE_SPTR)md->start_subject;
824            cb.subject_length   = md->end_subject - md->start_subject;
825            cb.start_match      = mstart - md->start_subject;
826            cb.current_position = eptr - md->start_subject;
827            cb.pattern_position = GET(ecode, LINK_SIZE + 3);
828            cb.next_item_length = GET(ecode, 3 + 2*LINK_SIZE);
829            cb.capture_top      = offset_top/2;
830            cb.capture_last     = md->capture_last;
831            cb.callout_data     = md->callout_data;
832            if ((rrc = (*pcre_callout)(&cb)) > 0) RRETURN(MATCH_NOMATCH);
833            if (rrc < 0) RRETURN(rrc);
834            }
835          ecode += _pcre_OP_lengths[OP_CALLOUT];
836          }
837    
838        condcode = ecode[LINK_SIZE+1];
839    
840        /* Now see what the actual condition is */
841    
842        if (condcode == OP_RREF)         /* Recursion test */
843          {
844          offset = GET2(ecode, LINK_SIZE + 2);     /* Recursion group number*/
845          condition = md->recursive != NULL &&
846            (offset == RREF_ANY || offset == md->recursive->group_num);
847          ecode += condition? 3 : GET(ecode, 1);
848          }
849    
850        else if (condcode == OP_CREF)    /* Group used test */
851        {        {
852        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */        offset = GET2(ecode, LINK_SIZE+2) << 1;  /* Doubled ref number */
853        condition = (offset == CREF_RECURSE * 2)?        condition = offset < offset_top && md->offset_vector[offset] >= 0;
854          (md->recursive != NULL) :        ecode += condition? 3 : GET(ecode, 1);
855          (offset < offset_top && md->offset_vector[offset] >= 0);        }
856        ecode += condition? (LINK_SIZE + 4) : (LINK_SIZE + 1 + GET(ecode, 1));  
857        flags = match_isgroup;      else if (condcode == OP_DEF)     /* DEFINE - always false */
858        goto TAIL_RECURSE;        {
859          condition = FALSE;
860          ecode += GET(ecode, 1);
861        }        }
862    
863      /* The condition is an assertion. Call match() to evaluate it - setting      /* The condition is an assertion. Call match() to evaluate it - setting
864      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
865        assertion. */
866    
867      else      else
868        {        {
869        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,
870            match_condassert | match_isgroup);            match_condassert, RM3);
871        if (rrc == MATCH_MATCH)        if (rrc == MATCH_MATCH)
872          {          {
873          ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE+2);          condition = TRUE;
874            ecode += 1 + LINK_SIZE + GET(ecode, LINK_SIZE + 2);
875          while (*ecode == OP_ALT) ecode += GET(ecode, 1);          while (*ecode == OP_ALT) ecode += GET(ecode, 1);
876          }          }
877        else if (rrc != MATCH_NOMATCH)        else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
878          {          {
879          RRETURN(rrc);         /* Need braces because of following else */          RRETURN(rrc);         /* Need braces because of following else */
880          }          }
881        else ecode += GET(ecode, 1);        else
882            {
883            condition = FALSE;
884            ecode += codelink;
885            }
886          }
887    
888        /* We are now at the branch that is to be obeyed. As there is only one,      /* We are now at the branch that is to be obeyed. As there is only one,
889        we can use tail recursion to avoid using another stack frame. */      we can use tail recursion to avoid using another stack frame, except when
890        match_cbegroup is required for an unlimited repeat of a possibly empty
891        group. If the second alternative doesn't exist, we can just plough on. */
892    
893        if (condition || *ecode == OP_ALT)
894          {
895        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
896        flags = match_isgroup;        if (op == OP_SCOND)        /* Possibly empty group */
897        goto TAIL_RECURSE;          {
898            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, match_cbegroup, RM49);
899            RRETURN(rrc);
900            }
901          else                       /* Group must match something */
902            {
903            flags = 0;
904            goto TAIL_RECURSE;
905            }
906        }        }
907      /* Control never reaches here */      else                         /* Condition false & no alternative */
908          {
909          ecode += 1 + LINK_SIZE;
910          }
911        break;
912    
913    
914      /* Skip over conditional reference or large extraction number data if      /* Before OP_ACCEPT there may be any number of OP_CLOSE opcodes,
915      encountered. */      to close any currently open capturing brackets. */
916    
917        case OP_CLOSE:
918        number = GET2(ecode, 1);
919        offset = number << 1;
920    
921    #ifdef DEBUG
922          printf("end bracket %d at *ACCEPT", number);
923          printf("\n");
924    #endif
925    
926      case OP_CREF:      md->capture_last = number;
927      case OP_BRANUMBER:      if (offset >= md->offset_max) md->offset_overflow = TRUE; else
928          {
929          md->offset_vector[offset] =
930            md->offset_vector[md->offset_end - number];
931          md->offset_vector[offset+1] = eptr - md->start_subject;
932          if (offset_top <= offset) offset_top = offset + 2;
933          }
934      ecode += 3;      ecode += 3;
935      break;      break;
936    
     /* End of the pattern. If we are in a recursion, we should restore the  
     offsets appropriately and continue from after the call. */  
937    
938        /* End of the pattern, either real or forced. If we are in a top-level
939        recursion, we should restore the offsets appropriately and continue from
940        after the call. */
941    
942        case OP_ACCEPT:
943      case OP_END:      case OP_END:
944      if (md->recursive != NULL && md->recursive->group_num == 0)      if (md->recursive != NULL && md->recursive->group_num == 0)
945        {        {
# Line 745  for (;;) Line 948  for (;;)
948        md->recursive = rec->prevrec;        md->recursive = rec->prevrec;
949        memmove(md->offset_vector, rec->offset_save,        memmove(md->offset_vector, rec->offset_save,
950          rec->saved_max * sizeof(int));          rec->saved_max * sizeof(int));
951        md->start_match = rec->save_start;        offset_top = rec->offset_top;
952          mstart = rec->save_start;
953        ims = original_ims;        ims = original_ims;
954        ecode = rec->after_call;        ecode = rec->after_call;
955        break;        break;
956        }        }
957    
958      /* 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
959      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
960        the subject. In both cases, backtracking will then try other alternatives,
961        if any. */
962    
963        if (eptr == mstart &&
964            (md->notempty ||
965              (md->notempty_atstart &&
966                mstart == md->start_subject + md->start_offset)))
967          RRETURN(MATCH_NOMATCH);
968    
969        /* Otherwise, we have a match. */
970    
971      if (md->notempty && eptr == md->start_match) RRETURN(MATCH_NOMATCH);      md->end_match_ptr = eptr;           /* Record where we ended */
972      md->end_match_ptr = eptr;          /* Record where we ended */      md->end_offset_top = offset_top;    /* and how many extracts were taken */
973      md->end_offset_top = offset_top;   /* and how many extracts were taken */      md->start_match_ptr = mstart;       /* and the start (\K can modify) */
974      RRETURN(MATCH_MATCH);      RRETURN(MATCH_MATCH);
975    
976      /* Change option settings */      /* Change option settings */
# Line 777  for (;;) Line 991  for (;;)
991      case OP_ASSERTBACK:      case OP_ASSERTBACK:
992      do      do
993        {        {
994        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
995          match_isgroup);          RM4);
996        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
997        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
998        ecode += GET(ecode, 1);        ecode += GET(ecode, 1);
999        }        }
1000      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 804  for (;;) Line 1018  for (;;)
1018      case OP_ASSERTBACK_NOT:      case OP_ASSERTBACK_NOT:
1019      do      do
1020        {        {
1021        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, NULL, 0,
1022          match_isgroup);          RM5);
1023        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);        if (rrc == MATCH_MATCH) RRETURN(MATCH_NOMATCH);
1024        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1025        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1026        }        }
1027      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 826  for (;;) Line 1040  for (;;)
1040  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1041      if (utf8)      if (utf8)
1042        {        {
1043        c = GET(ecode,1);        i = GET(ecode, 1);
1044        for (i = 0; i < c; i++)        while (i-- > 0)
1045          {          {
1046          eptr--;          eptr--;
1047          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);          if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1048          BACKCHAR(eptr)          BACKCHAR(eptr);
1049          }          }
1050        }        }
1051      else      else
# Line 840  for (;;) Line 1054  for (;;)
1054      /* 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 */
1055    
1056        {        {
1057        eptr -= GET(ecode,1);        eptr -= GET(ecode, 1);
1058        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);        if (eptr < md->start_subject) RRETURN(MATCH_NOMATCH);
1059        }        }
1060    
1061      /* Skip to next op code */      /* Save the earliest consulted character, then skip to next op code */
1062    
1063        if (eptr < md->start_used_ptr) md->start_used_ptr = eptr;
1064      ecode += 1 + LINK_SIZE;      ecode += 1 + LINK_SIZE;
1065      break;      break;
1066    
# Line 862  for (;;) Line 1077  for (;;)
1077        cb.offset_vector    = md->offset_vector;        cb.offset_vector    = md->offset_vector;
1078        cb.subject          = (PCRE_SPTR)md->start_subject;        cb.subject          = (PCRE_SPTR)md->start_subject;
1079        cb.subject_length   = md->end_subject - md->start_subject;        cb.subject_length   = md->end_subject - md->start_subject;
1080        cb.start_match      = md->start_match - md->start_subject;        cb.start_match      = mstart - md->start_subject;
1081        cb.current_position = eptr - md->start_subject;        cb.current_position = eptr - md->start_subject;
1082        cb.pattern_position = GET(ecode, 2);        cb.pattern_position = GET(ecode, 2);
1083        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);        cb.next_item_length = GET(ecode, 2 + LINK_SIZE);
# Line 897  for (;;) Line 1112  for (;;)
1112      case OP_RECURSE:      case OP_RECURSE:
1113        {        {
1114        callpat = md->start_code + GET(ecode, 1);        callpat = md->start_code + GET(ecode, 1);
1115        new_recursive.group_num = *callpat - OP_BRA;        new_recursive.group_num = (callpat == md->start_code)? 0 :
1116            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);  
1117    
1118        /* Add to "recursing stack" */        /* Add to "recursing stack" */
1119    
# Line 929  for (;;) Line 1139  for (;;)
1139    
1140        memcpy(new_recursive.offset_save, md->offset_vector,        memcpy(new_recursive.offset_save, md->offset_vector,
1141              new_recursive.saved_max * sizeof(int));              new_recursive.saved_max * sizeof(int));
1142        new_recursive.save_start = md->start_match;        new_recursive.save_start = mstart;
1143        md->start_match = eptr;        new_recursive.offset_top = offset_top;
1144          mstart = eptr;
1145    
1146        /* 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
1147        restore the offset and recursion data. */        restore the offset and recursion data. */
1148    
1149        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));        DPRINTF(("Recursing into group %d\n", new_recursive.group_num));
1150          flags = (*callpat >= OP_SBRA)? match_cbegroup : 0;
1151        do        do
1152          {          {
1153          RMATCH(rrc, eptr, callpat + 1 + LINK_SIZE, offset_top, md, ims,          RMATCH(eptr, callpat + _pcre_OP_lengths[*callpat], offset_top,
1154              eptrb, match_isgroup);            md, ims, eptrb, flags, RM6);
1155          if (rrc == MATCH_MATCH)          if (rrc == MATCH_MATCH)
1156            {            {
1157            DPRINTF(("Recursion matched\n"));            DPRINTF(("Recursion matched\n"));
# Line 948  for (;;) Line 1160  for (;;)
1160              (pcre_free)(new_recursive.offset_save);              (pcre_free)(new_recursive.offset_save);
1161            RRETURN(MATCH_MATCH);            RRETURN(MATCH_MATCH);
1162            }            }
1163          else if (rrc != MATCH_NOMATCH)          else if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN)
1164            {            {
1165            DPRINTF(("Recursion gave error %d\n", rrc));            DPRINTF(("Recursion gave error %d\n", rrc));
1166              if (new_recursive.offset_save != stacksave)
1167                (pcre_free)(new_recursive.offset_save);
1168            RRETURN(rrc);            RRETURN(rrc);
1169            }            }
1170    
# Line 982  for (;;) Line 1196  for (;;)
1196    
1197      do      do
1198        {        {
1199        RMATCH(rrc, eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims,        RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, ims, eptrb, 0, RM7);
         eptrb, match_isgroup);  
1200        if (rrc == MATCH_MATCH) break;        if (rrc == MATCH_MATCH) break;
1201        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH && rrc != MATCH_THEN) RRETURN(rrc);
1202        ecode += GET(ecode,1);        ecode += GET(ecode,1);
1203        }        }
1204      while (*ecode == OP_ALT);      while (*ecode == OP_ALT);
# Line 997  for (;;) Line 1210  for (;;)
1210      /* Continue as from after the assertion, updating the offsets high water      /* Continue as from after the assertion, updating the offsets high water
1211      mark, since extracts may have been taken. */      mark, since extracts may have been taken. */
1212    
1213      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
1214    
1215      offset_top = md->end_offset_top;      offset_top = md->end_offset_top;
1216      eptr = md->end_match_ptr;      eptr = md->end_match_ptr;
# Line 1028  for (;;) Line 1241  for (;;)
1241    
1242      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1243        {        {
1244        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);
1245        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1246        ecode = prev;        ecode = prev;
1247        flags = match_isgroup;        flags = 0;
1248        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1249        }        }
1250      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1251        {        {
1252        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, match_cbegroup, RM9);
1253        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1254        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1255        flags = 0;        flags = 0;
# Line 1051  for (;;) Line 1264  for (;;)
1264      do ecode += GET(ecode,1); while (*ecode == OP_ALT);      do ecode += GET(ecode,1); while (*ecode == OP_ALT);
1265      break;      break;
1266    
1267      /* BRAZERO and BRAMINZERO occur just before a bracket group, indicating      /* BRAZERO, BRAMINZERO and SKIPZERO occur just before a bracket group,
1268      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
1269      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
1270      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
1271      preceded by BRAZERO or BRAMINZERO. */      optional ones preceded by BRAZERO or BRAMINZERO. */
1272    
1273      case OP_BRAZERO:      case OP_BRAZERO:
1274        {        {
1275        next = ecode+1;        next = ecode+1;
1276        RMATCH(rrc, eptr, next, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, next, offset_top, md, ims, eptrb, 0, RM10);
1277        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1278        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next,1); while (*next == OP_ALT);
1279        ecode = next + 1+LINK_SIZE;        ecode = next + 1 + LINK_SIZE;
1280        }        }
1281      break;      break;
1282    
1283      case OP_BRAMINZERO:      case OP_BRAMINZERO:
1284        {        {
1285        next = ecode+1;        next = ecode+1;
1286        do next += GET(next,1); while (*next == OP_ALT);        do next += GET(next, 1); while (*next == OP_ALT);
1287        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);  
1288        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1289        ecode++;        ecode++;
1290        }        }
1291      break;      break;
1292    
1293      /* End of a group, repeated or non-repeating. If we are at the end of      case OP_SKIPZERO:
1294      an assertion "group", stop matching and return MATCH_MATCH, but record the        {
1295      current high water mark for use by positive assertions. Do this also        next = ecode+1;
1296      for the "once" (not-backup up) groups. */        do next += GET(next,1); while (*next == OP_ALT);
1297          ecode = next + 1 + LINK_SIZE;
1298          }
1299        break;
1300    
1301        /* End of a group, repeated or non-repeating. */
1302    
1303      case OP_KET:      case OP_KET:
1304      case OP_KETRMIN:      case OP_KETRMIN:
1305      case OP_KETRMAX:      case OP_KETRMAX:
1306      prev = ecode - GET(ecode, 1);      prev = ecode - GET(ecode, 1);
     saved_eptr = eptrb->epb_saved_eptr;  
1307    
1308      /* Back up the stack of bracket start pointers. */      /* If this was a group that remembered the subject start, in order to break
1309        infinite repeats of empty string matches, retrieve the subject start from
1310        the chain. Otherwise, set it NULL. */
1311    
1312        if (*prev >= OP_SBRA)
1313          {
1314          saved_eptr = eptrb->epb_saved_eptr;   /* Value at start of group */
1315          eptrb = eptrb->epb_prev;              /* Backup to previous group */
1316          }
1317        else saved_eptr = NULL;
1318    
1319      eptrb = eptrb->epb_prev;      /* If we are at the end of an assertion group, stop matching and return
1320        MATCH_MATCH, but record the current high water mark for use by positive
1321        assertions. Do this also for the "once" (atomic) groups. */
1322    
1323      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||      if (*prev == OP_ASSERT || *prev == OP_ASSERT_NOT ||
1324          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||          *prev == OP_ASSERTBACK || *prev == OP_ASSERTBACK_NOT ||
# Line 1102  for (;;) Line 1329  for (;;)
1329        RRETURN(MATCH_MATCH);        RRETURN(MATCH_MATCH);
1330        }        }
1331    
1332      /* 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
1333      group number back at the start and if necessary complete handling an      and if necessary complete handling an extraction by setting the offsets and
1334      extraction by setting the offsets and bumping the high water mark. */      bumping the high water mark. Note that whole-pattern recursion is coded as
1335        a recurse into group 0, so it won't be picked up here. Instead, we catch it
1336        when the OP_END is reached. Other recursion is handled here. */
1337    
1338      if (*prev != OP_COND)      if (*prev == OP_CBRA || *prev == OP_SCBRA)
1339        {        {
1340        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);  
1341        offset = number << 1;        offset = number << 1;
1342    
1343  #ifdef DEBUG  #ifdef DEBUG
1344        printf("end bracket %d", number);        printf("end bracket %d", number);
1345        printf("\n");        printf("\n");
1346  #endif  #endif
1347    
1348        /* Test for a numbered group. This includes groups called as a result        md->capture_last = number;
1349        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)  
1350          {          {
1351          md->capture_last = number;          md->offset_vector[offset] =
1352          if (offset >= md->offset_max) md->offset_overflow = TRUE; else            md->offset_vector[md->offset_end - number];
1353            {          md->offset_vector[offset+1] = eptr - md->start_subject;
1354            md->offset_vector[offset] =          if (offset_top <= offset) offset_top = offset + 2;
1355              md->offset_vector[md->offset_end - number];          }
1356            md->offset_vector[offset+1] = eptr - md->start_subject;  
1357            if (offset_top <= offset) offset_top = offset + 2;        /* Handle a recursively called group. Restore the offsets
1358            }        appropriately and continue from after the call. */
1359    
1360          /* Handle a recursively called group. Restore the offsets        if (md->recursive != NULL && md->recursive->group_num == number)
1361          appropriately and continue from after the call. */          {
1362            recursion_info *rec = md->recursive;
1363          if (md->recursive != NULL && md->recursive->group_num == number)          DPRINTF(("Recursion (%d) succeeded - continuing\n", number));
1364            {          md->recursive = rec->prevrec;
1365            recursion_info *rec = md->recursive;          mstart = rec->save_start;
1366            DPRINTF(("Recursion (%d) succeeded - continuing\n", number));          memcpy(md->offset_vector, rec->offset_save,
1367            md->recursive = rec->prevrec;            rec->saved_max * sizeof(int));
1368            md->start_match = rec->save_start;          offset_top = rec->offset_top;
1369            memcpy(md->offset_vector, rec->offset_save,          ecode = rec->after_call;
1370              rec->saved_max * sizeof(int));          ims = original_ims;
1371            ecode = rec->after_call;          break;
           ims = original_ims;  
           break;  
           }  
1372          }          }
1373        }        }
1374    
1375      /* 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
1376      the group. */      flags, in case they got changed during the group. */
1377    
1378      ims = original_ims;      ims = original_ims;
1379      DPRINTF(("ims reset to %02lx\n", ims));      DPRINTF(("ims reset to %02lx\n", ims));
# Line 1175  for (;;) Line 1392  for (;;)
1392    
1393      /* 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
1394      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
1395      tail recursion to avoid using another stack frame. */      tail recursion to avoid using another stack frame, unless we have an
1396        unlimited repeat of a group that can match an empty string. */
1397    
1398        flags = (*prev >= OP_SBRA)? match_cbegroup : 0;
1399    
1400      if (*ecode == OP_KETRMIN)      if (*ecode == OP_KETRMIN)
1401        {        {
1402        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);
1403        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1404          if (flags != 0)    /* Could match an empty string */
1405            {
1406            RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM50);
1407            RRETURN(rrc);
1408            }
1409        ecode = prev;        ecode = prev;
       flags = match_isgroup;  
1410        goto TAIL_RECURSE;        goto TAIL_RECURSE;
1411        }        }
1412      else  /* OP_KETRMAX */      else  /* OP_KETRMAX */
1413        {        {
1414        RMATCH(rrc, eptr, prev, offset_top, md, ims, eptrb, match_isgroup);        RMATCH(eptr, prev, offset_top, md, ims, eptrb, flags, RM13);
1415        if (rrc != MATCH_NOMATCH) RRETURN(rrc);        if (rrc != MATCH_NOMATCH) RRETURN(rrc);
1416        ecode += 1 + LINK_SIZE;        ecode += 1 + LINK_SIZE;
1417        flags = 0;        flags = 0;
# Line 1202  for (;;) Line 1426  for (;;)
1426      if ((ims & PCRE_MULTILINE) != 0)      if ((ims & PCRE_MULTILINE) != 0)
1427        {        {
1428        if (eptr != md->start_subject &&        if (eptr != md->start_subject &&
1429            (eptr == md->end_subject ||            (eptr == md->end_subject || !WAS_NEWLINE(eptr)))
            eptr < md->start_subject + md->nllen ||  
            !IS_NEWLINE(eptr - md->nllen)))  
1430          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
1431        ecode++;        ecode++;
1432        break;        break;
# Line 1225  for (;;) Line 1447  for (;;)
1447      ecode++;      ecode++;
1448      break;      break;
1449    
1450        /* Reset the start of match point */
1451    
1452        case OP_SET_SOM:
1453        mstart = eptr;
1454        ecode++;
1455        break;
1456    
1457      /* Assert before internal newline if multiline, or before a terminating      /* Assert before internal newline if multiline, or before a terminating
1458      newline unless endonly is set, else end of subject unless noteol is set. */      newline unless endonly is set, else end of subject unless noteol is set. */
1459    
# Line 1244  for (;;) Line 1473  for (;;)
1473        if (!md->endonly)        if (!md->endonly)
1474          {          {
1475          if (eptr != md->end_subject &&          if (eptr != md->end_subject &&
1476              (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))              (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1477            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1478          ecode++;          ecode++;
1479          break;          break;
# Line 1263  for (;;) Line 1492  for (;;)
1492    
1493      case OP_EODN:      case OP_EODN:
1494      if (eptr != md->end_subject &&      if (eptr != md->end_subject &&
1495          (eptr != md->end_subject - md->nllen || !IS_NEWLINE(eptr)))          (!IS_NEWLINE(eptr) || eptr != md->end_subject - md->nllen))
1496        RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1497      ecode++;      ecode++;
1498      break;      break;
# Line 1276  for (;;) Line 1505  for (;;)
1505    
1506        /* Find out if the previous and current characters are "word" characters.        /* Find out if the previous and current characters are "word" characters.
1507        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
1508        be "non-word" characters. */        be "non-word" characters. Remember the earliest consulted character for
1509          partial matching. */
1510    
1511  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
1512        if (utf8)        if (utf8)
1513          {          {
1514          if (eptr == md->start_subject) prev_is_word = FALSE; else          if (eptr == md->start_subject) prev_is_word = FALSE; else
1515            {            {
1516            const uschar *lastptr = eptr - 1;            USPTR lastptr = eptr - 1;
1517            while((*lastptr & 0xc0) == 0x80) lastptr--;            while((*lastptr & 0xc0) == 0x80) lastptr--;
1518              if (lastptr < md->start_used_ptr) md->start_used_ptr = lastptr;
1519            GETCHAR(c, lastptr);            GETCHAR(c, lastptr);
1520            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            prev_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
1521            }            }
1522          if (eptr >= md->end_subject) cur_is_word = FALSE; else          if (eptr >= md->end_subject)
1523              {
1524              SCHECK_PARTIAL();
1525              cur_is_word = FALSE;
1526              }
1527            else
1528            {            {
1529            GETCHAR(c, eptr);            GETCHAR(c, eptr);
1530            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;            cur_is_word = c < 256 && (md->ctypes[c] & ctype_word) != 0;
# Line 1297  for (;;) Line 1533  for (;;)
1533        else        else
1534  #endif  #endif
1535    
1536        /* More streamlined when not in UTF-8 mode */        /* Not in UTF-8 mode */
1537    
1538          {          {
1539          prev_is_word = (eptr != md->start_subject) &&          if (eptr == md->start_subject) prev_is_word = FALSE; else
1540            ((md->ctypes[eptr[-1]] & ctype_word) != 0);            {
1541          cur_is_word = (eptr < md->end_subject) &&            if (eptr <= md->start_used_ptr) md->start_used_ptr = eptr - 1;
1542            ((md->ctypes[*eptr] & ctype_word) != 0);            prev_is_word = ((md->ctypes[eptr[-1]] & ctype_word) != 0);
1543              }
1544            if (eptr >= md->end_subject)
1545              {
1546              SCHECK_PARTIAL();
1547              cur_is_word = FALSE;
1548              }
1549            else cur_is_word = ((md->ctypes[*eptr] & ctype_word) != 0);
1550          }          }
1551    
1552        /* Now see if the situation is what we want */        /* Now see if the situation is what we want */
# Line 1317  for (;;) Line 1560  for (;;)
1560      /* Match a single character type; inline for speed */      /* Match a single character type; inline for speed */
1561    
1562      case OP_ANY:      case OP_ANY:
1563      if ((ims & PCRE_DOTALL) == 0)      if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
1564        /* Fall through */
1565    
1566        case OP_ALLANY:
1567        if (eptr++ >= md->end_subject)
1568        {        {
1569        if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))        SCHECK_PARTIAL();
1570          RRETURN(MATCH_NOMATCH);        RRETURN(MATCH_NOMATCH);
1571        }        }
1572      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++;  
1573      ecode++;      ecode++;
1574      break;      break;
1575    
# Line 1332  for (;;) Line 1577  for (;;)
1577      any byte, even newline, independent of the setting of PCRE_DOTALL. */      any byte, even newline, independent of the setting of PCRE_DOTALL. */
1578    
1579      case OP_ANYBYTE:      case OP_ANYBYTE:
1580      if (eptr++ >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr++ >= md->end_subject)
1581          {
1582          SCHECK_PARTIAL();
1583          RRETURN(MATCH_NOMATCH);
1584          }
1585      ecode++;      ecode++;
1586      break;      break;
1587    
1588      case OP_NOT_DIGIT:      case OP_NOT_DIGIT:
1589      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1590          {
1591          SCHECK_PARTIAL();
1592          RRETURN(MATCH_NOMATCH);
1593          }
1594      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1595      if (      if (
1596  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1350  for (;;) Line 1603  for (;;)
1603      break;      break;
1604    
1605      case OP_DIGIT:      case OP_DIGIT:
1606      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1607          {
1608          SCHECK_PARTIAL();
1609          RRETURN(MATCH_NOMATCH);
1610          }
1611      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1612      if (      if (
1613  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1363  for (;;) Line 1620  for (;;)
1620      break;      break;
1621    
1622      case OP_NOT_WHITESPACE:      case OP_NOT_WHITESPACE:
1623      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1624          {
1625          SCHECK_PARTIAL();
1626          RRETURN(MATCH_NOMATCH);
1627          }
1628      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1629      if (      if (
1630  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1376  for (;;) Line 1637  for (;;)
1637      break;      break;
1638    
1639      case OP_WHITESPACE:      case OP_WHITESPACE:
1640      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1641          {
1642          SCHECK_PARTIAL();
1643          RRETURN(MATCH_NOMATCH);
1644          }
1645      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1646      if (      if (
1647  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1389  for (;;) Line 1654  for (;;)
1654      break;      break;
1655    
1656      case OP_NOT_WORDCHAR:      case OP_NOT_WORDCHAR:
1657      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1658          {
1659          SCHECK_PARTIAL();
1660          RRETURN(MATCH_NOMATCH);
1661          }
1662      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1663      if (      if (
1664  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1402  for (;;) Line 1671  for (;;)
1671      break;      break;
1672    
1673      case OP_WORDCHAR:      case OP_WORDCHAR:
1674      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1675          {
1676          SCHECK_PARTIAL();
1677          RRETURN(MATCH_NOMATCH);
1678          }
1679      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1680      if (      if (
1681  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1414  for (;;) Line 1687  for (;;)
1687      ecode++;      ecode++;
1688      break;      break;
1689    
1690        case OP_ANYNL:
1691        if (eptr >= md->end_subject)
1692          {
1693          SCHECK_PARTIAL();
1694          RRETURN(MATCH_NOMATCH);
1695          }
1696        GETCHARINCTEST(c, eptr);
1697        switch(c)
1698          {
1699          default: RRETURN(MATCH_NOMATCH);
1700          case 0x000d:
1701          if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
1702          break;
1703    
1704          case 0x000a:
1705          break;
1706    
1707          case 0x000b:
1708          case 0x000c:
1709          case 0x0085:
1710          case 0x2028:
1711          case 0x2029:
1712          if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
1713          break;
1714          }
1715        ecode++;
1716        break;
1717    
1718        case OP_NOT_HSPACE:
1719        if (eptr >= md->end_subject)
1720          {
1721          SCHECK_PARTIAL();
1722          RRETURN(MATCH_NOMATCH);
1723          }
1724        GETCHARINCTEST(c, eptr);
1725        switch(c)
1726          {
1727          default: break;
1728          case 0x09:      /* HT */
1729          case 0x20:      /* SPACE */
1730          case 0xa0:      /* NBSP */
1731          case 0x1680:    /* OGHAM SPACE MARK */
1732          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1733          case 0x2000:    /* EN QUAD */
1734          case 0x2001:    /* EM QUAD */
1735          case 0x2002:    /* EN SPACE */
1736          case 0x2003:    /* EM SPACE */
1737          case 0x2004:    /* THREE-PER-EM SPACE */
1738          case 0x2005:    /* FOUR-PER-EM SPACE */
1739          case 0x2006:    /* SIX-PER-EM SPACE */
1740          case 0x2007:    /* FIGURE SPACE */
1741          case 0x2008:    /* PUNCTUATION SPACE */
1742          case 0x2009:    /* THIN SPACE */
1743          case 0x200A:    /* HAIR SPACE */
1744          case 0x202f:    /* NARROW NO-BREAK SPACE */
1745          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1746          case 0x3000:    /* IDEOGRAPHIC SPACE */
1747          RRETURN(MATCH_NOMATCH);
1748          }
1749        ecode++;
1750        break;
1751    
1752        case OP_HSPACE:
1753        if (eptr >= md->end_subject)
1754          {
1755          SCHECK_PARTIAL();
1756          RRETURN(MATCH_NOMATCH);
1757          }
1758        GETCHARINCTEST(c, eptr);
1759        switch(c)
1760          {
1761          default: RRETURN(MATCH_NOMATCH);
1762          case 0x09:      /* HT */
1763          case 0x20:      /* SPACE */
1764          case 0xa0:      /* NBSP */
1765          case 0x1680:    /* OGHAM SPACE MARK */
1766          case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
1767          case 0x2000:    /* EN QUAD */
1768          case 0x2001:    /* EM QUAD */
1769          case 0x2002:    /* EN SPACE */
1770          case 0x2003:    /* EM SPACE */
1771          case 0x2004:    /* THREE-PER-EM SPACE */
1772          case 0x2005:    /* FOUR-PER-EM SPACE */
1773          case 0x2006:    /* SIX-PER-EM SPACE */
1774          case 0x2007:    /* FIGURE SPACE */
1775          case 0x2008:    /* PUNCTUATION SPACE */
1776          case 0x2009:    /* THIN SPACE */
1777          case 0x200A:    /* HAIR SPACE */
1778          case 0x202f:    /* NARROW NO-BREAK SPACE */
1779          case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
1780          case 0x3000:    /* IDEOGRAPHIC SPACE */
1781          break;
1782          }
1783        ecode++;
1784        break;
1785    
1786        case OP_NOT_VSPACE:
1787        if (eptr >= md->end_subject)
1788          {
1789          SCHECK_PARTIAL();
1790          RRETURN(MATCH_NOMATCH);
1791          }
1792        GETCHARINCTEST(c, eptr);
1793        switch(c)
1794          {
1795          default: break;
1796          case 0x0a:      /* LF */
1797          case 0x0b:      /* VT */
1798          case 0x0c:      /* FF */
1799          case 0x0d:      /* CR */
1800          case 0x85:      /* NEL */
1801          case 0x2028:    /* LINE SEPARATOR */
1802          case 0x2029:    /* PARAGRAPH SEPARATOR */
1803          RRETURN(MATCH_NOMATCH);
1804          }
1805        ecode++;
1806        break;
1807    
1808        case OP_VSPACE:
1809        if (eptr >= md->end_subject)
1810          {
1811          SCHECK_PARTIAL();
1812          RRETURN(MATCH_NOMATCH);
1813          }
1814        GETCHARINCTEST(c, eptr);
1815        switch(c)
1816          {
1817          default: RRETURN(MATCH_NOMATCH);
1818          case 0x0a:      /* LF */
1819          case 0x0b:      /* VT */
1820          case 0x0c:      /* FF */
1821          case 0x0d:      /* CR */
1822          case 0x85:      /* NEL */
1823          case 0x2028:    /* LINE SEPARATOR */
1824          case 0x2029:    /* PARAGRAPH SEPARATOR */
1825          break;
1826          }
1827        ecode++;
1828        break;
1829    
1830  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
1831      /* Check the next character by Unicode property. We will get here only      /* Check the next character by Unicode property. We will get here only
1832      if the support is in the binary; otherwise a compile-time error occurs. */      if the support is in the binary; otherwise a compile-time error occurs. */
1833    
1834      case OP_PROP:      case OP_PROP:
1835      case OP_NOTPROP:      case OP_NOTPROP:
1836      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1837          {
1838          SCHECK_PARTIAL();
1839          RRETURN(MATCH_NOMATCH);
1840          }
1841      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1842        {        {
1843        int chartype, script;        const ucd_record *prop = GET_UCD(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1844    
1845        switch(ecode[1])        switch(ecode[1])
1846          {          {
# Line 1433  for (;;) Line 1849  for (;;)
1849          break;          break;
1850    
1851          case PT_LAMP:          case PT_LAMP:
1852          if ((chartype == ucp_Lu ||          if ((prop->chartype == ucp_Lu ||
1853               chartype == ucp_Ll ||               prop->chartype == ucp_Ll ||
1854               chartype == ucp_Lt) == (op == OP_NOTPROP))               prop->chartype == ucp_Lt) == (op == OP_NOTPROP))
1855            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1856           break;           break;
1857    
1858          case PT_GC:          case PT_GC:
1859          if ((ecode[2] != category) == (op == OP_PROP))          if ((ecode[2] != _pcre_ucp_gentype[prop->chartype]) == (op == OP_PROP))
1860            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1861          break;          break;
1862    
1863          case PT_PC:          case PT_PC:
1864          if ((ecode[2] != chartype) == (op == OP_PROP))          if ((ecode[2] != prop->chartype) == (op == OP_PROP))
1865            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1866          break;          break;
1867    
1868          case PT_SC:          case PT_SC:
1869          if ((ecode[2] != script) == (op == OP_PROP))          if ((ecode[2] != prop->script) == (op == OP_PROP))
1870            RRETURN(MATCH_NOMATCH);            RRETURN(MATCH_NOMATCH);
1871          break;          break;
1872    
1873          default:          default:
1874          RRETURN(PCRE_ERROR_INTERNAL);          RRETURN(PCRE_ERROR_INTERNAL);
         break;  
1875          }          }
1876    
1877        ecode += 3;        ecode += 3;
# Line 1467  for (;;) Line 1882  for (;;)
1882      is in the binary; otherwise a compile-time error occurs. */      is in the binary; otherwise a compile-time error occurs. */
1883    
1884      case OP_EXTUNI:      case OP_EXTUNI:
1885      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
1886          {
1887          SCHECK_PARTIAL();
1888          RRETURN(MATCH_NOMATCH);
1889          }
1890      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
1891        {        {
1892        int chartype, script;        int category = UCD_CATEGORY(c);
       int category = _pcre_ucp_findprop(c, &chartype, &script);  
1893        if (category == ucp_M) RRETURN(MATCH_NOMATCH);        if (category == ucp_M) RRETURN(MATCH_NOMATCH);
1894        while (eptr < md->end_subject)        while (eptr < md->end_subject)
1895          {          {
# Line 1480  for (;;) Line 1898  for (;;)
1898            {            {
1899            GETCHARLEN(c, eptr, len);            GETCHARLEN(c, eptr, len);
1900            }            }
1901          category = _pcre_ucp_findprop(c, &chartype, &script);          category = UCD_CATEGORY(c);
1902          if (category != ucp_M) break;          if (category != ucp_M) break;
1903          eptr += len;          eptr += len;
1904          }          }
# Line 1501  for (;;) Line 1919  for (;;)
1919      case OP_REF:      case OP_REF:
1920        {        {
1921        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */        offset = GET2(ecode, 1) << 1;               /* Doubled ref number */
1922        ecode += 3;                                 /* Advance past item */        ecode += 3;
1923    
1924          /* If the reference is unset, there are two possibilities:
1925    
1926          (a) In the default, Perl-compatible state, set the length to be longer
1927          than the amount of subject left; this ensures that every attempt at a
1928          match fails. We can't just fail here, because of the possibility of
1929          quantifiers with zero minima.
1930    
1931        /* 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
1932        of subject left; this ensures that every attempt at a match fails. We        so that the back reference matches an empty string.
1933        can't just fail here, because of the possibility of quantifiers with zero  
1934        minima. */        Otherwise, set the length to the length of what was matched by the
1935          referenced subpattern. */
1936        length = (offset >= offset_top || md->offset_vector[offset] < 0)?  
1937          md->end_subject - eptr + 1 :        if (offset >= offset_top || md->offset_vector[offset] < 0)
1938          md->offset_vector[offset+1] - md->offset_vector[offset];          length = (md->jscript_compat)? 0 : md->end_subject - eptr + 1;
1939          else
1940            length = md->offset_vector[offset+1] - md->offset_vector[offset];
1941    
1942        /* Set up for repetition, or handle the non-repeated case */        /* Set up for repetition, or handle the non-repeated case */
1943    
# Line 1539  for (;;) Line 1966  for (;;)
1966          break;          break;
1967    
1968          default:               /* No repeat follows */          default:               /* No repeat follows */
1969          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1970              {
1971              CHECK_PARTIAL();
1972              RRETURN(MATCH_NOMATCH);
1973              }
1974          eptr += length;          eptr += length;
1975          continue;              /* With the main loop */          continue;              /* With the main loop */
1976          }          }
# Line 1555  for (;;) Line 1986  for (;;)
1986    
1987        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
1988          {          {
1989          if (!match_ref(offset, eptr, length, md, ims)) RRETURN(MATCH_NOMATCH);          if (!match_ref(offset, eptr, length, md, ims))
1990          eptr += length;            {
1991          }            CHECK_PARTIAL();
1992              RRETURN(MATCH_NOMATCH);
1993              }
1994            eptr += length;
1995            }
1996    
1997        /* If min = max, continue at the same level without recursion.        /* If min = max, continue at the same level without recursion.
1998        They are not both allowed to be zero. */        They are not both allowed to be zero. */
# Line 1570  for (;;) Line 2005  for (;;)
2005          {          {
2006          for (fi = min;; fi++)          for (fi = min;; fi++)
2007            {            {
2008            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM14);
2009            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2010            if (fi >= max || !match_ref(offset, eptr, length, md, ims))            if (fi >= max) RRETURN(MATCH_NOMATCH);
2011              if (!match_ref(offset, eptr, length, md, ims))
2012                {
2013                CHECK_PARTIAL();
2014              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2015                }
2016            eptr += length;            eptr += length;
2017            }            }
2018          /* Control never gets here */          /* Control never gets here */
# Line 1591  for (;;) Line 2030  for (;;)
2030            }            }
2031          while (eptr >= pp)          while (eptr >= pp)
2032            {            {
2033            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM15);
2034            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2035            eptr -= length;            eptr -= length;
2036            }            }
# Line 1600  for (;;) Line 2039  for (;;)
2039        }        }
2040      /* Control never gets here */      /* Control never gets here */
2041    
   
   
2042      /* Match a bit-mapped character class, possibly repeatedly. This op code is      /* Match a bit-mapped character class, possibly repeatedly. This op code is
2043      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,
2044      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 2093  for (;;)
2093          {          {
2094          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2095            {            {
2096            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2097                {
2098                SCHECK_PARTIAL();
2099                RRETURN(MATCH_NOMATCH);
2100                }
2101            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
2102            if (c > 255)            if (c > 255)
2103              {              {
# Line 1674  for (;;) Line 2115  for (;;)
2115          {          {
2116          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2117            {            {
2118            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
2119                {
2120                SCHECK_PARTIAL();
2121                RRETURN(MATCH_NOMATCH);
2122                }
2123            c = *eptr++;            c = *eptr++;
2124            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);            if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2125            }            }
# Line 1696  for (;;) Line 2141  for (;;)
2141            {            {
2142            for (fi = min;; fi++)            for (fi = min;; fi++)
2143              {              {
2144              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM16);
2145              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2146              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2147                if (eptr >= md->end_subject)
2148                  {
2149                  SCHECK_PARTIAL();
2150                  RRETURN(MATCH_NOMATCH);
2151                  }
2152              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
2153              if (c > 255)              if (c > 255)
2154                {                {
# Line 1716  for (;;) Line 2166  for (;;)
2166            {            {
2167            for (fi = min;; fi++)            for (fi = min;; fi++)
2168              {              {
2169              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM17);
2170              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2171              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2172                if (eptr >= md->end_subject)
2173                  {
2174                  SCHECK_PARTIAL();
2175                  RRETURN(MATCH_NOMATCH);
2176                  }
2177              c = *eptr++;              c = *eptr++;
2178              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);              if ((data[c/8] & (1 << (c&7))) == 0) RRETURN(MATCH_NOMATCH);
2179              }              }
# Line 1753  for (;;) Line 2208  for (;;)
2208              }              }
2209            for (;;)            for (;;)
2210              {              {
2211              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM18);
2212              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2213              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2214              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 1772  for (;;) Line 2227  for (;;)
2227              }              }
2228            while (eptr >= pp)            while (eptr >= pp)
2229              {              {
2230              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM19);
2231              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2232              eptr--;              eptr--;
2233              }              }
# Line 1785  for (;;) Line 2240  for (;;)
2240    
2241    
2242      /* Match an extended character class. This opcode is encountered only      /* Match an extended character class. This opcode is encountered only
2243      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
2244        mode, because Unicode properties are supported in non-UTF-8 mode. */
2245    
2246  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
2247      case OP_XCLASS:      case OP_XCLASS:
# Line 1826  for (;;) Line 2282  for (;;)
2282    
2283        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2284          {          {
2285          if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);          if (eptr >= md->end_subject)
2286          GETCHARINC(c, eptr);            {
2287              SCHECK_PARTIAL();
2288              RRETURN(MATCH_NOMATCH);
2289              }
2290            GETCHARINCTEST(c, eptr);
2291          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);          if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2292          }          }
2293    
# Line 1843  for (;;) Line 2303  for (;;)
2303          {          {
2304          for (fi = min;; fi++)          for (fi = min;; fi++)
2305            {            {
2306            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM20);
2307            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2308            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
2309            GETCHARINC(c, eptr);            if (eptr >= md->end_subject)
2310                {
2311                SCHECK_PARTIAL();
2312                RRETURN(MATCH_NOMATCH);
2313                }
2314              GETCHARINCTEST(c, eptr);
2315            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);            if (!_pcre_xclass(c, data)) RRETURN(MATCH_NOMATCH);
2316            }            }
2317          /* Control never gets here */          /* Control never gets here */
# Line 1861  for (;;) Line 2326  for (;;)
2326            {            {
2327            int len = 1;            int len = 1;
2328            if (eptr >= md->end_subject) break;            if (eptr >= md->end_subject) break;
2329            GETCHARLEN(c, eptr, len);            GETCHARLENTEST(c, eptr, len);
2330            if (!_pcre_xclass(c, data)) break;            if (!_pcre_xclass(c, data)) break;
2331            eptr += len;            eptr += len;
2332            }            }
2333          for(;;)          for(;;)
2334            {            {
2335            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM21);
2336            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2337            if (eptr-- == pp) break;        /* Stop if tried at original pos */            if (eptr-- == pp) break;        /* Stop if tried at original pos */
2338            BACKCHAR(eptr)            if (utf8) BACKCHAR(eptr);
2339            }            }
2340          RRETURN(MATCH_NOMATCH);          RRETURN(MATCH_NOMATCH);
2341          }          }
# Line 1888  for (;;) Line 2353  for (;;)
2353        length = 1;        length = 1;
2354        ecode++;        ecode++;
2355        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2356        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2357            {
2358            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2359            RRETURN(MATCH_NOMATCH);
2360            }
2361        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);        while (length-- > 0) if (*ecode++ != *eptr++) RRETURN(MATCH_NOMATCH);
2362        }        }
2363      else      else
# Line 1896  for (;;) Line 2365  for (;;)
2365    
2366      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2367        {        {
2368        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2369            {
2370            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2371            RRETURN(MATCH_NOMATCH);
2372            }
2373        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);        if (ecode[1] != *eptr++) RRETURN(MATCH_NOMATCH);
2374        ecode += 2;        ecode += 2;
2375        }        }
# Line 1912  for (;;) Line 2385  for (;;)
2385        ecode++;        ecode++;
2386        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
2387    
2388        if (length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);        if (length > md->end_subject - eptr)
2389            {
2390            CHECK_PARTIAL();             /* Not SCHECK_PARTIAL() */
2391            RRETURN(MATCH_NOMATCH);
2392            }
2393    
2394        /* 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
2395        can use the fast lookup table. */        can use the fast lookup table. */
# Line 1926  for (;;) Line 2403  for (;;)
2403    
2404        else        else
2405          {          {
2406          int dc;          unsigned int dc;
2407          GETCHARINC(dc, eptr);          GETCHARINC(dc, eptr);
2408          ecode += length;          ecode += length;
2409    
# Line 1936  for (;;) Line 2413  for (;;)
2413          if (fc != dc)          if (fc != dc)
2414            {            {
2415  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2416            if (dc != _pcre_ucp_othercase(fc))            if (dc != UCD_OTHERCASE(fc))
2417  #endif  #endif
2418              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2419            }            }
# Line 1947  for (;;) Line 2424  for (;;)
2424    
2425      /* Non-UTF-8 mode */      /* Non-UTF-8 mode */
2426        {        {
2427        if (md->end_subject - eptr < 1) RRETURN(MATCH_NOMATCH);        if (md->end_subject - eptr < 1)
2428            {
2429            SCHECK_PARTIAL();            /* This one can use SCHECK_PARTIAL() */
2430            RRETURN(MATCH_NOMATCH);
2431            }
2432        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);        if (md->lcc[ecode[1]] != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2433        ecode += 2;        ecode += 2;
2434        }        }
2435      break;      break;
2436    
2437      /* Match a single character repeatedly; different opcodes share code. */      /* Match a single character repeatedly. */
2438    
2439      case OP_EXACT:      case OP_EXACT:
2440      min = max = GET2(ecode, 1);      min = max = GET2(ecode, 1);
2441      ecode += 3;      ecode += 3;
2442      goto REPEATCHAR;      goto REPEATCHAR;
2443    
2444        case OP_POSUPTO:
2445        possessive = TRUE;
2446        /* Fall through */
2447    
2448      case OP_UPTO:      case OP_UPTO:
2449      case OP_MINUPTO:      case OP_MINUPTO:
2450      min = 0;      min = 0;
# Line 1968  for (;;) Line 2453  for (;;)
2453      ecode += 3;      ecode += 3;
2454      goto REPEATCHAR;      goto REPEATCHAR;
2455    
2456        case OP_POSSTAR:
2457        possessive = TRUE;
2458        min = 0;
2459        max = INT_MAX;
2460        ecode++;
2461        goto REPEATCHAR;
2462    
2463        case OP_POSPLUS:
2464        possessive = TRUE;
2465        min = 1;
2466        max = INT_MAX;
2467        ecode++;
2468        goto REPEATCHAR;
2469    
2470        case OP_POSQUERY:
2471        possessive = TRUE;
2472        min = 0;
2473        max = 1;
2474        ecode++;
2475        goto REPEATCHAR;
2476    
2477      case OP_STAR:      case OP_STAR:
2478      case OP_MINSTAR:      case OP_MINSTAR:
2479      case OP_PLUS:      case OP_PLUS:
# Line 1976  for (;;) Line 2482  for (;;)
2482      case OP_MINQUERY:      case OP_MINQUERY:
2483      c = *ecode++ - OP_STAR;      c = *ecode++ - OP_STAR;
2484      minimize = (c & 1) != 0;      minimize = (c & 1) != 0;
2485    
2486      min = rep_min[c];                 /* Pick up values from tables; */      min = rep_min[c];                 /* Pick up values from tables; */
2487      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2488      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2489    
2490      /* 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. */  
2491    
2492      REPEATCHAR:      REPEATCHAR:
2493  #ifdef SUPPORT_UTF8  #ifdef SUPPORT_UTF8
# Line 1991  for (;;) Line 2496  for (;;)
2496        length = 1;        length = 1;
2497        charptr = ecode;        charptr = ecode;
2498        GETCHARLEN(fc, ecode, length);        GETCHARLEN(fc, ecode, length);
       if (min * length > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2499        ecode += length;        ecode += length;
2500    
2501        /* Handle multibyte character matching specially here. There is        /* Handle multibyte character matching specially here. There is
# Line 1999  for (;;) Line 2503  for (;;)
2503    
2504        if (length > 1)        if (length > 1)
2505          {          {
         int oclength = 0;  
         uschar occhars[8];  
   
2506  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
2507          int othercase;          unsigned int othercase;
2508          if ((ims & PCRE_CASELESS) != 0 &&          if ((ims & PCRE_CASELESS) != 0 &&
2509              (othercase = _pcre_ucp_othercase(fc)) >= 0 &&              (othercase = UCD_OTHERCASE(fc)) != fc)
              othercase >= 0)  
2510            oclength = _pcre_ord2utf8(othercase, occhars);            oclength = _pcre_ord2utf8(othercase, occhars);
2511            else oclength = 0;
2512  #endif  /* SUPPORT_UCP */  #endif  /* SUPPORT_UCP */
2513    
2514          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2515            {            {
2516            if (memcmp(eptr, charptr, length) == 0) eptr += length;            if (eptr <= md->end_subject - length &&
2517            /* Need braces because of following else */              memcmp(eptr, charptr, length) == 0) eptr += length;
2518            else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2519              else if (oclength > 0 &&
2520                       eptr <= md->end_subject - oclength &&
2521                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2522    #endif  /* SUPPORT_UCP */
2523            else            else
2524              {              {
2525              if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);              CHECK_PARTIAL();
2526              eptr += oclength;              RRETURN(MATCH_NOMATCH);
2527              }              }
2528            }            }
2529    
# Line 2028  for (;;) Line 2533  for (;;)
2533            {            {
2534            for (fi = min;; fi++)            for (fi = min;; fi++)
2535              {              {
2536              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM22);
2537              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2538              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2539              if (memcmp(eptr, charptr, length) == 0) eptr += length;              if (eptr <= md->end_subject - length &&
2540              /* Need braces because of following else */                memcmp(eptr, charptr, length) == 0) eptr += length;
2541              else if (oclength == 0) { RRETURN(MATCH_NOMATCH); }  #ifdef SUPPORT_UCP
2542                else if (oclength > 0 &&
2543                         eptr <= md->end_subject - oclength &&
2544                         memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2545    #endif  /* SUPPORT_UCP */
2546              else              else
2547                {                {
2548                if (memcmp(eptr, occhars, oclength) != 0) RRETURN(MATCH_NOMATCH);                CHECK_PARTIAL();
2549                eptr += oclength;                RRETURN(MATCH_NOMATCH);
2550                }                }
2551              }              }
2552            /* Control never gets here */            /* Control never gets here */
2553            }            }
2554          else  
2555            else  /* Maximize */
2556            {            {
2557            pp = eptr;            pp = eptr;
2558            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2559              {              {
2560              if (eptr > md->end_subject - length) break;              if (eptr <= md->end_subject - length &&
2561              if (memcmp(eptr, charptr, length) == 0) eptr += length;                  memcmp(eptr, charptr, length) == 0) eptr += length;
2562              else if (oclength == 0) break;  #ifdef SUPPORT_UCP
2563              else              else if (oclength > 0 &&
2564                {                       eptr <= md->end_subject - oclength &&
2565                if (memcmp(eptr, occhars, oclength) != 0) break;                       memcmp(eptr, occhars, oclength) == 0) eptr += oclength;
2566                eptr += oclength;  #endif  /* SUPPORT_UCP */
2567                }              else break;
2568                }
2569    
2570              if (possessive) continue;
2571    
2572              for(;;)
2573                {
2574                RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM23);
2575                if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2576                if (eptr == pp) { RRETURN(MATCH_NOMATCH); }
2577    #ifdef SUPPORT_UCP
2578                eptr--;
2579                BACKCHAR(eptr);
2580    #else   /* without SUPPORT_UCP */
2581                eptr -= length;
2582    #endif  /* SUPPORT_UCP */
2583              }              }
           while (eptr >= pp)  
            {  
            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);  
            if (rrc != MATCH_NOMATCH) RRETURN(rrc);  
            eptr -= length;  
            }  
           RRETURN(MATCH_NOMATCH);  
2584            }            }
2585          /* Control never gets here */          /* Control never gets here */
2586          }          }
# Line 2075  for (;;) Line 2593  for (;;)
2593  #endif  /* SUPPORT_UTF8 */  #endif  /* SUPPORT_UTF8 */
2594    
2595      /* When not in UTF-8 mode, load a single-byte character. */      /* When not in UTF-8 mode, load a single-byte character. */
2596        {  
2597        if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);      fc = *ecode++;
       fc = *ecode++;  
       }  
2598    
2599      /* 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
2600      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 2612  for (;;)
2612        {        {
2613        fc = md->lcc[fc];        fc = md->lcc[fc];
2614        for (i = 1; i <= min; i++)        for (i = 1; i <= min; i++)
2615            {
2616            if (eptr >= md->end_subject)
2617              {
2618              SCHECK_PARTIAL();
2619              RRETURN(MATCH_NOMATCH);
2620              }
2621          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);          if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2622            }
2623        if (min == max) continue;        if (min == max) continue;
2624        if (minimize)        if (minimize)
2625          {          {
2626          for (fi = min;; fi++)          for (fi = min;; fi++)
2627            {            {
2628            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM24);
2629            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2630            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
2631                fc != md->lcc[*eptr++])            if (eptr >= md->end_subject)
2632                {
2633                SCHECK_PARTIAL();
2634              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2635                }
2636              if (fc != md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2637            }            }
2638          /* Control never gets here */          /* Control never gets here */
2639          }          }
2640        else        else  /* Maximize */
2641          {          {
2642          pp = eptr;          pp = eptr;
2643          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2118  for (;;) Line 2645  for (;;)
2645            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;            if (eptr >= md->end_subject || fc != md->lcc[*eptr]) break;
2646            eptr++;            eptr++;
2647            }            }
2648    
2649            if (possessive) continue;
2650    
2651          while (eptr >= pp)          while (eptr >= pp)
2652            {            {
2653            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM25);
2654            eptr--;            eptr--;
2655            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2656            }            }
# Line 2133  for (;;) Line 2663  for (;;)
2663    
2664      else      else
2665        {        {
2666        for (i = 1; i <= min; i++) if (fc != *eptr++) RRETURN(MATCH_NOMATCH);        for (i = 1; i <= min; i++)
2667            {
2668            if (eptr >= md->end_subject)
2669              {
2670              SCHECK_PARTIAL();
2671              RRETURN(MATCH_NOMATCH);
2672              }
2673            if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2674            }
2675    
2676        if (min == max) continue;        if (min == max) continue;
2677    
2678        if (minimize)        if (minimize)
2679          {          {
2680          for (fi = min;; fi++)          for (fi = min;; fi++)
2681            {            {
2682            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM26);
2683            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2684            if (fi >= max || eptr >= md->end_subject || fc != *eptr++)            if (fi >= max) RRETURN(MATCH_NOMATCH);
2685              if (eptr >= md->end_subject)
2686                {
2687                SCHECK_PARTIAL();
2688              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
2689                }
2690              if (fc != *eptr++) RRETURN(MATCH_NOMATCH);
2691            }            }
2692          /* Control never gets here */          /* Control never gets here */
2693          }          }
2694        else        else  /* Maximize */
2695          {          {
2696          pp = eptr;          pp = eptr;
2697          for (i = min; i < max; i++)          for (i = min; i < max; i++)
# Line 2154  for (;;) Line 2699  for (;;)
2699            if (eptr >= md->end_subject || fc != *eptr) break;            if (eptr >= md->end_subject || fc != *eptr) break;
2700            eptr++;            eptr++;
2701            }            }
2702            if (possessive) continue;
2703    
2704          while (eptr >= pp)          while (eptr >= pp)
2705            {            {
2706            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM27);
2707            eptr--;            eptr--;
2708            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2709            }            }
# Line 2169  for (;;) Line 2716  for (;;)
2716      checking can be multibyte. */      checking can be multibyte. */
2717    
2718      case OP_NOT:      case OP_NOT:
2719      if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);      if (eptr >= md->end_subject)
2720          {
2721          SCHECK_PARTIAL();
2722          RRETURN(MATCH_NOMATCH);
2723          }
2724      ecode++;      ecode++;
2725      GETCHARINCTEST(c, eptr);      GETCHARINCTEST(c, eptr);
2726      if ((ims & PCRE_CASELESS) != 0)      if ((ims & PCRE_CASELESS) != 0)
# Line 2206  for (;;) Line 2757  for (;;)
2757      ecode += 3;      ecode += 3;
2758      goto REPEATNOTCHAR;      goto REPEATNOTCHAR;
2759    
2760        case OP_NOTPOSSTAR:
2761        possessive = TRUE;
2762        min = 0;
2763        max = INT_MAX;
2764        ecode++;
2765        goto REPEATNOTCHAR;
2766    
2767        case OP_NOTPOSPLUS:
2768        possessive = TRUE;
2769        min = 1;
2770        max = INT_MAX;
2771        ecode++;
2772        goto REPEATNOTCHAR;
2773    
2774        case OP_NOTPOSQUERY:
2775        possessive = TRUE;
2776        min = 0;
2777        max = 1;
2778        ecode++;
2779        goto REPEATNOTCHAR;
2780    
2781        case OP_NOTPOSUPTO:
2782        possessive = TRUE;
2783        min = 0;
2784        max = GET2(ecode, 1);
2785        ecode += 3;
2786        goto REPEATNOTCHAR;
2787    
2788      case OP_NOTSTAR:      case OP_NOTSTAR:
2789      case OP_NOTMINSTAR:      case OP_NOTMINSTAR:
2790      case OP_NOTPLUS:      case OP_NOTPLUS:
# Line 2218  for (;;) Line 2797  for (;;)
2797      max = rep_max[c];                 /* zero for max => infinity */      max = rep_max[c];                 /* zero for max => infinity */
2798      if (max == 0) max = INT_MAX;      if (max == 0) max = INT_MAX;
2799    
2800      /* 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. */  
2801    
2802      REPEATNOTCHAR:      REPEATNOTCHAR:
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
2803      fc = *ecode++;      fc = *ecode++;
2804    
2805      /* 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 2821  for (;;)
2821        /* UTF-8 mode */        /* UTF-8 mode */
2822        if (utf8)        if (utf8)
2823          {          {
2824          register int d;          register unsigned int d;
2825          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2826            {            {
2827              if (eptr >= md->end_subject)
2828                {
2829                SCHECK_PARTIAL();
2830                RRETURN(MATCH_NOMATCH);
2831                }
2832            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2833            if (d < 256) d = md->lcc[d];            if (d < 256) d = md->lcc[d];
2834            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
# Line 2259  for (;;) Line 2840  for (;;)
2840        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2841          {          {
2842          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2843              {
2844              if (eptr >= md->end_subject)
2845                {
2846                SCHECK_PARTIAL();
2847                RRETURN(MATCH_NOMATCH);
2848                }
2849            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);            if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2850              }
2851          }          }
2852    
2853        if (min == max) continue;        if (min == max) continue;
# Line 2270  for (;;) Line 2858  for (;;)
2858          /* UTF-8 mode */          /* UTF-8 mode */
2859          if (utf8)          if (utf8)
2860            {            {
2861            register int d;            register unsigned int d;
2862            for (fi = min;; fi++)            for (fi = min;; fi++)
2863              {              {
2864              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM28);
2865              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2866                if (fi >= max) RRETURN(MATCH_NOMATCH);
2867                if (eptr >= md->end_subject)
2868                  {
2869                  SCHECK_PARTIAL();
2870                  RRETURN(MATCH_NOMATCH);
2871                  }
2872              GETCHARINC(d, eptr);              GETCHARINC(d, eptr);
2873              if (d < 256) d = md->lcc[d];              if (d < 256) d = md->lcc[d];
2874              if (fi >= max || eptr >= md->end_subject || fc == d)              if (fc == d) RRETURN(MATCH_NOMATCH);
               RRETURN(MATCH_NOMATCH);  
2875              }              }
2876            }            }
2877          else          else
# Line 2287  for (;;) Line 2880  for (;;)
2880            {            {
2881            for (fi = min;; fi++)            for (fi = min;; fi++)
2882              {              {
2883              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM29);
2884              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2885              if (fi >= max || eptr >= md->end_subject || fc == md->lcc[*eptr++])              if (fi >= max) RRETURN(MATCH_NOMATCH);
2886                if (eptr >= md->end_subject)
2887                  {
2888                  SCHECK_PARTIAL();
2889                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
2890                  }
2891                if (fc == md->lcc[*eptr++]) RRETURN(MATCH_NOMATCH);
2892              }              }
2893            }            }
2894          /* Control never gets here */          /* Control never gets here */
# Line 2306  for (;;) Line 2904  for (;;)
2904          /* UTF-8 mode */          /* UTF-8 mode */
2905          if (utf8)          if (utf8)
2906            {            {
2907            register int d;            register unsigned int d;
2908            for (i = min; i < max; i++)            for (i = min; i < max; i++)
2909              {              {
2910              int len = 1;              int len = 1;
# Line 2316  for (;;) Line 2914  for (;;)
2914              if (fc == d) break;              if (fc == d) break;
2915              eptr += len;              eptr += len;
2916              }              }
2917            for(;;)          if (possessive) continue;
2918            for(;;)
2919              {              {
2920              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM30);
2921              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2922              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
2923              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2333  for (;;) Line 2932  for (;;)
2932              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;              if (eptr >= md->end_subject || fc == md->lcc[*eptr]) break;
2933              eptr++;              eptr++;
2934              }              }
2935              if (possessive) continue;
2936            while (eptr >= pp)            while (eptr >= pp)
2937              {              {
2938              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM31);
2939              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2940              eptr--;              eptr--;
2941              }              }
# Line 2354  for (;;) Line 2954  for (;;)
2954        /* UTF-8 mode */        /* UTF-8 mode */
2955        if (utf8)        if (utf8)
2956          {          {
2957          register int d;          register unsigned int d;
2958          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2959            {            {
2960              if (eptr >= md->end_subject)
2961                {
2962                SCHECK_PARTIAL();
2963                RRETURN(MATCH_NOMATCH);
2964                }
2965            GETCHARINC(d, eptr);            GETCHARINC(d, eptr);
2966            if (fc == d) RRETURN(MATCH_NOMATCH);            if (fc == d) RRETURN(MATCH_NOMATCH);
2967            }            }
# Line 2366  for (;;) Line 2971  for (;;)
2971        /* Not UTF-8 mode */        /* Not UTF-8 mode */
2972          {          {
2973          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
2974              {
2975              if (eptr >= md->end_subject)
2976                {
2977                SCHECK_PARTIAL();
2978                RRETURN(MATCH_NOMATCH);
2979                }
2980            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);            if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
2981              }
2982          }          }
2983    
2984        if (min == max) continue;        if (min == max) continue;
# Line 2377  for (;;) Line 2989  for (;;)
2989          /* UTF-8 mode */          /* UTF-8 mode */
2990          if (utf8)          if (utf8)
2991            {            {
2992            register int d;            register unsigned int d;
2993            for (fi = min;; fi++)            for (fi = min;; fi++)
2994              {              {
2995              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM32);
2996              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
2997              GETCHARINC(d, eptr);              if (fi >= max) RRETURN(MATCH_NOMATCH);
2998              if (fi >= max || eptr >= md->end_subject || fc == d)              if (eptr >= md->end_subject)
2999                  {
3000                  SCHECK_PARTIAL();
3001                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3002                  }
3003                GETCHARINC(d, eptr);
3004                if (fc == d) RRETURN(MATCH_NOMATCH);
3005              }              }
3006            }            }
3007          else          else
# Line 2393  for (;;) Line 3010  for (;;)
3010            {            {
3011            for (fi = min;; fi++)            for (fi = min;; fi++)
3012              {              {
3013              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM33);
3014              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3015              if (fi >= max || eptr >= md->end_subject || fc == *eptr++)              if (fi >= max) RRETURN(MATCH_NOMATCH);
3016                if (eptr >= md->end_subject)
3017                  {
3018                  SCHECK_PARTIAL();
3019                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3020                  }
3021                if (fc == *eptr++) RRETURN(MATCH_NOMATCH);
3022              }              }
3023            }            }
3024          /* Control never gets here */          /* Control never gets here */
# Line 2412  for (;;) Line 3034  for (;;)
3034          /* UTF-8 mode */          /* UTF-8 mode */
3035          if (utf8)          if (utf8)
3036            {            {
3037            register int d;            register unsigned int d;
3038            for (i = min; i < max; i++)            for (i = min; i < max; i++)
3039              {              {
3040              int len = 1;              int len = 1;
# Line 2421  for (;;) Line 3043  for (;;)
3043              if (fc == d) break;              if (fc == d) break;
3044              eptr += len;              eptr += len;
3045              }              }
3046              if (possessive) continue;
3047            for(;;)            for(;;)
3048              {              {
3049              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM34);
3050              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3051              if (eptr-- == pp) break;        /* Stop if tried at original pos */              if (eptr-- == pp) break;        /* Stop if tried at original pos */
3052              BACKCHAR(eptr);              BACKCHAR(eptr);
# Line 2438  for (;;) Line 3061  for (;;)
3061              if (eptr >= md->end_subject || fc == *eptr) break;              if (eptr >= md->end_subject || fc == *eptr) break;
3062              eptr++;              eptr++;
3063              }              }
3064              if (possessive) continue;
3065            while (eptr >= pp)            while (eptr >= pp)
3066              {              {
3067              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM35);
3068              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3069              eptr--;              eptr--;
3070              }              }
# Line 2469  for (;;) Line 3093  for (;;)
3093      ecode += 3;      ecode += 3;
3094      goto REPEATTYPE;      goto REPEATTYPE;
3095    
3096        case OP_TYPEPOSSTAR:
3097        possessive = TRUE;
3098        min = 0;
3099        max = INT_MAX;
3100        ecode++;
3101        goto REPEATTYPE;
3102    
3103        case OP_TYPEPOSPLUS:
3104        possessive = TRUE;
3105        min = 1;
3106        max = INT_MAX;
3107        ecode++;
3108        goto REPEATTYPE;
3109    
3110        case OP_TYPEPOSQUERY:
3111        possessive = TRUE;
3112        min = 0;
3113        max = 1;
3114        ecode++;
3115        goto REPEATTYPE;
3116    
3117        case OP_TYPEPOSUPTO:
3118        possessive = TRUE;
3119        min = 0;
3120        max = GET2(ecode, 1);
3121        ecode += 3;
3122        goto REPEATTYPE;
3123    
3124      case OP_TYPESTAR:      case OP_TYPESTAR:
3125      case OP_TYPEMINSTAR:      case OP_TYPEMINSTAR:
3126      case OP_TYPEPLUS:      case OP_TYPEPLUS:
# Line 2500  for (;;) Line 3152  for (;;)
3152    
3153      /* First, ensure the minimum number of matches are present. Use inline      /* First, ensure the minimum number of matches are present. Use inline
3154      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
3155      (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  
3156      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
3157      and single-bytes. */      and single-bytes. */
3158    
     if (min > md->end_subject - eptr) RRETURN(MATCH_NOMATCH);  
3159      if (min > 0)      if (min > 0)
3160        {        {
3161  #ifdef SUPPORT_UCP  #ifdef SUPPORT_UCP
# Line 2518  for (;;) Line 3167  for (;;)
3167            if (prop_fail_result) RRETURN(MATCH_NOMATCH);            if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3168            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3169              {              {
3170              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3171              GETCHARINC(c, eptr);                {
3172                  SCHECK_PARTIAL();
3173                  RRETURN(MATCH_NOMATCH);
3174                  }
3175                GETCHARINCTEST(c, eptr);
3176              }              }
3177            break;            break;
3178    
3179            case PT_LAMP:            case PT_LAMP:
3180            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3181              {              {
3182              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3183              GETCHARINC(c, eptr);                {
3184              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3185                  RRETURN(MATCH_NOMATCH);
3186                  }
3187                GETCHARINCTEST(c, eptr);
3188                prop_chartype = UCD_CHARTYPE(c);
3189              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3190                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3191                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
# Line 2539  for (;;) Line 3196  for (;;)
3196            case PT_GC:            case PT_GC:
3197            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3198              {              {
3199              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3200              GETCHARINC(c, eptr);                {
3201              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3202                  RRETURN(MATCH_NOMATCH);
3203                  }
3204                GETCHARINCTEST(c, eptr);
3205                prop_category = UCD_CATEGORY(c);
3206              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3207                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3208              }              }
# Line 2550  for (;;) Line 3211  for (;;)
3211            case PT_PC:            case PT_PC:
3212            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3213              {              {
3214              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3215              GETCHARINC(c, eptr);                {
3216              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3217                  RRETURN(MATCH_NOMATCH);
3218                  }
3219                GETCHARINCTEST(c, eptr);
3220                prop_chartype = UCD_CHARTYPE(c);
3221              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3222                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3223              }              }
# Line 2561  for (;;) Line 3226  for (;;)
3226            case PT_SC:            case PT_SC:
3227            for (i = 1; i <= min; i++)            for (i = 1; i <= min; i++)
3228              {              {
3229              if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (eptr >= md->end_subject)
3230              GETCHARINC(c, eptr);                {
3231              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);                SCHECK_PARTIAL();
3232                  RRETURN(MATCH_NOMATCH);
3233                  }
3234                GETCHARINCTEST(c, eptr);
3235                prop_script = UCD_SCRIPT(c);
3236              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3237                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3238              }              }
# Line 2571  for (;;) Line 3240  for (;;)
3240    
3241            default:            default:
3242            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3243            }            }
3244          }          }
3245    
# Line 2582  for (;;) Line 3250  for (;;)
3250          {          {
3251          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3252            {            {
3253              if (eptr >= md->end_subject)
3254                {
3255                SCHECK_PARTIAL();
3256                RRETURN(MATCH_NOMATCH);
3257                }
3258            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3259            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3260            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3261            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3262              {              {
3263              int len = 1;              int len = 1;
3264              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3265                {                else { GETCHARLEN(c, eptr, len); }
3266                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3267              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3268              eptr += len;              eptr += len;
3269              }              }
# Line 2610  for (;;) Line 3281  for (;;)
3281          case OP_ANY:          case OP_ANY:
3282          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3283            {            {
3284            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3285                 ((ims & PCRE_DOTALL) == 0 &&              {
3286                   eptr <= md->end_subject - md->nllen &&              SCHECK_PARTIAL();
3287                   IS_NEWLINE(eptr)))              RRETURN(MATCH_NOMATCH);
3288                }
3289              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3290              eptr++;
3291              while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3292              }
3293            break;
3294    
3295            case OP_ALLANY:
3296            for (i = 1; i <= min; i++)
3297              {
3298              if (eptr >= md->end_subject)
3299                {
3300                SCHECK_PARTIAL();
3301              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3302                }
3303            eptr++;            eptr++;
3304            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;
3305            }            }
3306          break;          break;
3307    
3308          case OP_ANYBYTE:          case OP_ANYBYTE:
3309            if (eptr > md->end_subject - min) RRETURN(MATCH_NOMATCH);
3310          eptr += min;          eptr += min;
3311          break;          break;
3312    
3313          case OP_NOT_DIGIT:          case OP_ANYNL:
3314          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3315            {            {
3316            if (eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (eptr >= md->end_subject)
3317            GETCHARINC(c, eptr);              {
3318            if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)              SCHECK_PARTIAL();
3319              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3320                }
3321              GETCHARINC(c, eptr);
3322              switch(c)
3323                {
3324                default: RRETURN(MATCH_NOMATCH);
3325                case 0x000d:
3326                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3327                break;
3328    
3329                case 0x000a:
3330                break;
3331    
3332                case 0x000b:
3333                case 0x000c:
3334                case 0x0085:
3335                case 0x2028:
3336                case 0x2029:
3337                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3338                break;
3339                }
3340            }            }
3341          break;          break;
3342    
3343          case OP_DIGIT:          case OP_NOT_HSPACE:
3344          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3345            {            {
3346            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3347               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)              {
3348                SCHECK_PARTIAL();
3349              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3350            /* No need to skip more bytes - we know it's a 1-byte character */              }
3351              GETCHARINC(c, eptr);
3352              switch(c)
3353                {
3354                default: break;
3355                case 0x09:      /* HT */
3356                case 0x20:      /* SPACE */
3357                case 0xa0:      /* NBSP */
3358                case 0x1680:    /* OGHAM SPACE MARK */
3359                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3360                case 0x2000:    /* EN QUAD */
3361                case 0x2001:    /* EM QUAD */
3362                case 0x2002:    /* EN SPACE */
3363                case 0x2003:    /* EM SPACE */
3364                case 0x2004:    /* THREE-PER-EM SPACE */
3365                case 0x2005:    /* FOUR-PER-EM SPACE */
3366                case 0x2006:    /* SIX-PER-EM SPACE */
3367                case 0x2007:    /* FIGURE SPACE */
3368                case 0x2008:    /* PUNCTUATION SPACE */
3369                case 0x2009:    /* THIN SPACE */
3370                case 0x200A:    /* HAIR SPACE */
3371                case 0x202f:    /* NARROW NO-BREAK SPACE */
3372                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3373                case 0x3000:    /* IDEOGRAPHIC SPACE */
3374                RRETURN(MATCH_NOMATCH);
3375                }
3376            }            }
3377          break;          break;
3378    
3379          case OP_NOT_WHITESPACE:          case OP_HSPACE:
3380          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3381            {            {
3382            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3383               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_space) != 0))              {
3384                SCHECK_PARTIAL();
3385              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3386            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3387              GETCHARINC(c, eptr);
3388              switch(c)
3389                {
3390                default: RRETURN(MATCH_NOMATCH);
3391                case 0x09:      /* HT */
3392                case 0x20:      /* SPACE */
3393                case 0xa0:      /* NBSP */
3394                case 0x1680:    /* OGHAM SPACE MARK */
3395                case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3396                case 0x2000:    /* EN QUAD */
3397                case 0x2001:    /* EM QUAD */
3398                case 0x2002:    /* EN SPACE */
3399                case 0x2003:    /* EM SPACE */
3400                case 0x2004:    /* THREE-PER-EM SPACE */
3401                case 0x2005:    /* FOUR-PER-EM SPACE */
3402                case 0x2006:    /* SIX-PER-EM SPACE */
3403                case 0x2007:    /* FIGURE SPACE */
3404                case 0x2008:    /* PUNCTUATION SPACE */
3405                case 0x2009:    /* THIN SPACE */
3406                case 0x200A:    /* HAIR SPACE */
3407                case 0x202f:    /* NARROW NO-BREAK SPACE */
3408                case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3409                case 0x3000:    /* IDEOGRAPHIC SPACE */
3410                break;
3411                }
3412            }            }
3413          break;          break;
3414    
3415          case OP_WHITESPACE:          case OP_NOT_VSPACE:
3416          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3417            {            {
3418            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3419               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)              {
3420                SCHECK_PARTIAL();
3421              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3422            /* No need to skip more bytes - we know it's a 1-byte character */              }
3423              GETCHARINC(c, eptr);
3424              switch(c)
3425                {
3426                default: break;
3427                case 0x0a:      /* LF */
3428                case 0x0b:      /* VT */
3429                case 0x0c:      /* FF */
3430                case 0x0d:      /* CR */
3431                case 0x85:      /* NEL */
3432                case 0x2028:    /* LINE SEPARATOR */
3433                case 0x2029:    /* PARAGRAPH SEPARATOR */
3434                RRETURN(MATCH_NOMATCH);
3435                }
3436            }            }
3437          break;          break;
3438    
3439          case OP_NOT_WORDCHAR:          case OP_VSPACE:
3440          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3441            {            {
3442            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject)
3443               (*eptr < 128 && (md->ctypes[*eptr++] & ctype_word) != 0))              {
3444                SCHECK_PARTIAL();
3445              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3446            while (eptr < md->end_subject && (*eptr & 0xc0) == 0x80) eptr++;              }
3447              GETCHARINC(c, eptr);
3448              switch(c)
3449                {
3450                default: RRETURN(MATCH_NOMATCH);
3451                case 0x0a:      /* LF */
3452                case 0x0b:      /* VT */
3453                case 0x0c:      /* FF */
3454                case 0x0d:      /* CR */
3455                case 0x85:      /* NEL */
3456                case 0x2028:    /* LINE SEPARATOR */
3457                case 0x2029:    /* PARAGRAPH SEPARATOR */
3458                break;
3459                }
3460            }            }
3461          break;          break;
3462    
3463          case OP_WORDCHAR:          case OP_NOT_DIGIT:
3464            for (i = 1; i <= min; i++)
3465              {
3466              if (eptr >= md->end_subject)
3467                {
3468                SCHECK_PARTIAL();
3469                RRETURN(MATCH_NOMATCH);
3470                }
3471              GETCHARINC(c, eptr);
3472              if (c < 128 && (md->ctypes[c] & ctype_digit) != 0)
3473                RRETURN(MATCH_NOMATCH);
3474              }
3475            break;
3476    
3477            case OP_DIGIT:
3478            for (i = 1; i <= min; i++)
3479              {
3480              if (eptr >= md->end_subject)
3481                {
3482                SCHECK_PARTIAL();
3483                RRETURN(MATCH_NOMATCH);
3484                }
3485              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_digit) == 0)
3486                RRETURN(MATCH_NOMATCH);
3487              /* No need to skip more bytes - we know it's a 1-byte character */
3488              }
3489            break;
3490    
3491            case OP_NOT_WHITESPACE:
3492            for (i = 1; i <= min; i++)
3493              {
3494              if (eptr >= md->end_subject)
3495                {
3496                SCHECK_PARTIAL();
3497                RRETURN(MATCH_NOMATCH);
3498                }
3499              if (*eptr < 128 && (md->ctypes[*eptr] & ctype_space) != 0)
3500                RRETURN(MATCH_NOMATCH);
3501              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3502              }
3503            break;
3504    
3505            case OP_WHITESPACE:
3506            for (i = 1; i <= min; i++)
3507              {
3508              if (eptr >= md->end_subject)
3509                {
3510                SCHECK_PARTIAL();
3511                RRETURN(MATCH_NOMATCH);
3512                }
3513              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_space) == 0)
3514                RRETURN(MATCH_NOMATCH);
3515              /* No need to skip more bytes - we know it's a 1-byte character */
3516              }
3517            break;
3518    
3519            case OP_NOT_WORDCHAR:
3520          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3521            {            {
3522            if (eptr >= md->end_subject ||            if (eptr >= md->end_subject ||
3523               *eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)               (*eptr < 128 && (md->ctypes[*eptr] & ctype_word) != 0))
3524                RRETURN(MATCH_NOMATCH);
3525              while (++eptr < md->end_subject && (*eptr & 0xc0) == 0x80);
3526              }
3527            break;
3528    
3529            case OP_WORDCHAR:
3530            for (i = 1; i <= min; i++)
3531              {
3532              if (eptr >= md->end_subject)
3533                {
3534                SCHECK_PARTIAL();
3535                RRETURN(MATCH_NOMATCH);
3536                }
3537              if (*eptr >= 128 || (md->ctypes[*eptr++] & ctype_word) == 0)
3538              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3539            /* No need to skip more bytes - we know it's a 1-byte character */            /* No need to skip more bytes - we know it's a 1-byte character */
3540            }            }
# Line 2697  for (;;) Line 3553  for (;;)
3553        switch(ctype)        switch(ctype)
3554          {          {
3555          case OP_ANY:          case OP_ANY:
3556          if ((ims & PCRE_DOTALL) == 0)          for (i = 1; i <= min; i++)
3557            {            {
3558            for (i = 1; i <= min; i++)            if (eptr >= md->end_subject)
3559              {              {
3560              if (eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr))              SCHECK_PARTIAL();
3561                RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
             eptr++;  
3562              }              }
3563              if (IS_NEWLINE(eptr)) RRETURN(MATCH_NOMATCH);
3564              eptr++;
3565              }
3566            break;
3567    
3568            case OP_ALLANY:
3569            if (eptr > md->end_subject - min)
3570              {
3571              SCHECK_PARTIAL();
3572              RRETURN(MATCH_NOMATCH);
3573            }            }
3574          else eptr += min;          eptr += min;
3575          break;          break;
3576    
3577          case OP_ANYBYTE:          case OP_ANYBYTE:
3578            if (eptr > md->end_subject - min)
3579              {
3580              SCHECK_PARTIAL();
3581              RRETURN(MATCH_NOMATCH);
3582              }
3583          eptr += min;          eptr += min;
3584          break;          break;
3585    
3586            case OP_ANYNL:
3587            for (i = 1; i <= min; i++)
3588              {
3589              if (eptr >= md->end_subject)
3590                {
3591                SCHECK_PARTIAL();
3592                RRETURN(MATCH_NOMATCH);
3593                }
3594              switch(*eptr++)
3595                {
3596                default: RRETURN(MATCH_NOMATCH);
3597                case 0x000d:
3598                if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3599                break;
3600                case 0x000a:
3601                break;
3602    
3603                case 0x000b:
3604                case 0x000c:
3605                case 0x0085:
3606                if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3607                break;
3608                }
3609              }
3610            break;
3611    
3612            case OP_NOT_HSPACE:
3613            for (i = 1; i <= min; i++)
3614              {
3615              if (eptr >= md->end_subject)
3616                {
3617                SCHECK_PARTIAL();
3618                RRETURN(MATCH_NOMATCH);
3619                }
3620              switch(*eptr++)
3621                {
3622                default: break;
3623                case 0x09:      /* HT */
3624                case 0x20:      /* SPACE */
3625                case 0xa0:      /* NBSP */
3626                RRETURN(MATCH_NOMATCH);
3627                }
3628              }
3629            break;
3630    
3631            case OP_HSPACE:
3632            for (i = 1; i <= min; i++)
3633              {
3634              if (eptr >= md->end_subject)
3635                {
3636                SCHECK_PARTIAL();
3637                RRETURN(MATCH_NOMATCH);
3638                }
3639              switch(*eptr++)
3640                {
3641                default: RRETURN(MATCH_NOMATCH);
3642                case 0x09:      /* HT */
3643                case 0x20:      /* SPACE */
3644                case 0xa0:      /* NBSP */
3645                break;
3646                }
3647              }
3648            break;
3649    
3650            case OP_NOT_VSPACE:
3651            for (i = 1; i <= min; i++)
3652              {
3653              if (eptr >= md->end_subject)
3654                {
3655                SCHECK_PARTIAL();
3656                RRETURN(MATCH_NOMATCH);
3657                }
3658              switch(*eptr++)
3659                {
3660                default: break;
3661                case 0x0a:      /* LF */
3662                case 0x0b:      /* VT */
3663                case 0x0c:      /* FF */
3664                case 0x0d:      /* CR */
3665                case 0x85:      /* NEL */
3666                RRETURN(MATCH_NOMATCH);
3667                }
3668              }
3669            break;
3670    
3671            case OP_VSPACE:
3672            for (i = 1; i <= min; i++)
3673              {
3674              if (eptr >= md->end_subject)
3675                {
3676                SCHECK_PARTIAL();
3677                RRETURN(MATCH_NOMATCH);
3678                }
3679              switch(*eptr++)
3680                {
3681                default: RRETURN(MATCH_NOMATCH);
3682                case 0x0a:      /* LF */
3683                case 0x0b:      /* VT */
3684                case 0x0c:      /* FF */
3685                case 0x0d:      /* CR */
3686                case 0x85:      /* NEL */
3687                break;
3688                }
3689              }
3690            break;
3691    
3692          case OP_NOT_DIGIT:          case OP_NOT_DIGIT:
3693          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3694              {
3695              if (eptr >= md->end_subject)
3696                {
3697                SCHECK_PARTIAL();
3698                RRETURN(MATCH_NOMATCH);
3699                }
3700            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) != 0) RRETURN(MATCH_NOMATCH);
3701              }
3702          break;          break;
3703    
3704          case OP_DIGIT:          case OP_DIGIT:
3705          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3706              {
3707              if (eptr >= md->end_subject)
3708                {
3709                SCHECK_PARTIAL();
3710                RRETURN(MATCH_NOMATCH);
3711                }
3712            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_digit) == 0) RRETURN(MATCH_NOMATCH);
3713              }
3714          break;          break;
3715    
3716          case OP_NOT_WHITESPACE:          case OP_NOT_WHITESPACE:
3717          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3718              {
3719              if (eptr >= md->end_subject)
3720                {
3721                SCHECK_PARTIAL();
3722                RRETURN(MATCH_NOMATCH);
3723                }
3724            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) != 0) RRETURN(MATCH_NOMATCH);
3725              }
3726          break;          break;
3727    
3728          case OP_WHITESPACE:          case OP_WHITESPACE:
3729          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3730              {
3731              if (eptr >= md->end_subject)
3732                {
3733                SCHECK_PARTIAL();
3734                RRETURN(MATCH_NOMATCH);
3735                }
3736            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);            if ((md->ctypes[*eptr++] & ctype_space) == 0) RRETURN(MATCH_NOMATCH);
3737              }
3738          break;          break;
3739    
3740          case OP_NOT_WORDCHAR:          case OP_NOT_WORDCHAR:
3741          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3742              {
3743              if (eptr >= md->end_subject)
3744                {
3745                SCHECK_PARTIAL();
3746                RRETURN(MATCH_NOMATCH);
3747                }
3748            if ((md->ctypes[*eptr++] & ctype_word) != 0)            if ((md->ctypes[*eptr++] & ctype_word) != 0)
3749              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3750              }
3751          break;          break;
3752    
3753          case OP_WORDCHAR:          case OP_WORDCHAR:
3754          for (i = 1; i <= min; i++)          for (i = 1; i <= min; i++)
3755              {
3756              if (eptr >= md->end_subject)
3757                {
3758                SCHECK_PARTIAL();
3759                RRETURN(MATCH_NOMATCH);
3760                }
3761            if ((md->ctypes[*eptr++] & ctype_word) == 0)            if ((md->ctypes[*eptr++] & ctype_word) == 0)
3762              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
3763              }
3764          break;          break;
3765    
3766          default:          default:
# Line 2768  for (;;) Line 3786  for (;;)
3786            case PT_ANY:            case PT_ANY:
3787            for (fi = min;; fi++)            for (fi = min;; fi++)
3788              {              {
3789              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM36);
3790              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3791              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3792                if (eptr >= md->end_subject)
3793                  {
3794                  SCHECK_PARTIAL();
3795                  RRETURN(MATCH_NOMATCH);
3796                  }
3797              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3798              if (prop_fail_result) RRETURN(MATCH_NOMATCH);              if (prop_fail_result) RRETURN(MATCH_NOMATCH);
3799              }              }
3800            break;            /* Control never gets here */
3801    
3802            case PT_LAMP:            case PT_LAMP:
3803            for (fi = min;; fi++)            for (fi = min;; fi++)
3804              {              {
3805              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM37);
3806              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3807              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3808                if (eptr >= md->end_subject)
3809                  {
3810                  SCHECK_PARTIAL();
3811                  RRETURN(MATCH_NOMATCH);
3812                  }
3813              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3814              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3815              if ((prop_chartype == ucp_Lu ||              if ((prop_chartype == ucp_Lu ||
3816                   prop_chartype == ucp_Ll ||                   prop_chartype == ucp_Ll ||
3817                   prop_chartype == ucp_Lt) == prop_fail_result)                   prop_chartype == ucp_Lt) == prop_fail_result)
3818                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3819              }              }
3820            break;            /* Control never gets here */
3821    
3822            case PT_GC:            case PT_GC:
3823            for (fi = min;; fi++)            for (fi = min;; fi++)
3824              {              {
3825              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM38);
3826              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3827              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3828                if (eptr >= md->end_subject)
3829                  {
3830                  SCHECK_PARTIAL();
3831                  RRETURN(MATCH_NOMATCH);
3832                  }
3833              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3834              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_category = UCD_CATEGORY(c);
3835              if ((prop_category == prop_value) == prop_fail_result)              if ((prop_category == prop_value) == prop_fail_result)
3836                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3837              }              }
3838            break;            /* Control never gets here */
3839    
3840            case PT_PC:            case PT_PC:
3841            for (fi = min;; fi++)            for (fi = min;; fi++)
3842              {              {
3843              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM39);
3844              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3845              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3846                if (eptr >= md->end_subject)
3847                  {
3848                  SCHECK_PARTIAL();
3849                  RRETURN(MATCH_NOMATCH);
3850                  }
3851              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3852              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_chartype = UCD_CHARTYPE(c);
3853              if ((prop_chartype == prop_value) == prop_fail_result)              if ((prop_chartype == prop_value) == prop_fail_result)
3854                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3855              }              }
3856            break;            /* Control never gets here */
3857    
3858            case PT_SC:            case PT_SC:
3859            for (fi = min;; fi++)            for (fi = min;; fi++)
3860              {              {
3861              RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);              RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM40);
3862              if (rrc != MATCH_NOMATCH) RRETURN(rrc);              if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3863              if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);              if (fi >= max) RRETURN(MATCH_NOMATCH);
3864                if (eptr >= md->end_subject)
3865                  {
3866                  SCHECK_PARTIAL();
3867                  RRETURN(MATCH_NOMATCH);
3868                  }
3869              GETCHARINC(c, eptr);              GETCHARINC(c, eptr);
3870              prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);              prop_script = UCD_SCRIPT(c);
3871              if ((prop_script == prop_value) == prop_fail_result)              if ((prop_script == prop_value) == prop_fail_result)
3872                RRETURN(MATCH_NOMATCH);                RRETURN(MATCH_NOMATCH);
3873              }              }
3874            break;            /* Control never gets here */
3875    
3876            default:            default:
3877            RRETURN(PCRE_ERROR_INTERNAL);            RRETURN(PCRE_ERROR_INTERNAL);
           break;  
3878            }            }
3879          }          }
3880    
# Line 2843  for (;;) Line 3885  for (;;)
3885          {          {
3886          for (fi = min;; fi++)          for (fi = min;; fi++)
3887            {            {
3888            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM41);
3889            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3890            if (fi >= max || eptr >= md->end_subject) RRETURN(MATCH_NOMATCH);            if (fi >= max) RRETURN(MATCH_NOMATCH);
3891              if (eptr >= md->end_subject)
3892                {
3893                SCHECK_PARTIAL();
3894                RRETURN(MATCH_NOMATCH);
3895                }
3896            GETCHARINCTEST(c, eptr);            GETCHARINCTEST(c, eptr);
3897            prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);            prop_category = UCD_CATEGORY(c);
3898            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);            if (prop_category == ucp_M) RRETURN(MATCH_NOMATCH);
3899            while (eptr < md->end_subject)            while (eptr < md->end_subject)
3900              {              {
3901              int len = 1;              int len = 1;
3902              if (!utf8) c = *eptr; else              if (!utf8) c = *eptr;
3903                {                else { GETCHARLEN(c, eptr, len); }
3904                GETCHARLEN(c, eptr, len);              prop_category = UCD_CATEGORY(c);
               }  
             prop_category = _pcre_ucp_findprop(c, &prop_chartype, &prop_script);  
3905              if (prop_category != ucp_M) break;              if (prop_category != ucp_M) break;
3906              eptr += len;              eptr += len;
3907              }              }
# Line 2872  for (;;) Line 3917  for (;;)
3917          {          {
3918          for (fi = min;; fi++)          for (fi = min;; fi++)
3919            {            {
3920            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM42);
3921            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
3922            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
3923                 (ctype == OP_ANY && (ims & PCRE_DOTALL) == 0 &&            if (eptr >= md->end_subject)
3924                  eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))              {
3925                SCHECK_PARTIAL();
3926                RRETURN(MATCH_NOMATCH);
3927                }
3928              if (ctype == OP_ANY && IS_NEWLINE(eptr))
3929              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
3930            GETCHARINC(c, eptr);            GETCHARINC(c, eptr);
3931            switch(ctype)            switch(ctype)
3932              {              {
3933              case OP_ANY:        /* This is the DOTALL case */              case OP_ANY:        /* This is the non-NL case */
3934                case OP_ALLANY:
3935                case OP_ANYBYTE:
3936              break;              break;
3937    
3938              case OP_ANYBYTE:              case OP_ANYNL:
3939                switch(c)
3940                  {
3941                  default: RRETURN(MATCH_NOMATCH);
3942                  case 0x000d:
3943                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
3944                  break;
3945                  case 0x000a:
3946                  break;
3947    
3948                  case 0x000b:
3949                  case 0x000c:
3950                  case 0x0085:
3951                  case 0x2028:
3952                  case 0x2029:
3953                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
3954                  break;
3955                  }
3956                break;
3957    
3958                case OP_NOT_HSPACE:
3959                switch(c)
3960                  {
3961                  default: break;
3962                  case 0x09:      /* HT */
3963                  case 0x20:      /* SPACE */
3964                  case 0xa0:      /* NBSP */
3965                  case 0x1680:    /* OGHAM SPACE MARK */
3966                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3967                  case 0x2000:    /* EN QUAD */
3968                  case 0x2001:    /* EM QUAD */
3969                  case 0x2002:    /* EN SPACE */
3970                  case 0x2003:    /* EM SPACE */
3971                  case 0x2004:    /* THREE-PER-EM SPACE */
3972                  case 0x2005:    /* FOUR-PER-EM SPACE */
3973                  case 0x2006:    /* SIX-PER-EM SPACE */
3974                  case 0x2007:    /* FIGURE SPACE */
3975                  case 0x2008:    /* PUNCTUATION SPACE */
3976                  case 0x2009:    /* THIN SPACE */
3977                  case 0x200A:    /* HAIR SPACE */
3978                  case 0x202f:    /* NARROW NO-BREAK SPACE */
3979                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
3980                  case 0x3000:    /* IDEOGRAPHIC SPACE */
3981                  RRETURN(MATCH_NOMATCH);
3982                  }
3983                break;
3984    
3985                case OP_HSPACE:
3986                switch(c)
3987                  {
3988                  default: RRETURN(MATCH_NOMATCH);
3989                  case 0x09:      /* HT */
3990                  case 0x20:      /* SPACE */
3991                  case 0xa0:      /* NBSP */
3992                  case 0x1680:    /* OGHAM SPACE MARK */
3993                  case 0x180e:    /* MONGOLIAN VOWEL SEPARATOR */
3994                  case 0x2000:    /* EN QUAD */
3995                  case 0x2001:    /* EM QUAD */
3996                  case 0x2002:    /* EN SPACE */
3997                  case 0x2003:    /* EM SPACE */
3998                  case 0x2004:    /* THREE-PER-EM SPACE */
3999                  case 0x2005:    /* FOUR-PER-EM SPACE */
4000                  case 0x2006:    /* SIX-PER-EM SPACE */
4001                  case 0x2007:    /* FIGURE SPACE */
4002                  case 0x2008:    /* PUNCTUATION SPACE */
4003                  case 0x2009:    /* THIN SPACE */
4004                  case 0x200A:    /* HAIR SPACE */
4005                  case 0x202f:    /* NARROW NO-BREAK SPACE */
4006                  case 0x205f:    /* MEDIUM MATHEMATICAL SPACE */
4007                  case 0x3000:    /* IDEOGRAPHIC SPACE */
4008                  break;
4009                  }
4010                break;
4011    
4012                case OP_NOT_VSPACE:
4013                switch(c)
4014                  {
4015                  default: break;
4016                  case 0x0a:      /* LF */
4017                  case 0x0b:      /* VT */
4018                  case 0x0c:      /* FF */
4019                  case 0x0d:      /* CR */
4020                  case 0x85:      /* NEL */
4021                  case 0x2028:    /* LINE SEPARATOR */
4022                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4023                  RRETURN(MATCH_NOMATCH);
4024                  }
4025                break;
4026    
4027                case OP_VSPACE:
4028                switch(c)
4029                  {
4030                  default: RRETURN(MATCH_NOMATCH);
4031                  case 0x0a:      /* LF */
4032                  case 0x0b:      /* VT */
4033                  case 0x0c:      /* FF */
4034                  case 0x0d:      /* CR */
4035                  case 0x85:      /* NEL */
4036                  case 0x2028:    /* LINE SEPARATOR */
4037                  case 0x2029:    /* PARAGRAPH SEPARATOR */
4038                  break;
4039                  }
4040              break;              break;
4041    
4042              case OP_NOT_DIGIT:              case OP_NOT_DIGIT:
# Line 2929  for (;;) Line 4080  for (;;)
4080          {          {
4081          for (fi = min;; fi++)          for (fi = min;; fi++)
4082            {            {
4083            RMATCH(rrc, eptr, ecode, offset_top, md, ims, eptrb, 0);            RMATCH(eptr, ecode, offset_top, md, ims, eptrb, 0, RM43);
4084            if (rrc != MATCH_NOMATCH) RRETURN(rrc);            if (rrc != MATCH_NOMATCH) RRETURN(rrc);
4085            if (fi >= max || eptr >= md->end_subject ||            if (fi >= max) RRETURN(MATCH_NOMATCH);
4086                 ((ims & PCRE_DOTALL) == 0 &&            if (eptr >= md->end_subject)
4087                   eptr <= md->end_subject - md->nllen && IS_NEWLINE(eptr)))              {
4088                SCHECK_PARTIAL();
4089                RRETURN(MATCH_NOMATCH);
4090                }
4091              if (ctype == OP_ANY && IS_NEWLINE(eptr))
4092              RRETURN(MATCH_NOMATCH);              RRETURN(MATCH_NOMATCH);
   
4093            c = *eptr++;            c = *eptr++;
4094            switch(ctype)            switch(ctype)
4095              {              {
4096              case OP_ANY:   /* This is the DOTALL case */              case OP_ANY:     /* This is the non-NL case */
4097                case OP_ALLANY:
4098                case OP_ANYBYTE:
4099              break;              break;
4100    
4101              case OP_ANYBYTE:              case OP_ANYNL:
4102                switch(c)
4103                  {
4104                  default: RRETURN(MATCH_NOMATCH);
4105                  case 0x000d:
4106                  if (eptr < md->end_subject && *eptr == 0x0a) eptr++;
4107                  break;
4108    
4109                  case 0x000a:
4110                  break;
4111    
4112                  case 0x000b:
4113                  case 0x000c:
4114                  case 0x0085:
4115                  if (md->bsr_anycrlf) RRETURN(MATCH_NOMATCH);
4116                  break;
4117                  }
4118                break;
4119    
4120                case OP_NOT_HSPACE:
4121                switch(c)
4122                  {
4123                  default: break;
4124                  case 0x09:      /* HT */
4125                  case 0x20:      /* SPACE */
4126                  case 0xa0:      /* NBSP */
4127                  RRETURN(MATCH_NOMATCH);
4128                  }
4129                break;
4130    
4131                case OP_HSPACE:
4132                switch(c)
4133                  {
4134                  default: RRETURN(MATCH_NOMATCH);
4135                  case 0x09:      /* HT */
4136                  case 0x20:      /* SPACE */
4137                  case 0xa0:      /* NBSP */
4138                  break;
4139                  }
4140                break;
4141    
4142                case OP_NOT_VSPACE:
4143                switch(c)
4144                  {
4145                  default: break;
4146                  case 0x0a:      /* LF */
4147                  case 0x0b:      /* VT */
4148                  case 0x0c:      /* FF */
4149                  case 0x0d:      /* CR */
4150                  case 0x85:      /* NEL */
4151                  RRETURN(MATCH_NOMATCH);
4152                  }
4153                break;
4154    
4155                case OP_VSPACE:
4156                switch(c)
4157                  {
4158                  default: RRETURN(MATCH_NOMATCH);
4159                  case 0x0a:      /* LF */
4160                  case 0x0b:      /* VT */